Spaces:
Build error
Build error
Update srv.py
Browse files
srv.py
CHANGED
|
@@ -43,8 +43,6 @@ def download():
|
|
| 43 |
if not url:
|
| 44 |
return jsonify({'error': 'URL is required'}), 400
|
| 45 |
|
| 46 |
-
file_name = None
|
| 47 |
-
|
| 48 |
try:
|
| 49 |
if format_type == 'mp3':
|
| 50 |
ydl_opts = {
|
|
@@ -57,18 +55,18 @@ def download():
|
|
| 57 |
'preferredquality': '192',
|
| 58 |
}],
|
| 59 |
}
|
| 60 |
-
else:
|
| 61 |
quality_map = {
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
selected_quality = quality_map.get(quality, quality_map['best'])
|
| 72 |
|
| 73 |
ydl_opts = {
|
| 74 |
'format': selected_quality,
|
|
@@ -89,15 +87,15 @@ def download():
|
|
| 89 |
file_name,
|
| 90 |
as_attachment=True,
|
| 91 |
download_name=os.path.basename(file_name),
|
| 92 |
-
mimetype='
|
| 93 |
)
|
| 94 |
|
| 95 |
except Exception as e:
|
| 96 |
return jsonify({'error': str(e)}), 500
|
| 97 |
|
| 98 |
finally:
|
| 99 |
-
if file_name and os.path.exists(file_name):
|
| 100 |
os.remove(file_name)
|
| 101 |
|
| 102 |
if __name__ == '__main__':
|
| 103 |
-
|
|
|
|
| 43 |
if not url:
|
| 44 |
return jsonify({'error': 'URL is required'}), 400
|
| 45 |
|
|
|
|
|
|
|
| 46 |
try:
|
| 47 |
if format_type == 'mp3':
|
| 48 |
ydl_opts = {
|
|
|
|
| 55 |
'preferredquality': '192',
|
| 56 |
}],
|
| 57 |
}
|
| 58 |
+
else:
|
| 59 |
quality_map = {
|
| 60 |
+
'144': 'bv*[height=144][ext=mp4]+ba[ext=m4a]/b[height=144][ext=mp4]',
|
| 61 |
+
'240': 'bv*[height=240][ext=mp4]+ba[ext=m4a]/b[height=240][ext=mp4]',
|
| 62 |
+
'360': 'bv*[height=360][ext=mp4]+ba[ext=m4a]/b[height=360][ext=mp4]',
|
| 63 |
+
'480': 'bv*[height=480][ext=mp4]+ba[ext=m4a]/b[height=480][ext=mp4]',
|
| 64 |
+
'720': 'bv*[height=720][ext=mp4]+ba[ext=m4a]/b[height=720][ext=mp4]',
|
| 65 |
+
'1080': 'bv*[height=1080][ext=mp4]+ba[ext=m4a]/b[height=1080][ext=mp4]',
|
| 66 |
+
'best': 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]'
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
selected_quality = quality_map.get(quality, quality_map['best'])
|
| 70 |
|
| 71 |
ydl_opts = {
|
| 72 |
'format': selected_quality,
|
|
|
|
| 87 |
file_name,
|
| 88 |
as_attachment=True,
|
| 89 |
download_name=os.path.basename(file_name),
|
| 90 |
+
mimetype='video/mp4' if format_type == 'mp4' else 'audio/mp3'
|
| 91 |
)
|
| 92 |
|
| 93 |
except Exception as e:
|
| 94 |
return jsonify({'error': str(e)}), 500
|
| 95 |
|
| 96 |
finally:
|
| 97 |
+
if 'file_name' in locals() and os.path.exists(file_name):
|
| 98 |
os.remove(file_name)
|
| 99 |
|
| 100 |
if __name__ == '__main__':
|
| 101 |
+
app.run(host='0.0.0.0', port=7860, debug=True,threaded=True)
|