<?php
$formats = [];
if(isset($_GET['url'])) {
    $apiUrl = "https://loader.to/api/extract?url=" . urlencode($_GET['url']) . "&format=mp4,mp3,wav,avi";
    $response = file_get_contents($apiUrl);
    $data = json_decode($response, true);
    $formats = $data['formats'] ?? [];
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>YouTube Downloader | Furiebstvo</title>
    <style>
        body { 
            background: #1a1a2e; 
            color: #e6e6ff; 
            font-family: Arial; 
            margin: 0; 
            padding: 20px;
        }
        .container { 
            max-width: 800px; 
            margin: 0 auto; 
            background: #2d2d44; 
            padding: 30px; 
            border-radius: 10px; 
            box-shadow: 0 0 20px rgba(102, 0, 153, 0.3);
        }
        h1 { 
            color: #b366ff; 
            text-align: center; 
            margin-bottom: 30px;
        }
        input, select, button { 
            padding: 12px; 
            margin: 5px; 
            border: none; 
            border-radius: 5px;
        }
        input { 
            width: 70%; 
            background: #3a3a52; 
            color: white;
        }
        select { 
            background: #3a3a52; 
            color: white;
        }
        button { 
            background: #663399; 
            color: white; 
            cursor: pointer; 
            transition: 0.3s;
        }
        button:hover { 
            background: #7a4ca3;
        }
        .format-option { 
            background: #3a3a52; 
            padding: 10px; 
            margin: 5px 0; 
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>YouTube Video Downloader</h1>
        <form method="get">
            <input type="text" name="url" placeholder="Paste YouTube URL here" required>
            <button type="submit">Get Formats</button>
        </form>
        
        <?php if(!empty($formats)): ?>
            <h3>Available Formats:</h3>
            <?php foreach($formats as $format): ?>
                <div class="format-option">
                    <a href="<?= $format['url'] ?>" style="color: #b366ff; text-decoration: none;">
                        Download: <?= $format['format'] ?> (Quality: <?= $format['quality'] ?>)
                    </a>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</body>
</html>