soiz commited on
Commit
9f1ef4c
·
verified ·
1 Parent(s): f62ef1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -19,7 +19,14 @@ def download_video():
19
  try:
20
  # YouTube URLを作成
21
  youtube_url = f'https://www.youtube.com/watch?v={video_id}'
22
- yt = YouTube(youtube_url, use_oauth=True, allow_oauth_cache=True)
 
 
 
 
 
 
 
23
 
24
  # ファイル保存用ディレクトリ
25
  download_dir = "downloads"
 
19
  try:
20
  # YouTube URLを作成
21
  youtube_url = f'https://www.youtube.com/watch?v={video_id}'
22
+
23
+ # OAuthを有効化してYouTubeオブジェクトを作成
24
+ try:
25
+ yt = YouTube(youtube_url, use_oauth=True, allow_oauth_cache=True)
26
+ except Exception as e:
27
+ if "device" in str(e).lower():
28
+ return jsonify({'error': 'OAuth authentication required. Please follow the instructions in the log to complete authentication.'}), 401
29
+ return jsonify({'error': str(e)}), 500
30
 
31
  # ファイル保存用ディレクトリ
32
  download_dir = "downloads"