Spaces:
Sleeping
Sleeping
GPTfree api
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
from flask import Flask, request, send_file, jsonify
|
2 |
import os
|
3 |
import subprocess
|
4 |
-
from yt_dlp import YoutubeDL
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
@@ -17,25 +16,29 @@ def download_video():
|
|
17 |
output_path = "downloads"
|
18 |
os.makedirs(output_path, exist_ok=True) # ダウンロード先ディレクトリが存在しない場合、作成する
|
19 |
|
20 |
-
#
|
21 |
output_file = os.path.join(output_path, '%(title)s.%(ext)s')
|
22 |
|
23 |
-
#
|
24 |
-
cookies_file = 'cookies.txt'
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
# yt-dlp
|
27 |
-
|
28 |
-
'cookies': cookies_file, # クッキーを指定
|
29 |
-
'outtmpl': output_file, # 出力ファイルのパスとテンプレート
|
30 |
-
'format': 'bestvideo+bestaudio/best', # 最高画質で動画と音声を選択
|
31 |
-
}
|
32 |
|
33 |
-
# yt-dlp
|
34 |
-
|
35 |
-
|
36 |
-
downloaded_file = ydl.prepare_filename(info) # ダウンロードされたファイルのパスを取得
|
37 |
|
38 |
-
#
|
|
|
|
|
|
|
39 |
return send_file(downloaded_file, as_attachment=True)
|
40 |
|
41 |
except Exception as e:
|
|
|
1 |
from flask import Flask, request, send_file, jsonify
|
2 |
import os
|
3 |
import subprocess
|
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
|
|
16 |
output_path = "downloads"
|
17 |
os.makedirs(output_path, exist_ok=True) # ダウンロード先ディレクトリが存在しない場合、作成する
|
18 |
|
19 |
+
# 出力ファイル名テンプレート
|
20 |
output_file = os.path.join(output_path, '%(title)s.%(ext)s')
|
21 |
|
22 |
+
# yt-dlpコマンドの設定
|
23 |
+
cookies_file = 'cookies.txt' # エクスポートしたクッキーを指定
|
24 |
+
cmd = [
|
25 |
+
'yt-dlp',
|
26 |
+
'--cookies', cookies_file,
|
27 |
+
'--output', output_file, # 出力ファイルのパスを指定
|
28 |
+
video_url
|
29 |
+
]
|
30 |
|
31 |
+
# yt-dlpコマンドを実行
|
32 |
+
result = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
# yt-dlpが実行された結果を表示(デバッグ用)
|
35 |
+
print(result.stdout.decode())
|
36 |
+
print(result.stderr.decode())
|
|
|
37 |
|
38 |
+
# ダウンロードされたファイルのパスを取得
|
39 |
+
downloaded_file = output_file % {'title': video_url.split('=')[-1], 'ext': 'mp4'}
|
40 |
+
|
41 |
+
# ファイルをクライアントに送信
|
42 |
return send_file(downloaded_file, as_attachment=True)
|
43 |
|
44 |
except Exception as e:
|