<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>TG - @𝙲𝚁𝙸𝙲𝙓𝙿𝚁𝙴𝚂𝚂</title>
  <link rel="shortcut icon" href="https://i.pinimg.com/originals/31/2a/f9/312af9235aadad69655688eaee97eabf.png" type="image/x-icon">
  <link rel="stylesheet" href="https://cdn.plyr.io/3.6.12/plyr.css" />
  <style>
    @import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap");

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: "Roboto", system-ui, sans-serif;
    }

    #my-video {
      width: 100%;
      height: 100vh;
      height: 100svh;
    }

    video {
      width: 100% !important;
      height: 100vh;
      height: 100svh !important;
    }

    .watermark {
      position: absolute;
      top: 10px;
      left: 10px;
      z-index: 1000;
      opacity: 0.8;
    }

    .watermark img {
      width: 130px;
      height: auto;
    }
  </style>
</head>

<body>
  <div class="watermark">
    <img src="https://i.postimg.cc/R0tFCHGy/Picsart-25-01-08-18-20-40-829.png" alt="Watermark">
  </div>

  <video id="player" controls preload="auto" autoplay muted></video>

  <script src="https://cdn.jsdelivr.net/npm/hls.js@1.1.4/dist/hls.min.js"></script>
  <script src="https://cdn.plyr.io/3.6.12/plyr.js"></script>
<script>
  document.addEventListener("DOMContentLoaded", () => {
    if (confirm("Join Our Telegram Channel @𝙲𝚁𝙸𝙲𝚇𝙿𝚁𝙴𝚂𝚂")) {
      window.location.href = "https://t.me/CRICXPRESS";
    }

    const video = document.getElementById("player");
    const urlParams = new URLSearchParams(window.location.search);
    const id = urlParams.get("id"); // Fetch the 'id' parameter from the URL

    // URL of your JSON file
    const jsonFileUrl = "https://cricxpress.pages.dev/find.json";

    fetch(jsonFileUrl)
      .then((response) => response.json())
      .then((data) => {
        const source = data[id]; // Get the m3u8 URL for the corresponding ID

        if (!source) {
          alert("No video found for the provided ID.");
          return;
        }

        if (Hls.isSupported()) {
          const hls = new Hls();
          hls.loadSource(source);

          // Attach media to video element
          hls.attachMedia(video);

          hls.config.maxBufferSize = 120 * 1000 * 1000; // 120MB
          hls.config.maxBufferLength = 30; // 30 seconds of buffer

          // On manifest parsed, initialize Plyr
          hls.on(Hls.Events.MANIFEST_PARSED, function () {
            const availableQualities = hls.levels.map((l) => l.height);

            const defaultOptions = {
              controls: [
                "play-large",
                "play",
                "progress",
                "current-time",
                "mute",
                "volume",
                "captions",
                "settings",
                "pip",
                "fullscreen",
                "airplay",
              ],
              quality: {
                default: "auto",
                options: ["auto", ...availableQualities],
                forced: true,
                onChange: (quality) => {
                  if (quality === "auto") {
                    hls.currentLevel = -1; // Auto
                  } else {
                    hls.levels.forEach((level, index) => {
                      if (level.height === quality) {
                        hls.currentLevel = index;
                      }
                    });
                  }
                },
              },
              i18n: {
                qualityLabel: {
                  auto: "Auto",
                  ...availableQualities.reduce((labels, quality) => {
                    labels[quality] = `${quality}p`;
                    return labels;
                  }, {}),
                },
              },
            };

            new Plyr(video, defaultOptions);
          });
        } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
          video.src = source;
        }
      })
      .catch((error) => {
        console.error("Error fetching video source:", error);
      });
  });
</script>
</body>

</html>
