Thursday, July 4, 2024

YouTube video downloader

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>YouTube Video Downloader</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .container {
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 500px;
            text-align: center;
        }
        input {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        button {
            padding: 10px 20px;
            background-color: #28a745;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:disabled {
            background-color: #ccc;
        }
        .message {
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>YouTube Video Downloader</h1>
        <input type="text" id="videoUrl" placeholder="Enter YouTube Video URL">
        <button id="downloadBtn">Download</button>
        <div id="message" class="message"></div>
    </div>

    <script>
        document.getElementById('downloadBtn').addEventListener('click', function() {
            const videoUrl = document.getElementById('videoUrl').value;
            const messageDiv = document.getElementById('message');

            if (!videoUrl) {
                messageDiv.textContent = 'Please enter a YouTube video URL.';
                return;
            }

            messageDiv.textContent = 'Downloading...';

            // Replace this with the actual API endpoint
            const apiEndpoint = 'https://example.com/api/download';

            fetch(apiEndpoint, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ url: videoUrl })
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    const link = document.createElement('a');
                    link.href = data.downloadUrl;
                    link.download = data.filename;
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                    messageDiv.textContent = 'Download started.';
                } else {
                    messageDiv.textContent = 'Error: ' + data.message;
                }
            })
            .catch(error => {
                messageDiv.textContent = 'An error occurred. Please try again.';
                console.error('Error:', error);
            });
        });
    </script>
</body>
</html>

YouTube Video Downloader

YouTube Video Downloader