-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (26 loc) · 854 Bytes
/
main.py
File metadata and controls
31 lines (26 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import Flask, request, jsonify
import yt_dlp
app = Flask(__name__)
@app.route('/download', methods=['GET'])
def download():
url = request.args.get('url')
if not url:
return jsonify({'error': 'No URL provided'}), 400
ydl_opts = {
'format': 'best[ext=mp4]/best',
'quiet': True,
'no_warnings': True,
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
video_url = info.get('url') or info['formats'][-1]['url']
return jsonify({
'success': True,
'url': video_url,
'title': info.get('title', ''),
})
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)