-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (33 loc) · 1.16 KB
/
main.py
File metadata and controls
41 lines (33 loc) · 1.16 KB
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
32
33
34
35
36
37
38
39
40
41
from flask import Flask, request, jsonify
import yt_dlp
app = Flask(__name__)
@app.route('/')
def root():
return "Сервер работает!"
@app.route('/get_link', methods=['POST'])
def get_link():
try:
data = request.get_json()
url = data.get("url")
format_type = data.get("format", "video")
if not url:
return jsonify({"error": "URL is required"}), 400
ydl_opts = {
'format': 'bestaudio/best' if format_type == "audio" else 'best',
'quiet': True,
'noplaylist': True
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
return jsonify({
"title": info.get("title"),
"url": info.get("url"),
"ext": info.get("ext"),
"duration": info.get("duration")
})
except Exception as e:
import traceback
traceback.print_exc() # 🔥 Лог ошибки в Render
return jsonify({"error": str(e)}), 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)