First Version!

This commit is contained in:
Wesley Neuhaus 2024-11-21 21:16:27 -05:00
parent 56e1486150
commit 3f5d197a48
3 changed files with 120 additions and 0 deletions

74
index.html Normal file
View File

@ -0,0 +1,74 @@
<!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;
max-width: 800px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
.container {
margin-top: 50px;
}
input[type="url"] {
width: 80%;
padding: 10px;
margin: 10px 0;
}
button {
padding: 10px 20px;
background-color: #ff0000;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #cc0000;
}
#status {
margin-top: 20px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h1>YouTube Video Downloader</h1>
<form id="downloadForm">
<input type="url" id="videoUrl" placeholder="Enter YouTube URL" required>
<button type="submit">Download Video</button>
</form>
<div id="status"></div>
</div>
<script>
document.getElementById('downloadForm').addEventListener('submit', function(e) {
e.preventDefault();
const url = document.getElementById('videoUrl').value;
const status = document.getElementById('status');
status.textContent = 'Starting download...';
fetch('http://localhost:5000/download?url=' + encodeURIComponent(url))
.then(response => {
if (!response.ok) {
return response.text().then(text => {
throw new Error(text || 'Download failed');
});
}
status.textContent = 'Download completed!';
})
.catch(error => {
console.error('Error:', error);
status.textContent = 'Error: ' + error.message;
});
});
</script>
</body>
</html>

41
main.py Normal file
View File

@ -0,0 +1,41 @@
from flask import Flask, request, send_file
import yt_dlp
import os
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/')
def index():
return send_file('index.html')
@app.route('/download', methods=['GET'])
def download_video():
try:
video_url = request.args.get('url')
if not video_url:
return "Please provide a YouTube URL", 400
# Configure yt-dlp options
ydl_opts = {
'format': 'best', # Download best quality
'outtmpl': '%(title)s.%(ext)s', # Output template - download to current directory
}
# Download the video
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(video_url, download=True)
return "Download completed", 200
except Exception as e:
print(f"Error: {str(e)}") # Add this for debugging
return str(e), 500
@app.route('/ping')
def ping():
return 'pong'
if __name__ == '__main__':
app.run(debug=True, port=5000)

5
requirements.txt Normal file
View File

@ -0,0 +1,5 @@
# requirements.txt
flask
yt-dlp
flask-cors