diff --git a/views.py b/views.py index 00fa9f9..3ed571f 100644 --- a/views.py +++ b/views.py @@ -26,8 +26,21 @@ def thumbnailProxy(received_request): 'error_msg': 'invalid request. pretend this is a thumbnail :D' }), mimetype='application/json', status=400) - thumbnail = requests.get(prefix + "vi/" + received_request, headers=ythdd_globals.getHeaders(caller='proxy'), stream=True) + quality_urls = ['maxresdefault', 'sddefault', 'hqdefault', 'mqdefault', 'default', '1', '2', '3'] + video_id, requested_quality = received_request.split('/') + + thumbnail = requests.get(prefix + "vi/" + video_id + "/" + requested_quality, headers=ythdd_globals.getHeaders(caller='proxy'), stream=True) thumbnail.raw.decode_content = True + + quality_id = 0 + if requested_quality == "maxres.jpg": + # if requested quality is maxres, + # provide the best quality possible + while thumbnail.status_code != 200: + thumbnail = requests.get(prefix + "vi/" + video_id + "/" + quality_urls[quality_id] + ".jpg", headers=ythdd_globals.getHeaders(caller='proxy'), stream=True) + thumbnail.raw.decode_content = True + quality_id += 1 + response = Response(thumbnail.raw, mimetype=thumbnail.headers['content-type'], status=thumbnail.status_code) return response diff --git a/ythdd_inv_tl.py b/ythdd_inv_tl.py index 94a042f..0530b2f 100644 --- a/ythdd_inv_tl.py +++ b/ythdd_inv_tl.py @@ -31,9 +31,9 @@ import ythdd_struct_parser # [✓] /api/v1/videos/:videoIdXXXX # [✓] /api/v1/playlists/:plid # [✓] /api/v1/channel/{videos, shorts, playlists, streams, latest?}/:ucid (rewrite) +# [✓] /api/v1/:videoIdXXXX/maxres.jpg redirects to best quality thumbnail # ---------- # PLANNED: -# [X] /api/v1/:videoIdXXXX/maxres.jpg redirects to best quality thumbnail # [X] /api/v1/storyboards/:videoIdXXXX # [X] /api/v1/videos/:videoIdXXXX does not depend on yt-dlp and offloads stream retrieval elsewhere (making initial response fast) # [X] /api/v1/manifest/:videoIdXXXX (above is prerequisite) diff --git a/ythdd_struct_parser.py b/ythdd_struct_parser.py index cb4b6fa..bc1e966 100644 --- a/ythdd_struct_parser.py +++ b/ythdd_struct_parser.py @@ -11,7 +11,7 @@ def genThumbs(videoId: str): result = [] thumbnails = [ - #{'height': 720, 'width': 1280, 'quality': "maxres", 'url': "maxres"}, # for the time being omit the buggy maxres quality + {'height': 720, 'width': 1280, 'quality': "maxres", 'url': "maxres"}, # will always attempt to return the best quality available {'height': 720, 'width': 1280, 'quality': "maxresdefault", 'url': "maxresdefault"}, {'height': 480, 'width': 640, 'quality': "sddefault", 'url': "sddefault"}, {'height': 360, 'width': 480, 'quality': "high", 'url': "hqdefault"},