-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (25 loc) · 972 Bytes
/
main.py
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('/info', methods=['GET'])
def get_info():
# Retrieve the URL from query parameters
url = request.args.get('url')
if not url:
return jsonify({"error": "URL is required"}), 400
# Get the cookies from environment variables (Vercel setup)
# If cookies exist, load and pass them to yt-dlp
try:
ydl_opts = {
'quiet': True, # Suppress the standard output
'extract_flat': True, # Only extract info, not download
'forcejson': True, # Get info in JSON format
'cookiefile': 'cookies.txt' # Pass cookies to yt-dlp
}
# Extract video info
info_dict = yt_dlp.YoutubeDL(ydl_opts).extract_info(url, download=False)
return jsonify(info_dict)
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(debug=True)