<?php
// Get the 'id' and 'e' from the query string
$id = isset($_GET['id']) ? $_GET['id'] : null;
$e = isset($_GET['e']) ? $_GET['e'] : null;
$ch_name = isset($_GET['ch_name']) ? $_GET['ch_name'] : null;

// Redirect to an error page if 'id', 'e', or 'ch_name' is missing
if (!$id || !$e || !$ch_name) {
    echo "Error: Missing stream parameters.";
    exit;
}

// Build the stream URL based on 'id' and 'e'
$stream_url = "https://flix.cwabdtv.eu.org/streamingengine.php?id=$id&e=$e";
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="assets/clap.css?v=1">
    <script src="https://flix.cwabdtv.eu.org/api/js/clappr.min.js"></script>
    <script src="https://flix.cwabdtv.eu.org/api/js/level-selector.min_1.js"></script>
    <script src="https://flix.cwabdtv.eu.org/api/js/hlsjs-playback.min_1.js"></script>
    
    <style>
        body {
            margin: 0;
            background-color: #000000;
            height: 100vh;
            overflow: hidden;
        }

        #player-wrapper {
            height: 100%;
            width: 100%;
            position: relative;
            background-color: #fff;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            overflow: hidden;
        }

        .watermark {
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
            background-color: rgba(0, 0, 0, 0.5);
            color: #fff;
            padding: 5px 10px;
            border-radius: 3px;
            font-size: 12px;
            font-weight: bold;
            text-align: center;
        }

        .watermark a {
            color: #fff;
            text-decoration: none;
        }

        .watermark a:hover {
            text-decoration: underline;
        }

        @keyframes fadeIn {
            0% { opacity: 0; }
            100% { opacity: 1; }
        }

        .watermark {
            animation: fadeIn 1s ease-in-out;
        }
    </style>
</head>
<body>
<div id="player-wrapper">
    <div id="player" style="height: 100%; width: 100%;"></div>
    <!-- Watermark Text -->
    <div class="watermark">
        Stream Powered by <a href="https://flix.cwabdtv.eu.org" target="_blank">FLIX.CWABDTV.EU.ORG</a>
    </div>
</div>

<script src="https://flix.cwabdtv.eu.org/api/js/jquery.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
    var player = new Clappr.Player({
        source: '<?php echo $stream_url; ?>', // Dynamically set the stream URL
        width: '100%',
        height: '100%',
        autoPlay: true,
        plugins: [HlsjsPlayback, LevelSelector],
        mimeType: "application/x-mpegURL",
        mediacontrol: { seekbar: "#ff0000", buttons: "#eee" },
        parentId: "#player",
    });
</script>
<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool'></script>
    <script>
        // Disable F12 and Ctrl+Shift+I
        document.addEventListener("keydown", function(event) {
            if (
                event.key === "F12" ||
                (event.ctrlKey && event.shiftKey && (event.key === "I" || event.key === "J")) ||
                (event.ctrlKey && event.key === "U")
            ) {
                event.preventDefault();
                alert("Developer tools are disabled!");
            }
        });

        // Disable right-click
        document.addEventListener("contextmenu", function(event) {
            event.preventDefault();
            alert("Ki Vhai Ki Korte Chacho? !");
        });

        // Detect DevTools and take action
        setInterval(function() {
            const devtools = /./;
            devtools.toString = function() { return "DevTools detected"; };
            console.log(devtools);
            if (console.log.toString().length > 100) {
                alert("Please close Developer Tools!");
                window.location.href = "about:blank"; // Redirect or take action
            }
        }, 1000);
    </script>
</body>
</html>
