2024-11-21 21:16:27 -05:00

42 lines
1.0 KiB
Python

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)