<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>EliteAdult - Premium Adult Content</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"/>
<style>
        .video-thumbnail {
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        .video-thumbnail:hover {
            transform: scale(1.03);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
        }
        .video-thumbnail::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 50%);
            z-index: 1;
        }
        .duration-badge {
            position: absolute;
            bottom: 10px;
            right: 10px;
            z-index: 2;
        }
        .video-player {
            background-color: #000;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
        }
        .dropdown-menu {
            display: none;
            position: absolute;
            right: 0;
            background-color: #1a1a1a;
            min-width: 200px;
            box-shadow: 0 8px 16px rgba(0,0,0,0.3);
            z-index: 100;
            border-radius: 8px;
            overflow: hidden;
        }
        .dropdown:hover .dropdown-menu {
            display: block;
        }
        .search-bar {
            background-color: rgba(255,255,255,0.1);
            backdrop-filter: blur(10px);
        }
        .preview-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.7);
            display: flex;
            justify-content: center;
            align-items: center;
            opacity: 0;
            transition: opacity 0.3s ease;
            z-index: 3;
        }
        .video-thumbnail:hover .preview-overlay {
            opacity: 1;
        }
        .loading-spinner {
            border: 4px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top: 4px solid #ec4899;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .video-js {
            width: 100%;
            height: 100%;
        }
        .video-placeholder {
            width: 100%;
            height: 100%;
            background-color: #000;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .speed-control {
            position: absolute;
            right: 10px;
            bottom: 50px;
            z-index: 10;
            background: rgba(0,0,0,0.7);
            border-radius: 4px;
            padding: 5px;
        }
        .quality-selector {
            position: absolute;
            right: 10px;
            bottom: 90px;
            z-index: 10;
            background: rgba(0,0,0,0.7);
            border-radius: 4px;
            padding: 5px;
        }
        .progress-marker {
            position: absolute;
            width: 2px;
            height: 10px;
            background-color: #fff;
            top: -5px;
            z-index: 5;
        }
        .progress-marker::after {
            content: attr(data-time);
            position: absolute;
            top: -20px;
            left: -15px;
            background: rgba(0,0,0,0.7);
            color: white;
            padding: 2px 5px;
            border-radius: 3px;
            font-size: 12px;
            white-space: nowrap;
        }
    </style>
<!-- Video.js for better video playback -->
<link href="https://vjs.zencdn.net/8.6.1/video-js.css" rel="stylesheet">
</link></head>
<body class="bg-gray-900 text-white min-h-screen">
<!-- Header -->
<header class="bg-gray-800 sticky top-0 z-50 shadow-lg">
<div class="container mx-auto px-4 py-3 flex justify-between items-center">
<div class="flex items-center space-x-2">
<img src="https://iili.io/3sUCA9s.th.png" alt="EliteAdult Logo" class="w-10 h-10 rounded-full"/>
<h1 class="text-2xl font-bold bg-gradient-to-r from-yellow-600 to-black bg-clip-text text-transparent">EliteAdult</h1>
</div>
<div class="relative w-3/4">
<div class="search-bar flex items-center rounded-full px-4 py-2">
<i class="fas fa-search text-gray-400 mr-2"></i>
<input class="bg-transparent w-full focus:outline-none text-white placeholder-gray-400" id="searchInput" placeholder="Search videos..." type="text"/>
<button class="bg-gradient-to-r from-yellow-600 to-black text-white px-4 py-1 rounded-full ml-2 hover:opacity-90 transition" id="searchBtn">Search</button>
</div>
</div>
<div class="flex items-center space-x-4">

</div>
</div>
</header>
<!-- Main Content -->
<main class="container mx-auto px-4 py-6">
<!-- Featured Video Section -->
<section class="mb-10 hidden" id="featuredVideo">
<div class="video-player w-full aspect-video mb-4 relative">
<video class="video-js vjs-default-skin" controls="" height="100%" id="mainVideoPlayer" preload="auto" width="100%">
<p class="vjs-no-js">
                        To view this video please enable JavaScript, and consider upgrading to a
                        web browser that <a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
</p>
</video>
<div class="speed-control hidden" id="speedControl">
<select class="bg-gray-800 text-white text-sm p-1 rounded" id="playbackSpeed">
<option value="0.5">0.5x</option>
<option selected="" value="1">1x</option>
<option value="1.5">1.5x</option>
<option value="2">2x</option>
</select>
</div>
<div class="quality-selector hidden" id="qualitySelector">
<select class="bg-gray-800 text-white text-sm p-1 rounded" id="videoQuality">
<option selected="" value="auto">Auto Quality</option>
</select>
</div>
</div>
<div class="flex justify-between items-start mb-4">
<div>
<h2 class="text-2xl font-bold mb-2" id="videoTitle"></h2>
<div class="flex items-center space-x-4 text-gray-400 text-sm">
<span id="videoViews"></span>
<span id="videoLikes"></span>
<span id="videoDislikes"></span>
</div>
</div>
<div class="flex space-x-2">
<button class="bg-gradient-to-r from-yellow-600 to-black text-white px-4 py-2 rounded hover:opacity-90 transition flex items-center" id="downloadBtn">
<i class="fas fa-download mr-2"></i> Download
                    </button>
<button class="bg-gradient-to-r from-blue-500 to-blue-600 text-white px-4 py-2 rounded hover:opacity-90 transition flex items-center" id="telegramBtn">
<i class="fab fa-telegram mr-2"></i> Send to Telegram
                    </button>
</div>
</div>
<!-- Download Options -->
<div class="hidden bg-gray-800 p-4 rounded-lg mt-4" id="downloadOptions">
<h3 class="text-lg font-semibold mb-3">Download Options</h3>
<div class="flex flex-wrap gap-3">
<a class="bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded flex items-center" href="#" id="downloadLink">
<i class="fas fa-video mr-2"></i> MP4 Video
                    </a>
<a class="bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded flex items-center" href="#" id="downloadHD">
<i class="fas fa-high-definition mr-2"></i> HD Quality
                    </a>
<a class="bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded flex items-center" href="#" id="download480p">
<i class="fas fa-video mr-2"></i> 480p
                    </a>
<a class="bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded flex items-center" href="#" id="download720p">
<i class="fas fa-video mr-2"></i> 720p
                    </a>
<a class="bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded flex items-center" href="#" id="download1080p">
<i class="fas fa-video mr-2"></i> 1080p
                    </a>
</div>
</div>
<!-- Telegram Bot Section -->
<div class="bg-gray-800 p-4 rounded-lg mt-4 hidden" id="telegramSection">
<h3 class="text-lg font-semibold mb-3">Send to Telegram Bot</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-300 mb-1" for="telegramUserId">Your Telegram User ID</label>
<input class="w-full bg-gray-700 text-white px-3 py-2 rounded focus:outline-none focus:ring-2 focus:ring-blue-500" id="telegramUserId" placeholder="Enter your Telegram User ID" type="text"/>
<p class="text-xs text-gray-400 mt-1">Get your User ID by messaging @userinfobot on Telegram</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1" for="telegramQuality">Quality</label>
<select class="w-full bg-gray-700 text-white px-3 py-2 rounded focus:outline-none focus:ring-2 focus:ring-blue-500" id="telegramQuality">
<option value="best">Best Quality</option>
<option value="720p">720p</option>
<option value="480p">480p</option>
<option value="360p">360p</option>
</select>
</div>
</div>
<button class="mt-4 bg-gradient-to-r from-blue-500 to-blue-600 text-white px-4 py-2 rounded hover:opacity-90 transition flex items-center justify-center w-full" id="sendToTelegramBtn">
<i class="fab fa-telegram mr-2"></i> Send Video to Telegram
                </button>
<div class="mt-3 text-sm hidden" id="telegramStatus"></div>
</div>
<!-- Video Chapters -->
<div class="bg-gray-800 p-4 rounded-lg mt-4 hidden" id="videoChapters">
<h3 class="text-lg font-semibold mb-3">Video Chapters</h3>
<div class="relative h-2 bg-gray-700 rounded-full mb-4">
<div class="absolute top-0 left-0 h-full bg-pink-500 rounded-full" id="progressBar" style="width: 0%"></div>
<div class="absolute top-0 left-0 w-full h-full" id="chapterMarkers"></div>
</div>
<div class="grid grid-cols-2 md:grid-cols-4 gap-2" id="chapterList"></div>
</div>
<div id="scrollLoader" class="text-center py-6 text-gray-400">Scroll to load more...</div>
</section>
<!-- Video Grid -->
<section id="videoGrid">
<h2 class="text-xl font-bold mb-6 flex items-center">
<span id="sectionTitle">Recommended Videos</span>
<button class="ml-4 text-gray-400 hover:text-white" id="refreshBtn">
<i class="fas fa-sync-alt"></i>
</button>
</h2>
<div class="flex justify-center items-center py-20" id="loadingSpinner">
<div class="loading-spinner"></div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6" id="videosContainer">
<!-- Videos will be loaded here -->
</div>
<div id="scrollLoader" class="text-center py-6 text-gray-400">Scroll to load more...</div>
</section>
</main>
<!-- Footer -->
<footer class="bg-gray-800 py-8 mt-12">
<div class="container mx-auto px-4">
<div class="flex flex-col md:flex-row justify-between items-center">
<div class="mb-4 md:mb-0">
<div class="flex items-center space-x-2">
<img src="https://iili.io/3sUCA9s.th.png" alt="EliteAdult Logo" class="w-8 h-8 rounded-full"/>
<h2 class="text-xl font-bold bg-gradient-to-r from-yellow-600 to-black bg-clip-text text-transparent">EliteAdult</h2>
</div>
<p class="text-gray-400 text-sm mt-2">Premium adult content platform</p>
</div>
<div class="flex space-x-6">
<a class="text-gray-400 hover:text-white" href="#">Terms</a>
<a class="text-gray-400 hover:text-white" href="#">Privacy</a>
<div class="dropdown relative">
<a class="text-gray-400 hover:text-white flex items-center" href="#">
<span>Contact</span> <i class="fas fa-chevron-down ml-1 text-xs"></i>
</a>
<div class="dropdown-menu mt-2">
<a class="block px-4 py-2 hover:bg-gray-700" href="https://t.me/DARKDATAOfficial" target="_blank">
<i class="fab fa-telegram mr-2"></i> Telegram
                            </a>
<a class="block px-4 py-2 hover:bg-gray-700" href="#">
<i class="fas fa-envelope mr-2"></i> Email
                            </a>
</div>
</div>
</div>
</div>
<div class="border-t border-gray-700 mt-6 pt-6 text-center text-gray-500 text-sm">
<p>© 2023 EliteAdult. All rights reserved. Content is provided by third parties.</p>
<p class="mt-2">This website is for adults only. By accessing this site you certify that you are 18 years or older.</p>
</div>
</div>
</footer>
<!-- Video.js script -->
<script src="https://vjs.zencdn.net/8.6.1/video.min.js"></script>
<script>
        document.addEventListener('DOMContentLoaded', function() {
            // DOM Elements
            const videosContainer = document.getElementById('videosContainer');
            const loadingSpinner = document.getElementById('loadingSpinner');
            const featuredVideoSection = document.getElementById('featuredVideo');
            const mainVideoPlayer = document.getElementById('mainVideoPlayer');
            const videoTitle = document.getElementById('videoTitle');
            const videoViews = document.getElementById('videoViews');
            const videoLikes = document.getElementById('videoLikes');
            const videoDislikes = document.getElementById('videoDislikes');
            const downloadBtn = document.getElementById('downloadBtn');
            const downloadOptions = document.getElementById('downloadOptions');
            const downloadLink = document.getElementById('downloadLink');
            const downloadHD = document.getElementById('downloadHD');
            const download480p = document.getElementById('download480p');
            const download720p = document.getElementById('download720p');
            const download1080p = document.getElementById('download1080p');
            const searchInput = document.getElementById('searchInput');
            const searchBtn = document.getElementById('searchBtn');
            const refreshBtn = document.getElementById('refreshBtn');
            const sectionTitle = document.getElementById('sectionTitle');
            const telegramBtn = document.getElementById('telegramBtn');
            const telegramSection = document.getElementById('telegramSection');
            const sendToTelegramBtn = document.getElementById('sendToTelegramBtn');
            const telegramUserId = document.getElementById('telegramUserId');
            const telegramQuality = document.getElementById('telegramQuality');
            const telegramStatus = document.getElementById('telegramStatus');
            const speedControl = document.getElementById('speedControl');
            const playbackSpeed = document.getElementById('playbackSpeed');
            const qualitySelector = document.getElementById('qualitySelector');
            const videoQuality = document.getElementById('videoQuality');
            const videoChapters = document.getElementById('videoChapters');
            const chapterList = document.getElementById('chapterList');
            const progressBar = document.getElementById('progressBar');
            const chapterMarkers = document.getElementById('chapterMarkers');
            
            // Telegram Bot Token
            const TELEGRAM_BOT_TOKEN = '<TRUFFLEHOG_REDACTED_TELEGRAMBOTTOKEN>';
            
            // State
            let currentVideoData = null;
            let previewTimers = {};
            let videoQualities = [];
            let videoChaptersData = [];
            
            // Categories for random selection
            const categories = [
    'sister', 'teen', 'milf', 'anal', 'lesbian', 'creampie',
    'blowjob', 'hardcore', 'amateur', 'orgasm', 'threesome',
    'bukkake', 'bondage', 'oral', 'cumshot', 'gangbang',
    'public', 'interracial', 'fetish', 'asian', 'voyeur',
    'double penetration', 'foot fetish', 'squirting', 'rimming',
    'bdsm', 'strap-on', 'cuckold', 'solo', 'massage',
    'hairy', 'mature', 'big tits', 'small tits', 'big ass',
    'latina', 'ebony', 'lesbian tribbing', 'milf orgy', 'group sex',
    'blonde', 'redhead', 'hard fuck', 'deep throat', 'anal creampie',
    'oral creampie', 'public sex', 'teen anal', 'lesbian sex',
    'fingering', 'titfuck', 'dildo', 'vibrator', 'cum in mouth',
    'cum in pussy', 'cum in ass', 'facial', 'deep anal',
    'interracial gangbang', 'blowjob compilation', 'cock worship',
    'gaping', 'chubby', 'bbw', 'petite', 'college',
    'teacher', 'student', 'stepmom', 'stepsister', 'big cock',
    'small cock', 'transgender', 'shemale', 'milf double penetration',
    'teen blowjob', 'anal blowjob', 'spanking', 'bondage sex',
    'lesbian domination', 'lesbian submission', 'femdom',
    'fisting', 'gangbang compilation', 'cumshot compilation',
    'ass worship', 'rimjob', 'strap-on sex', 'hair pulling',
    'forced', 'bizarre', 'latex', 'leather', 'latex fetish',
    'cosplay', 'roleplay', 'daddy', 'baby girl', 'incest',
    'feet', 'stockings', 'leggings', 'blowjob deep throat',
    'double blowjob', 'handjob', 'ass to mouth',
];
            
            // Initialize
            loadRandomVideos();
            
            // Event Listeners
            searchBtn.addEventListener('click', searchVideos);
            searchInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') searchVideos();
            });
            
            refreshBtn.addEventListener('click', loadRandomVideos);
            
            downloadBtn.addEventListener('click', function() {
                downloadOptions.classList.toggle('hidden');
                telegramSection.classList.add('hidden');
                if (!downloadOptions.classList.contains('hidden')) {
                    fetchDownloadUrl(currentVideoData.url);
                }
            });
            
            telegramBtn.addEventListener('click', function() {
                telegramSection.classList.toggle('hidden');
                downloadOptions.classList.add('hidden');
                if (!telegramSection.classList.contains('hidden')) {
                    // Check if user ID is stored in localStorage
                    const savedUserId = localStorage.getItem('telegramUserId');
                    if (savedUserId) {
                        telegramUserId.value = savedUserId;
                    }
                }
            });
            
            sendToTelegramBtn.addEventListener('click', sendToTelegram);
            
            playbackSpeed.addEventListener('change', function() {
                if (videoPlayer) {
                    videoPlayer.playbackRate(parseFloat(this.value));
                }
            });
            
            videoQuality.addEventListener('change', function() {
                if (this.value === 'auto') {
                    videoPlayer.qualityLevels().autoQuality = true;
                } else {
                    const selectedQuality = videoQualities.find(q => q.label === this.value);
                    if (selectedQuality) {
                        videoPlayer.qualityLevels().autoQuality = false;
                        videoPlayer.qualityLevels()[selectedQuality.index].enabled = true;
                    }
                }
            });
            
            // Close download options when clicking outside
            document.addEventListener('click', function(e) {
                if (!downloadBtn.contains(e.target) && !downloadOptions.contains(e.target)) {
                    downloadOptions.classList.add('hidden');
                }
                if (!telegramBtn.contains(e.target) && !telegramSection.contains(e.target)) {
                    telegramSection.classList.add('hidden');
                }
            });
            
            // Functions
            async function loadRandomVideos() {
                loadingSpinner.classList.remove('hidden');
                videosContainer.innerHTML = '';
                featuredVideoSection.classList.add('hidden');
                
                const randomCategory = categories[Math.floor(Math.random() * categories.length)];
                sectionTitle.textContent = `${randomCategory.charAt(0).toUpperCase() + randomCategory.slice(1)} Videos`;
                
                try {
                    const response = await fetch(`https://api.agatz.xyz/api/xvideo?message=${randomCategory}`);
                    const data = await response.json();
                    
                    if (data.status === 200 && data.data.length > 0) {
                        displayVideos(data.data);
                    } else {
                        showError("No videos found. Try another search.");
                    }
                } catch (error) {
                    showError("Failed to load videos. Please try again.");
                    console.error("Error fetching videos:", error);
                } finally {
                    loadingSpinner.classList.add('hidden');
                }
            }
            
            async function searchVideos() {
                const query = searchInput.value.trim();
                if (!query) return;
                
                loadingSpinner.classList.remove('hidden');
                videosContainer.innerHTML = '';
                featuredVideoSection.classList.add('hidden');
                sectionTitle.textContent = `Search Results for "${query}"`;
                
                try {
                    const response = await fetch(`https://api.agatz.xyz/api/xvideo?message=${encodeURIComponent(query)}`);
                    const data = await response.json();
                    
                    if (data.status === 200 && data.data.length > 0) {
                        displayVideos(data.data);
                    } else {
                        showError("No videos found. Try another search.");
                    }
                } catch (error) {
                    showError("Failed to search videos. Please try again.");
                    console.error("Error searching videos:", error);
                } finally {
                    loadingSpinner.classList.add('hidden');
                }
            }
            
            function displayVideos(videos) {
                videosContainer.innerHTML = '';
                
                videos.forEach(video => {
                    const videoCard = document.createElement('div');
                    videoCard.className = 'video-thumbnail rounded-lg overflow-hidden cursor-pointer relative';
                    videoCard.dataset.videoUrl = video.url;
                    videoCard.dataset.videoTitle = video.title;
                    
                    videoCard.innerHTML = `
                        <img src="${video.thumb}" alt="${video.title}" class="w-full h-48 object-cover">
                        <div class="preview-overlay">
                            <div class="bg-black bg-opacity-70 rounded-full w-16 h-16 flex items-center justify-center">
                                <i class="fas fa-play text-white text-2xl"></i>
                            </div>
                        </div>
                        <div class="absolute bottom-0 left-0 p-3 z-2 w-full">
                            <h3 class="text-white font-medium text-sm line-clamp-2">${video.title}</h3>
                            <span class="duration-badge bg-black bg-opacity-70 text-white text-xs px-2 py-1 rounded">
                                ${video.duration}
                            </span>
                        </div>
                    `;
                    
                    // Mouse enter event for preview
                    videoCard.addEventListener('mouseenter', function() {
                        this.querySelector('img').style.transform = 'scale(1.05)';
                    });
                    
                    // Mouse leave event
                    videoCard.addEventListener('mouseleave', function() {
                        this.querySelector('img').style.transform = 'scale(1)';
                    });
                    
                    // Click event to play video
                    videoCard.addEventListener('click', function() {
                        playVideo(video);
                    });
                    
                    videosContainer.appendChild(videoCard);
                });
            }
            
            function playVideo(video) {
                currentVideoData = video;
                featuredVideoSection.classList.remove('hidden');
                downloadOptions.classList.add('hidden');
                telegramSection.classList.add('hidden');
                videoChapters.classList.add('hidden');
                
                // Scroll to featured video section
                featuredVideoSection.scrollIntoView({ behavior: 'smooth' });
                
                // Set video details
                videoTitle.textContent = video.title;
                videoViews.textContent = 'Loading views...';
                videoLikes.textContent = 'Loading likes...';
                videoDislikes.textContent = 'Loading dislikes...';
                
                // Show loading state in video player
                videoPlayer.poster(video.thumb);
                videoPlayer.src({});
                videoPlayer.ready(function() {
                    this.addClass('vjs-waiting');
                    this.one('loadedmetadata', function() {
                        this.removeClass('vjs-waiting');
                        // Show speed and quality controls
                        speedControl.classList.remove('hidden');
                        qualitySelector.classList.remove('hidden');
                    });
                });
                
                // Fetch video details and source
                fetchVideoDetails(video.url);
            }
            
            async function fetchVideoDetails(videoUrl) {
                try {
                    const response = await fetch(`https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(videoUrl)}`);
                    const data = await response.json();
                    
                    if (data.status === 200 && data.data) {
                        const details = data.data;
                        
                        videoViews.textContent = details.views || 'N/A';
                        videoLikes.textContent = details.like_count || 'N/A';
                        videoDislikes.textContent = details.dislike_count || 'N/A';
                        
                        // Update current video data with additional details
                        currentVideoData.details = details;
                        
                        // Set video source if available
                        if (details.url) {
                            // Reset quality selector
                            videoQuality.innerHTML = '<option value="auto" selected>Auto Quality</option>';
                            videoQualities = [];
                            
                            // Set the main source
                            videoPlayer.src({
                                src: details.url,
                                type: 'video/mp4'
                            });
                            
                            // Add quality options if available
                            if (details.qualities && details.qualities.length > 0) {
                                details.qualities.forEach((quality, index) => {
                                    const option = document.createElement('option');
                                    option.value = quality.label;
                                    option.textContent = quality.label;
                                    videoQuality.appendChild(option);
                                    videoQualities.push({
                                        label: quality.label,
                                        index: index,
                                        src: quality.url
                                    });
                                });
                            }
                            
                            videoPlayer.poster(details.thumb || currentVideoData.thumb);
                            
                            // Generate chapters if available
                            if (details.chapters && details.chapters.length > 0) {
                                videoChaptersData = details.chapters;
                                generateVideoChapters();
                                videoChapters.classList.remove('hidden');
                            }
                        } else {
                            videoPlayer.poster(currentVideoData.thumb);
                            videoPlayer.addClass('vjs-error');
                        }
                    }
                } catch (error) {
                    console.error("Error fetching video details:", error);
                    videoPlayer.addClass('vjs-error');
                }
            }
            
            function generateVideoChapters() {
                chapterList.innerHTML = '';
                chapterMarkers.innerHTML = '';
                
                if (!videoPlayer || !videoChaptersData.length) return;
                
                const duration = videoPlayer.duration();
                
                videoChaptersData.forEach((chapter, index) => {
                    // Add chapter to list
                    const chapterItem = document.createElement('div');
                    chapterItem.className = 'bg-gray-700 hover:bg-gray-600 p-2 rounded cursor-pointer';
                    chapterItem.innerHTML = `
                        <div class="font-medium text-sm">${chapter.title}</div>
                        <div class="text-xs text-gray-400">${formatTime(chapter.startTime)}</div>
                    `;
                    chapterItem.addEventListener('click', () => {
                        videoPlayer.currentTime(chapter.startTime);
                    });
                    chapterList.appendChild(chapterItem);
                    
                    // Add marker to progress bar
                    if (duration > 0) {
                        const markerPosition = (chapter.startTime / duration) * 100;
                        const marker = document.createElement('div');
                        marker.className = 'progress-marker';
                        marker.style.left = `${markerPosition}%`;
                        marker.setAttribute('data-time', formatTime(chapter.startTime));
                        chapterMarkers.appendChild(marker);
                    }
                });
                
                // Update progress bar on timeupdate
                videoPlayer.on('timeupdate', function() {
                    if (duration > 0) {
                        const currentTime = videoPlayer.currentTime();
                        const progressPercent = (currentTime / duration) * 100;
                        progressBar.style.width = `${progressPercent}%`;
                    }
                });
            }
            
            function formatTime(seconds) {
                const mins = Math.floor(seconds / 60);
                const secs = Math.floor(seconds % 60);
                return `${mins}:${secs < 10 ? '0' : ''}${secs}`;
            }
            
            async function fetchDownloadUrl(videoUrl) {
                try {
                    const response = await fetch(`https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(videoUrl)}`);
                    const data = await response.json();
                    
                    if (data.status === 200 && data.data) {
                        const videoData = data.data;
                        
                        // Set standard quality download
                        if (videoData.url) {
                            downloadLink.href = videoData.url;
                            downloadLink.setAttribute('download', `${videoData.title || 'video'}.mp4`);
                            downloadLink.innerHTML = `<i class="fas fa-video mr-2"></i> MP4 (${videoData.quality || 'Standard'})`;
                            downloadLink.classList.remove('text-gray-400', 'hover:bg-gray-600');
                        } else {
                            downloadLink.href = '#';
                            downloadLink.innerHTML = '<i class="fas fa-times-circle mr-2"></i> Download not available';
                            downloadLink.classList.add('text-gray-400');
                            downloadLink.classList.remove('hover:bg-gray-600');
                        }
                        
                        // Set HD quality download (if available)
                        if (videoData.hd_url) {
                            downloadHD.href = videoData.hd_url;
                            downloadHD.setAttribute('download', `${videoData.title || 'video'}_HD.mp4`);
                            downloadHD.innerHTML = `<i class="fas fa-high-definition mr-2"></i> HD Quality`;
                            downloadHD.classList.remove('hidden');
                        } else {
                            downloadHD.classList.add('hidden');
                        }
                        
                        // Set other quality options if available
                        if (videoData.qualities && videoData.qualities.length > 0) {
                            videoData.qualities.forEach(quality => {
                                if (quality.label.includes('480')) {
                                    download480p.href = quality.url;
                                    download480p.setAttribute('download', `${videoData.title || 'video'}_480p.mp4`);
                                    download480p.innerHTML = `<i class="fas fa-video mr-2"></i> 480p`;
                                    download480p.classList.remove('hidden');
                                } else if (quality.label.includes('720')) {
                                    download720p.href = quality.url;
                                    download720p.setAttribute('download', `${videoData.title || 'video'}_720p.mp4`);
                                    download720p.innerHTML = `<i class="fas fa-video mr-2"></i> 720p`;
                                    download720p.classList.remove('hidden');
                                } else if (quality.label.includes('1080')) {
                                    download1080p.href = quality.url;
                                    download1080p.setAttribute('download', `${videoData.title || 'video'}_1080p.mp4`);
                                    download1080p.innerHTML = `<i class="fas fa-video mr-2"></i> 1080p`;
                                    download1080p.classList.remove('hidden');
                                }
                            });
                        } else {
                            download480p.classList.add('hidden');
                            download720p.classList.add('hidden');
                            download1080p.classList.add('hidden');
                        }
                    } else {
                        downloadLink.href = '#';
                        downloadLink.innerHTML = '<i class="fas fa-times-circle mr-2"></i> Download not available';
                        downloadLink.classList.add('text-gray-400');
                        downloadLink.classList.remove('hover:bg-gray-600');
                        downloadHD.classList.add('hidden');
                        download480p.classList.add('hidden');
                        download720p.classList.add('hidden');
                        download1080p.classList.add('hidden');
                    }
                } catch (error) {
                    console.error("Error fetching download URL:", error);
                    downloadLink.href = '#';
                    downloadLink.innerHTML = '<i class="fas fa-times-circle mr-2"></i> Error loading download';
                    downloadLink.classList.add('text-gray-400');
                    downloadLink.classList.remove('hover:bg-gray-600');
                    downloadHD.classList.add('hidden');
                    download480p.classList.add('hidden');
                    download720p.classList.add('hidden');
                    download1080p.classList.add('hidden');
                }
            }
            
            async function sendToTelegram() {
                const userId = telegramUserId.value.trim();
                const quality = telegramQuality.value;
                
                if (!userId) {
                    telegramStatus.textContent = 'Please enter your Telegram User ID';
                    telegramStatus.classList.remove('hidden', 'text-green-500');
                    telegramStatus.classList.add('text-red-500');
                    return;
                }
                
                // Save user ID to localStorage
                localStorage.setItem('telegramUserId', userId);
                
                telegramStatus.textContent = 'Sending video to Telegram...';
                telegramStatus.classList.remove('hidden', 'text-red-500');
                telegramStatus.classList.add('text-blue-500');
                
                try {
                    // First get the download URL for the selected quality
                    const response = await fetch(`https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(currentVideoData.url)}`);
                    const data = await response.json();
                    
                    if (data.status === 200 && data.data) {
                        let downloadUrl = data.data.url; // Default to standard quality
                        
                        // Find the selected quality URL
                        if (quality !== 'best' && data.data.qualities && data.data.qualities.length > 0) {
                            const selectedQuality = data.data.qualities.find(q => 
                                quality === '720p' && q.label.includes('720') ||
                                quality === '480p' && q.label.includes('480') ||
                                quality === '360p' && q.label.includes('360')
                            );
                            
                            if (selectedQuality) {
                                downloadUrl = selectedQuality.url;
                            }
                        } else if (quality === 'best' && data.data.hd_url) {
                            downloadUrl = data.data.hd_url;
                        }
                        
                        // Now send to Telegram bot
                        const botResponse = await fetch(`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage`, {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json',
                            },
                            body: JSON.stringify({
                                chat_id: userId,
                                text: `Here's your video: ${currentVideoData.title}\n\nDownload: ${downloadUrl}`,
                                disable_web_page_preview: false
                            })
                        });
                        
                        const botData = await botResponse.json();
                        
                        if (botData.ok) {
                            telegramStatus.textContent = 'Video sent successfully to Telegram!';
                            telegramStatus.classList.remove('text-red-500', 'text-blue-500');
                            telegramStatus.classList.add('text-green-500');
                        } else {
                            telegramStatus.textContent = 'Failed to send video. Please check your User ID.';
                            telegramStatus.classList.remove('text-green-500', 'text-blue-500');
                            telegramStatus.classList.add('text-red-500');
                        }
                    } else {
                        telegramStatus.textContent = 'Failed to get video download link.';
                        telegramStatus.classList.remove('text-green-500', 'text-blue-500');
                        telegramStatus.classList.add('text-red-500');
                    }
                } catch (error) {
                    console.error("Error sending to Telegram:", error);
                    telegramStatus.textContent = 'Error sending video. Please try again.';
                    telegramStatus.classList.remove('text-green-500', 'text-blue-500');
                    telegramStatus.classList.add('text-red-500');
                }
            }
            
            function showError(message) {
                videosContainer.innerHTML = `
                    <div class="col-span-full text-center py-10">
                        <i class="fas fa-exclamation-triangle text-4xl text-yellow-500 mb-4"></i>
                        <p class="text-xl">${message}</p>
                    </div>
                `;
            }
            
            // Initialize Video.js player with advanced features
            let videoPlayer = videojs('mainVideoPlayer', {
                controls: true,
                autoplay: false,
                preload: 'auto',
                fluid: true,
                responsive: true,
                playbackRates: [0.5, 1, 1.5, 2],
                controlBar: {
                    children: [
                        'playToggle',
                        'progressControl',
                        'volumePanel',
                        'currentTimeDisplay',
                        'timeDivider',
                        'durationDisplay',
                        'playbackRateMenuButton',
                        'fullscreenToggle'
                    ]
                }
            });
            
            // Add keyboard shortcuts
            document.addEventListener('keydown', function(e) {
                if (!videoPlayer) return;
                
                // Space to play/pause
                if (e.key === ' ' && document.activeElement.tagName !== 'INPUT') {
                    e.preventDefault();
                    if (videoPlayer.paused()) {
                        videoPlayer.play();
                    } else {
                        videoPlayer.pause();
                    }
                }
                
                // Arrow keys for seeking
                if (e.key === 'ArrowLeft') {
                    videoPlayer.currentTime(videoPlayer.currentTime() - 5);
                }
                if (e.key === 'ArrowRight') {
                    videoPlayer.currentTime(videoPlayer.currentTime() + 5);
                }
                
                // M for mute
                if (e.key === 'm' || e.key === 'M') {
                    videoPlayer.muted(!videoPlayer.muted());
                }
                
                // F for fullscreen
                if (e.key === 'f' || e.key === 'F') {
                    if (videoPlayer.isFullscreen()) {
                        videoPlayer.exitFullscreen();
                    } else {
                        videoPlayer.requestFullscreen();
                    }
                }
            });
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px; position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">
  Made with 
  <img alt="Logo" src="https://iili.io/3sXdfbp.md.png" style="width: 16px; height: 16px; vertical-align: middle; display: inline-block; margin-right: 3px; filter: brightness(0) invert(1);"/>
<a href="https://t.me/EliteAdultsend_bot" style="color: #fff; text-decoration: underline;" target="_blank">Telegram Downloader</a> -  🤖
  <a href="https://t.me/DARKDATAOFFICIAL" style="color: #fff; text-decoration: underline;" target="_blank">Owner Contact</a>
</p>
</body>
</html>