<!DOCTYPE html>
<html lang="en">
<head>
    <script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool@latest'></script>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RgShows - Series Download</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/devtools-detector/2.0.17/devtools-detector.js"></script>
    <script src="../../js/protected_devtoolsdetector.js" preload></script>
    <script src="../../js/nocheats.js" preload></script>
    <script type="text/javascript" data-cfasync="false">
        /*<![CDATA[/* */
        (function(){var x=window,h="b610fb19695265b8c103d805e8d5b537",i=[["siteId",592-707+586*858+4641969],["minBid",0],["popundersPerIP","0"],["delayBetween",0],["default",false],["defaultPerDay",0],["topmostLayer","auto"]],p=["d3d3LnZpc2FyaW9tZWRpYS5jb20vYnR3aWxpby5taW4uY3Nz","ZDEzazdwcmF4MXlpMDQuY2xvdWRmcm9udC5uZXQvdWFaS2JqL2JwZGYubWluLmpz","d3d3LnhzdnVvbXdrbncuY29tL3Z0d2lsaW8ubWluLmNzcw==","d3d3Lm5qbHJrcnJ0LmNvbS9UeGtNaW8veXBkZi5taW4uanM="],m=-1,c,y,v=function(){clearTimeout(y);m++;if(p[m]&&!(1763035816000<(new Date).getTime()&&1<m)){c=x.document.createElement("script");c.type="text/javascript";c.async=!0;var g=x.document.getElementsByTagName("script")[0];c.src="https://"+atob(p[m]);c.crossOrigin="anonymous";c.onerror=v;c.onload=function(){clearTimeout(y);x[h.slice(0,16)+h.slice(0,16)]||v()};y=setTimeout(v,5E3);g.parentNode.insertBefore(c,g)}};if(!x[h]){try{Object.freeze(x[h]=i)}catch(e){}v()}})();
        /*]]>/* */
    </script>        
    <link rel="stylesheet" href="https://unpkg.com/kursor/dist/kursor.css">
    <link rel="preload stylesheet" href="../../css/flash.css" as="style">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/devtools-detector/2.0.17/devtools-detector.js"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');
        body, html {
            margin: 0;
            padding: 0;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            background-color: #000;
            color: #fff;
            font-family: 'Poppins', Arial, sans-serif;
        }
        header {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            z-index: 1000;
            text-align: center;
            padding: 10px 0;
            background-color: #111;
            border-bottom: 2px solid #ff0000;
        }
        header img {
            max-width: 100%;
            height: auto;
        }
        .container {
            margin-top: 80px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: calc(100vh - 120px);
        }
        .box {
            background-color: #222;
            border-radius: 10px;
            padding: 15px;
            width: 90%;
            max-width: 300px;
            text-align: center;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
        }
        .box-title {
            font-size: 18px;
            margin-bottom: 10px;
            color: #fff;
            font-weight: 600;
        }
        .movie-poster {
            margin: 10px 0;
        }
        .movie-poster img {
            max-width: 70%;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
        }
        button {
            padding: 10px 12px;
            margin: 6px;
            font-size: 14px;
            color: white;
            background-color: grey;
            border: none;
            border-radius: 6px;
            cursor: not-allowed;
            transition: background-color 0.3s, transform 0.2s;
            font-family: 'Poppins', sans-serif;
        }
        button:hover {
            transform: scale(1.05);
        }
        button.active-blue {
            background-color: blue;
            cursor: pointer;
        }
        button.active-green {
            background-color: green;
            cursor: pointer;
        }
        .popup {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            color: black;
            padding: 15px;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
            z-index: 1000;
            text-align: center;
        }
        .popup h2 {
            font-size: 16px;
            margin-bottom: 10px;
            font-weight: 500;
        }
        .popup button {
            display: block;
            width: 80%;
            margin: 5px auto;
            color: black;
            background-color: lightgray;
            border: none;
            border-radius: 6px;
            padding: 8px;
            cursor: pointer;
        }
        .popup .popup-close {
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 18px;
            font-weight: bold;
            color: black;
            cursor: pointer;
        }
        .overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.7);
            z-index: 999;
        }
        footer {
            text-align: center;
            padding: 10px 0;
            background-color: #111;
            border-top: 2px solid #ff0000;
            color: #fff;
            font-size: 12px;
        }
        ::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: #1f1f1f;
}
::-webkit-scrollbar-thumb {
    background: #333333;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #555555;
}
    </style>
</head>
<body>
    <a href="../../">
        <header>
            <img src="../../banner.png" alt="Banner">
        </header>
    </a>
    <div class="container">
        <div class="box">
            <div class="box-title" id="box-title">Download "ShowName" from RgShows</div>
            <div class="movie-poster" id="movie-poster">
                <img src="" alt="Movie Poster" id="poster-image">
            </div>
            <button id="download-v1" href="#" target="_blank">Download 1 (v1)</button>
            <button id="download-v2" href="#" target="_blank">Download 2 (v2)</button>
            <button id="download-subtitles" href="#" target="_blank">Download Subtitles</button>
        </div>
    </div>
    <div class="overlay" id="overlay"></div>
    <div class="popup" id="popup">
        <div class="popup-close" onclick="closePopup()">&times;</div>
        <h2>Download Links</h2>
        <div id="popup-links"></div>
    </div>
    <footer>
        © 2025 RgShows. All Rights Reserved.
    </footer>
    <script>
        const apiKey = "f6e840332142f77746185ab4e67be858";
        const queryParams = new URLSearchParams(window.location.search);
        const tmdbId = queryParams.get("id");
        const season = queryParams.get('s');
        const episode = queryParams.get('e');
    
        if (!tmdbId) {
            alert("No TMDB ID provided in the URL.");
        } else {
            // Proxies and APIs
            const proxies = [
                "https://api.codetabs.com/v1/proxy/?quest=",
                "https://api.cors.lol/?url=",
                "https://rgproxy.notowner.workers.dev/?u="
            ];
    
            const apis = [
                "https://expected-erika-rgshows-06042e31.koyeb.app",
                "https://api.rgshows.me"
            ];
    
            // Function to get a random element from an array
            function getRandomElement(arr) {
                return arr[Math.floor(Math.random() * arr.length)];
            }
    
            // Fetch TMDB TV show details
            fetch(`https://api.themoviedb.org/3/tv/${tmdbId}?api_key=${apiKey}`)
                .then(response => response.json())
                .then(data => {
                    const showTitle = data.name || "Show Title Not Found";
                    document.getElementById("box-title").textContent = ` ${showTitle} - S${season}E${episode}`;
                    const posterPath = data.poster_path ? `https://image.tmdb.org/t/p/w500${data.poster_path}` : "";
                    document.getElementById("poster-image").src = posterPath;
                });
    
            let downloadV1Link = "";
            let subtitleLink = "";
    
            // Fetch download and subtitle links with proxy
            const downloadProxy = getRandomElement(proxies);
            const downloadApi = getRandomElement(apis);
    
            fetch(`${downloadProxy}${downloadApi}/download/tv/v1/${tmdbId}/${season}/${episode}`)
                .then(response => response.json())
                .then(data => {
                    if (data.downloadLink && data.downloadLink !== "Download link not available") {
                        downloadV1Link = data.downloadLink;
                        document.getElementById("download-v1").classList.add("active-blue");
                        document.getElementById("download-v1").disabled = false;
                    }
    
                    if (data.subtitleLink && data.subtitleLink !== "Download link not available") {
                        subtitleLink = data.subtitleLink;
                        document.getElementById("download-subtitles").classList.add("active-green");
                        document.getElementById("download-subtitles").disabled = false;
                    }
                });
    
            fetch(`${downloadProxy}${downloadApi}/download/tv/v2/${tmdbId}/${season}/${episode}`)
                .then(response => response.json())
                .then(data => {
                    if (data.downloadLinks && data.downloadLinks.length > 0) {
                        const popupLinks = document.getElementById("popup-links");
                        data.downloadLinks.forEach(link => {
                            const button = document.createElement("button");
                            button.textContent = link.label;
                            button.setAttribute("data-url", link.url);  // Add data-url attribute
                            popupLinks.appendChild(button);
                        });
                        document.getElementById("download-v2").classList.add("active-blue");
                        document.getElementById("download-v2").disabled = false;
                    }
                });
    
            // Event listeners
            document.getElementById('download-v1').addEventListener('click', function() {
                if (downloadV1Link) {
                    window.open(downloadV1Link, '_blank');
                } else {
                    alert("Download link not available yet.");
                }
            });
    
            document.getElementById('download-subtitles').addEventListener('click', function() {
                if (subtitleLink) {
                    window.open(subtitleLink, '_blank');
                } else {
                    alert("Subtitle link not available yet.");
                }
            });
    
            document.getElementById("download-v2").addEventListener("click", () => {
                // Show the popup and overlay
                document.getElementById("overlay").style.display = "block";
                document.getElementById("popup").style.display = "block";
            });
    
            document.getElementById("popup-links").addEventListener("click", function(event) {
                // Check if the clicked element is a button
                if (event.target.tagName === "BUTTON") {
                    const downloadUrl = event.target.getAttribute("data-url");
                    if (downloadUrl) {
                        window.open(downloadUrl, "_blank");
                    }
                }
            });
        }
    
        function closePopup() {
            document.getElementById("overlay").style.display = "none";
            document.getElementById("popup").style.display = "none";
        }
    </script>    
    <iframe src="../../views.html" style="display: none;" id="viewsFrame"></iframe>
    <script>
        document.getElementById('viewsFrame').onload = function() {
            var iframeDoc = document.getElementById('viewsFrame').contentDocument || document.getElementById('viewsFrame').contentWindow.document;
            var viewsCounter = iframeDoc.querySelector('script[src*="freevisitorcounters.com"]');
            if (viewsCounter) {
                document.getElementById('viewsCount').innerText = 'Total Views: (Check views.html)';
            } else {
                document.getElementById('viewsCount').innerText = 'Failed to load view counter.';
            }
        };
    </script>    
    <script type="text/javascript" data-cfasync="false">
        /*<![CDATA[/* */
        (function(){var x=window,h="b610fb19695265b8c103d805e8d5b537",i=[["siteId",592-707+586*858+4641969],["minBid",0],["popundersPerIP","0"],["delayBetween",0],["default",false],["defaultPerDay",0],["topmostLayer","auto"]],p=["d3d3LnZpc2FyaW9tZWRpYS5jb20vYnR3aWxpby5taW4uY3Nz","ZDEzazdwcmF4MXlpMDQuY2xvdWRmcm9udC5uZXQvdWFaS2JqL2JwZGYubWluLmpz","d3d3LnhzdnVvbXdrbncuY29tL3Z0d2lsaW8ubWluLmNzcw==","d3d3Lm5qbHJrcnJ0LmNvbS9UeGtNaW8veXBkZi5taW4uanM="],m=-1,c,y,v=function(){clearTimeout(y);m++;if(p[m]&&!(1763035816000<(new Date).getTime()&&1<m)){c=x.document.createElement("script");c.type="text/javascript";c.async=!0;var g=x.document.getElementsByTagName("script")[0];c.src="https://"+atob(p[m]);c.crossOrigin="anonymous";c.onerror=v;c.onload=function(){clearTimeout(y);x[h.slice(0,16)+h.slice(0,16)]||v()};y=setTimeout(v,5E3);g.parentNode.insertBefore(c,g)}};if(!x[h]){try{Object.freeze(x[h]=i)}catch(e){}v()}})();
        /*]]>/* */
    </script>        
    <script src="https://cdn.jsdelivr.net/npm/kursor@0.0.14/dist/kursor.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/pace-js@latest/pace.min.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MRLWZB0FWK"></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        const storedCursor = localStorage.getItem("selectedCursor");
        const selectedColor = localStorage.getItem("selectedColor") || "#000000"; // Default to black if no color is stored
        const cursorType = storedCursor ? parseInt(storedCursor) : 1; // Default to type 1 if no cursor is selected

        // Initialize the kursor with the selected type and color
        new kursor({
            type: cursorType,
            color: selectedColor,
        });

        // If no cursor type is stored, set the default type in localStorage
        if (!storedCursor) {
            localStorage.setItem("selectedCursor", 1);
        }
    });
</script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-MRLWZB0FWK');
</script>
</body>
</html>