aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/watch.py
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-03-27 21:23:03 -0500
committerAstounds <kirito@disroot.org>2026-03-27 21:23:03 -0500
commite03f40d72801b8954cd378aaf0e595ccb29f8091 (patch)
tree7ada367f2b275d53b80503630f121a4d0464f9bd /youtube/watch.py
parent22c72aa842efa6d1dca3bb95eeb47122537ce12a (diff)
downloadyt-local-e03f40d72801b8954cd378aaf0e595ccb29f8091.tar.lz
yt-local-e03f40d72801b8954cd378aaf0e595ccb29f8091.tar.xz
yt-local-e03f40d72801b8954cd378aaf0e595ccb29f8091.zip
fix error handling, null URLs in templates, and Radio playlist support
- Global error handler: friendly messages for 429, 502, 403, 400 instead of raw tracebacks. Filter FetchError from Flask logger. - Fix None URLs in templates: protect href/src in common_elements, playlist, watch, and comments templates against None values. - Radio playlists (RD...): redirect /playlist?list=RD... to /watch?v=...&list=RD... since YouTube only supports them in player. - Wrap player client fallbacks (ios, tv_embedded) in try/catch so a failed fallback doesn't crash the whole page.
Diffstat (limited to 'youtube/watch.py')
-rw-r--r--youtube/watch.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/youtube/watch.py b/youtube/watch.py
index 2fbc1fc..360fbc9 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -431,14 +431,20 @@ def extract_info(video_id, use_invidious, playlist_id=None, index=None):
# Fallback to 'ios' if no valid URLs are found
if not info.get('formats') or info.get('player_urls_missing'):
print(f"No URLs found in '{primary_client}', attempting with '{fallback_client}'.")
- player_response = fetch_player_response(fallback_client, video_id) or {}
- yt_data_extract.update_with_new_urls(info, player_response)
+ try:
+ player_response = fetch_player_response(fallback_client, video_id) or {}
+ yt_data_extract.update_with_new_urls(info, player_response)
+ except util.FetchError as e:
+ print(f"Fallback '{fallback_client}' failed: {e}")
# Final attempt with 'tv_embedded' if there are still no URLs
if not info.get('formats') or info.get('player_urls_missing'):
print(f"No URLs found in '{fallback_client}', attempting with '{last_resort_client}'")
- player_response = fetch_player_response(last_resort_client, video_id) or {}
- yt_data_extract.update_with_new_urls(info, player_response)
+ try:
+ player_response = fetch_player_response(last_resort_client, video_id) or {}
+ yt_data_extract.update_with_new_urls(info, player_response)
+ except util.FetchError as e:
+ print(f"Fallback '{last_resort_client}' failed: {e}")
# signature decryption
if info.get('formats'):