GPTfree api commited on
Commit
159d136
·
verified ·
1 Parent(s): 4b56793

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
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
- # yt-dlpが実行された結果を表示(デバッグ用)
36
- print(result.stdout.decode())
37
- print(result.stderr.decode())
38
 
39
  # ダウンロードされたファイルのパスを取得
40
- # ここでは、yt-dlpの出力ファイル名が`%(title)s.%(ext)s`形式で保存されることを前提としています
41
- downloaded_file = output_file % {'title': video_url.split('=')[-1], 'ext': 'mp4'}
 
 
42
 
43
  # ファイルをクライアントに送信
44
- return send_file(downloaded_file, as_attachment=True)
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