From 56ecd6cb1b461bd3622c669936050fa7e4d83542 Mon Sep 17 00:00:00 2001 From: Astounds Date: Fri, 27 Mar 2026 19:22:12 -0500 Subject: 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. --- youtube/subscriptions.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'youtube/subscriptions.py') 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: -- cgit v1.2.3