feat: make maxres provide the best quality thumbnail available
This commit is contained in:
15
views.py
15
views.py
@@ -26,8 +26,21 @@ def thumbnailProxy(received_request):
|
|||||||
'error_msg': 'invalid request. pretend this is a thumbnail :D'
|
'error_msg': 'invalid request. pretend this is a thumbnail :D'
|
||||||
}), mimetype='application/json', status=400)
|
}), 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
|
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)
|
response = Response(thumbnail.raw, mimetype=thumbnail.headers['content-type'], status=thumbnail.status_code)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ import ythdd_struct_parser
|
|||||||
# [✓] /api/v1/videos/:videoIdXXXX
|
# [✓] /api/v1/videos/:videoIdXXXX
|
||||||
# [✓] /api/v1/playlists/:plid
|
# [✓] /api/v1/playlists/:plid
|
||||||
# [✓] /api/v1/channel/{videos, shorts, playlists, streams, latest?}/:ucid (rewrite)
|
# [✓] /api/v1/channel/{videos, shorts, playlists, streams, latest?}/:ucid (rewrite)
|
||||||
|
# [✓] /api/v1/:videoIdXXXX/maxres.jpg redirects to best quality thumbnail
|
||||||
# ----------
|
# ----------
|
||||||
# PLANNED:
|
# PLANNED:
|
||||||
# [X] /api/v1/:videoIdXXXX/maxres.jpg redirects to best quality thumbnail
|
|
||||||
# [X] /api/v1/storyboards/:videoIdXXXX
|
# [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/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)
|
# [X] /api/v1/manifest/:videoIdXXXX (above is prerequisite)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ def genThumbs(videoId: str):
|
|||||||
|
|
||||||
result = []
|
result = []
|
||||||
thumbnails = [
|
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': 720, 'width': 1280, 'quality': "maxresdefault", 'url': "maxresdefault"},
|
||||||
{'height': 480, 'width': 640, 'quality': "sddefault", 'url': "sddefault"},
|
{'height': 480, 'width': 640, 'quality': "sddefault", 'url': "sddefault"},
|
||||||
{'height': 360, 'width': 480, 'quality': "high", 'url': "hqdefault"},
|
{'height': 360, 'width': 480, 'quality': "high", 'url': "hqdefault"},
|
||||||
|
|||||||
Reference in New Issue
Block a user