<?php   

if(isset($_SERVER['HTTP_REFERER'])) {
    $referer = $_SERVER['HTTP_REFERER'];
    // রেফারার লগ করুন বা ডাটাবেজে সেভ করুন
    file_put_contents('referer_log.txt', date('Y-m-d H:i:s') . " - " . $referer . "\n", FILE_APPEND);
}

// অনুমোদিত রেফারার ডোমেইন তালিকা
$allowedReferers = [
    "eplayhd.com",
    "cricfoots.com",
    "tof.photocard.fun"
];

// HTTP_REFERER যাচাই
if (!isset($_SERVER['HTTP_REFERER'])) {
    // যদি HTTP_REFERER সেট না থাকে, মেসেজ দেখান
    die('<h1 style="color: red; text-align: center; margin-top: 50px;">You Have no Access to Play this Video</h1>
         <p style="color: orange; text-align: center;">Need Access? Contact <a href="https://t.me/eplayhd" target="_blank">t.me/eplayhd</a> or visit <a href="https://eplayhd.com" target="_blank">ePlayHD.com</a></p>');
} else {
    // HTTP_REFERER থেকে হোস্ট বের করুন
    $refererHost = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);

    // যদি রেফারার অনুমোদিত না হয়, মেসেজ দেখান
    if (!in_array($refererHost, $allowedReferers)) {
        die('<h1 style="color: red; text-align: center; margin-top: 50px;">You Have no Access to Play this Video</h1>
             <p style="color: orange; text-align: center;">Need Access? Contact <a href="https://t.me/eplayhd" target="_blank">t.me/eplayhd</a> or visit <a href="https://eplayhd.com" target="_blank">ePlayHD.com</a></p>');
    }
}

?>
  <title>Live Sports By ePlayHD</title>  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/4.7.11/shaka-player.ui.min.js" crossorigin="anonymous"></script>  
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/4.7.11/controls.min.css" crossorigin="anonymous" />  
  <style>  
    * { margin: 0; padding: 0; box-sizing: border-box; }  
    html, body {  
      background: #000;  
      height: 100vh;  
      width: 100vw;  
      overflow: hidden;  
      font-family: system-ui, -apple-system, sans-serif;  
    }  
    .shaka-video-container {  
      position: absolute;  
      inset: 0;  
      width: 100%;  
      height: 100%;  
    }  
    video {  
      width: 100%;  
      height: 100%;  
      background: #000;  
      object-fit: contain;  
    }  
    .shaka-spinner-container, .shaka-spinner, .shaka-spinner-svg {  
      display: none !important;  
      visibility: hidden !important;  
      opacity: 0 !important;  
    }  
    .channel-logo {  
      position: fixed !important;  
      top: 15px !important;  
      right: 15px !important;  
      z-index: 2147483647 !important;  
      pointer-events: none !important;  
      max-width: 120px;  
      max-height: 80px;  
      opacity: 0.85 !important;  
      transition: all 0.3s ease !important;  
      filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5)) !important;  
    }  
    @media (max-width: 768px) {  
      .channel-logo {  
        max-width: 80px;  
        max-height: 60px;  
        top: 10px !important;  
        right: 10px !important;  
      }  
    }  
  </style>  
<body>  
  <div class="channel-logo" id="channelLogo">  
    <img src="https://cdn2.eplayhd.com/icon/eplaylogo.webp" alt="Channel Logo" id="logoImage" />  
  </div>  
  
  <div class="shaka-video-container" data-shaka-player>  
    <video autoplay playsinline preload="metadata" poster="https://cdn2.eplayhd.com/icon/eplaylogo.webp"></video>  
  </div>  
  
  <script>  
    let player;  
  
    // লোগো সেট ফাংশন  
    function setChannelLogo(logoUrl) {  
      const logoImage = document.getElementById('logoImage');  
      const logoContainer = document.getElementById('channelLogo');  
      if (logoUrl) {  
        logoImage.src = logoUrl;  
        logoContainer.style.display = 'block';  
        logoImage.onerror = function () {  
          logoContainer.style.display = 'none';  
        };  
      } else {  
        logoContainer.style.display = 'none';  
      }  
    }  
  
 
    async function loadChannelData() {  
      try {  
    
        const params = new URLSearchParams(window.location.search);  
        const id = params.get('id') || 'prime';  // ডিফল্ট prime  
  
        
        const response = await fetch('channel.php?key=eplayhd_2026');
        if (!response.ok) throw new Error('চ্যানেল ডেটা লোড করা যায়নি');  
  
        const channels = await response.json();  
  
        if (!channels[id]) {  
          alert('চ্যানেল পাওয়া যায়নি!');  
          return;  
        }  
  
        const currentChannel = channels[id];  
  
        setChannelLogo(currentChannel.logo);  
        document.title = currentChannel.name + ' - Prime By Allrounder';  
  
        player.configure({  
          drm: currentChannel.drm,  
          streaming: {  
            lowLatencyMode: true,  
            bufferingGoal: 15,  
            rebufferingGoal: 2,  
            bufferBehind: 15,  
            retryParameters: {  
              timeout: 10000,  
              maxAttempts: 5,  
              baseDelay: 300,  
              backoffFactor: 1.2  
            },  
            segmentRequestTimeout: 8000,  
            segmentPrefetchLimit: 2,  
            useNativeHlsOnSafari: true  
          },  
          manifest: {  
            retryParameters: {  
              timeout: 8000,  
              maxAttempts: 3  
            }  
          }  
        });  
  
        await player.load(currentChannel.url);  
        console.log(`✅ ${currentChannel.name} লোড হয়েছে`);  
      } catch (err) {  
        console.error(err);  
        alert('ভুল হয়েছে! চ্যানেল লোড করুন ফেইল করেছে।');  
      }  
    }  
  
    document.addEventListener('DOMContentLoaded', async () => {  
      shaka.polyfill.installAll();  
  
      if (!shaka.Player.isBrowserSupported()) {  
        console.error('Browser not supported');  
        alert('আপনার ব্রাউজার সাপোর্ট করে না।');  
        return;  
      }  
  
      const video = document.querySelector('video');  
      player = new shaka.Player();  
      await player.attach(video);  
  
      const container = document.querySelector('.shaka-video-container');  
      const ui = new shaka.ui.Overlay(player, container, video);  
  
      ui.configure({  
        controlPanelElements: [  
          'play_pause', 'time_and_duration', 'mute', 'volume',  
          'spacer', 'language', 'captions', 'picture_in_picture',  
          'quality', 'fullscreen'  
        ],  
        volumeBarColors: {  
          base: 'rgba(255, 192, 203, 0.3)',  
          level: 'rgb(255, 105, 180)'  
        },  
        seekBarColors: {  
          base: 'rgba(255, 255, 0, 0.3)',  
          buffered: 'rgba(255, 255, 0, 0.6)',  
          played: 'rgb(255, 255, 0)'  
        }  
      });  
  
      player.addEventListener('error', (event) => {  
        console.error('Shaka Player Error:', event.detail);  
      });  
  
      await loadChannelData();  
    });  
  </script>  
</body>  
</html>t video = document.querySelector('video');  
      player = new shaka.Player();  
      await player.attach(video);  
  
      const container = document.querySelector('.shaka-video-container');  
      const ui = new shaka.ui.Overlay(player, container, video);  
  
      ui.configure({  
        controlPanelElements: [  
          'play_pause', 'time_and_duration', 'mute', 'volume',  
          'spacer', 'language', 'captions', 'picture_in_picture',  
          'quality', 'fullscreen'  
        ],  
        volumeBarColors: {  
          base: 'rgba(255, 192, 203, 0.3)',  
          level: 'rgb(255, 105, 180)'  
        },  
        seekBarColors: {  
          base: 'rgba(255, 255, 0, 0.3)',  
          buffered: 'rgba(255, 255, 0, 0.6)',  
          played: 'rgb(255, 255, 0)'  
        }