Spaces:
Sleeping
Sleeping
GPTfree api
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -32,16 +32,18 @@ def download_video():
|
|
32 |
# yt-dlpコマンドを実行
|
33 |
result = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
34 |
|
35 |
-
#
|
36 |
-
print(result.stdout.decode())
|
37 |
-
print(result.stderr.decode())
|
38 |
|
39 |
# ダウンロードされたファイルのパスを取得
|
40 |
-
#
|
41 |
-
|
|
|
|
|
42 |
|
43 |
# ファイルをクライアントに送信
|
44 |
-
return send_file(
|
45 |
|
46 |
except Exception as e:
|
47 |
return jsonify({"error": str(e)}), 500
|
|
|
32 |
# yt-dlpコマンドを実行
|
33 |
result = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
34 |
|
35 |
+
# 出力とエラーメッセージをログに表示
|
36 |
+
print(result.stdout.decode()) # コマンド実行結果を表示
|
37 |
+
print(result.stderr.decode()) # エラーメッセージを表示
|
38 |
|
39 |
# ダウンロードされたファイルのパスを取得
|
40 |
+
# 出力ファイル名の形式をチェック
|
41 |
+
file_path = os.path.join(output_path, 'nRh5QyKIs8o.mp4') # 固定ファイル名でなく、動的に取得する方法が良い
|
42 |
+
if not os.path.exists(file_path):
|
43 |
+
return jsonify({"error": "File not found"}), 404
|
44 |
|
45 |
# ファイルをクライアントに送信
|
46 |
+
return send_file(file_path, as_attachment=True)
|
47 |
|
48 |
except Exception as e:
|
49 |
return jsonify({"error": str(e)}), 500
|