aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/watch.py
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-03-27 19:22:12 -0500
committerAstounds <kirito@disroot.org>2026-03-27 19:22:12 -0500
commit56ecd6cb1b461bd3622c669936050fa7e4d83542 (patch)
treea67dc3b8dc75ea20a00e25162949626bd1c6f2a8 /youtube/watch.py
parentf629565e77ae7178950fceaac7ba650b97bd4c51 (diff)
downloadyt-local-56ecd6cb1b461bd3622c669936050fa7e4d83542.tar.lz
yt-local-56ecd6cb1b461bd3622c669936050fa7e4d83542.tar.xz
yt-local-56ecd6cb1b461bd3622c669936050fa7e4d83542.zip
fix: use YouTube-provided thumbnail URLs instead of hardcoded hq720.jpg
Videos without hq720.jpg thumbnails caused mass 404 errors. Now preserves the actual thumbnail URL from YouTube's API response, falls back to hqdefault.jpg only when no thumbnail is provided. Also picks highest quality thumbnail from API (thumbnails[-1]) and adds progressive fallback for subscription/download functions.
Diffstat (limited to 'youtube/watch.py')
-rw-r--r--youtube/watch.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/youtube/watch.py b/youtube/watch.py
index 14f1dae..b76a462 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -628,12 +628,12 @@ def get_watch_page(video_id=None):
# prefix urls, and other post-processing not handled by yt_data_extract
for item in info['related_videos']:
- # For playlists, use first_video_id for thumbnail, not playlist id
- if item.get('type') == 'playlist' and item.get('first_video_id'):
- item['thumbnail'] = "https://i.ytimg.com/vi/{}/hq720.jpg".format(item['first_video_id'])
- elif item.get('type') == 'video':
- item['thumbnail'] = "https://i.ytimg.com/vi/{}/hq720.jpg".format(item['id'])
- # For other types, keep existing thumbnail or skip
+ # Only set thumbnail if YouTube didn't provide one
+ if not item.get('thumbnail'):
+ if item.get('type') == 'playlist' and item.get('first_video_id'):
+ item['thumbnail'] = "https://i.ytimg.com/vi/{}/hqdefault.jpg".format(item['first_video_id'])
+ elif item.get('type') == 'video' and item.get('id'):
+ item['thumbnail'] = "https://i.ytimg.com/vi/{}/hqdefault.jpg".format(item['id'])
util.prefix_urls(item)
util.add_extra_html_info(item)
for song in info['music_list']:
@@ -641,9 +641,9 @@ def get_watch_page(video_id=None):
if info['playlist']:
playlist_id = info['playlist']['id']
for item in info['playlist']['items']:
- # Set high quality thumbnail for playlist videos
- if item.get('type') == 'video' and item.get('id'):
- item['thumbnail'] = "https://i.ytimg.com/vi/{}/hq720.jpg".format(item['id'])
+ # Only set thumbnail if YouTube didn't provide one
+ if not item.get('thumbnail') and item.get('type') == 'video' and item.get('id'):
+ item['thumbnail'] = "https://i.ytimg.com/vi/{}/hqdefault.jpg".format(item['id'])
util.prefix_urls(item)
util.add_extra_html_info(item)
if playlist_id: