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'
|
||||
}), 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
|
||||
|
||||
Reference in New Issue
Block a user