Update app.py
Browse files
app.py
CHANGED
|
@@ -40,6 +40,8 @@ def try_download_transcript(video_id):
|
|
| 40 |
return None
|
| 41 |
|
| 42 |
def download_audio_youtube(url, output_path="audio.wav", cookies_path=None):
|
|
|
|
|
|
|
| 43 |
fallback_video_path = "fallback_video.mp4"
|
| 44 |
|
| 45 |
ydl_opts = {
|
|
@@ -48,6 +50,7 @@ def download_audio_youtube(url, output_path="audio.wav", cookies_path=None):
|
|
| 48 |
"user_agent": "com.google.android.youtube/17.31.35 (Linux; U; Android 11)",
|
| 49 |
"compat_opts": ["allow_unplayable_formats"]
|
| 50 |
}
|
|
|
|
| 51 |
if cookies_path:
|
| 52 |
ydl_opts["cookiefile"] = cookies_path
|
| 53 |
|
|
@@ -55,7 +58,20 @@ def download_audio_youtube(url, output_path="audio.wav", cookies_path=None):
|
|
| 55 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 56 |
ydl.download([url])
|
| 57 |
except Exception as e:
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
return extract_audio_from_video(fallback_video_path, audio_path=output_path)
|
| 61 |
|
|
|
|
| 40 |
return None
|
| 41 |
|
| 42 |
def download_audio_youtube(url, output_path="audio.wav", cookies_path=None):
|
| 43 |
+
import subprocess
|
| 44 |
+
|
| 45 |
fallback_video_path = "fallback_video.mp4"
|
| 46 |
|
| 47 |
ydl_opts = {
|
|
|
|
| 50 |
"user_agent": "com.google.android.youtube/17.31.35 (Linux; U; Android 11)",
|
| 51 |
"compat_opts": ["allow_unplayable_formats"]
|
| 52 |
}
|
| 53 |
+
|
| 54 |
if cookies_path:
|
| 55 |
ydl_opts["cookiefile"] = cookies_path
|
| 56 |
|
|
|
|
| 58 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 59 |
ydl.download([url])
|
| 60 |
except Exception as e:
|
| 61 |
+
# On failure, run yt-dlp in subprocess to list formats
|
| 62 |
+
try:
|
| 63 |
+
list_cmd = ["yt-dlp", "-F", url]
|
| 64 |
+
if cookies_path:
|
| 65 |
+
list_cmd += ["--cookies", cookies_path]
|
| 66 |
+
result = subprocess.run(list_cmd, capture_output=True, text=True, timeout=15)
|
| 67 |
+
formats = result.stdout or "No formats found."
|
| 68 |
+
except Exception as format_err:
|
| 69 |
+
formats = f"⚠️ Could not list formats due to: {format_err}"
|
| 70 |
+
|
| 71 |
+
raise RuntimeError(
|
| 72 |
+
f"yt-dlp failed: {e}\n\n"
|
| 73 |
+
f"Available formats for this video:\n\n{formats}"
|
| 74 |
+
)
|
| 75 |
|
| 76 |
return extract_audio_from_video(fallback_video_path, audio_path=output_path)
|
| 77 |
|