diff options
| author | Astounds <kirito@disroot.org> | 2026-03-27 19:22:12 -0500 |
|---|---|---|
| committer | Astounds <kirito@disroot.org> | 2026-03-27 19:22:12 -0500 |
| commit | 56ecd6cb1b461bd3622c669936050fa7e4d83542 (patch) | |
| tree | a67dc3b8dc75ea20a00e25162949626bd1c6f2a8 /youtube/subscriptions.py | |
| parent | f629565e77ae7178950fceaac7ba650b97bd4c51 (diff) | |
| download | yt-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/subscriptions.py')
| -rw-r--r-- | youtube/subscriptions.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py index 0cb5e95..3326a51 100644 --- a/youtube/subscriptions.py +++ b/youtube/subscriptions.py @@ -1089,12 +1089,26 @@ def serve_subscription_thumbnail(thumbnail): f.close() return flask.Response(image, mimetype='image/jpeg') - url = f"https://i.ytimg.com/vi/{video_id}/hq720.jpg" - try: - image = util.fetch_url(url, report_text="Saved thumbnail: " + video_id) - except urllib.error.HTTPError as e: - print("Failed to download thumbnail for " + video_id + ": " + str(e)) - flask.abort(e.code) + image = None + for quality in ('hq720.jpg', 'sddefault.jpg', 'hqdefault.jpg'): + url = f"https://i.ytimg.com/vi/{video_id}/{quality}" + try: + image = util.fetch_url(url, report_text="Saved thumbnail: " + video_id) + break + except util.FetchError as e: + if '404' in str(e): + continue + print("Failed to download thumbnail for " + video_id + ": " + str(e)) + flask.abort(500) + except urllib.error.HTTPError as e: + if e.code == 404: + continue + print("Failed to download thumbnail for " + video_id + ": " + str(e)) + flask.abort(e.code) + + if image is None: + flask.abort(404) + try: f = open(thumbnail_path, 'wb') except FileNotFoundError: |
