From 8ac0142c42cea0f56fe0256f6c6a4966c12cf8d4 Mon Sep 17 00:00:00 2001 From: girst Date: Mon, 14 Jun 2021 10:10:40 +0200 Subject: [PATCH] work around youtube not returning player_response also fixes an exception that occurred when returning 'exhausted' error --- app/common/common.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/common/common.py b/app/common/common.py index 74ea4db..890c2c8 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -206,7 +206,7 @@ def get_video_info(video_id, sts=0, algo=""): returns: best-quality muxed video stream, stream map, player_response, error-type/mesage error types: player, malformed, livestream, geolocked, exhausted """ - player_error = None # for 'exhausted' + player_error, metadata = None, None # for 'exhausted' with sqlite3.connect(cf['global']['database']) as conn: c = conn.cursor() c.execute("SELECT * FROM captcha_cookies") @@ -228,7 +228,13 @@ def get_video_info(video_id, sts=0, algo=""): if 'errorcode' in params: # status=fail return None, None, None, 'malformed', params['reason'][0] - metadata = json.loads(params.get('player_response')[0]) + try: + metadata = json.loads(params.get('player_response')[0]) + except: + # XXX(HOTFIX): some requests are missing the player_response; don't + # crash, but either try again or fail gracefully and the user shoud + # retry. + continue playabilityStatus = metadata['playabilityStatus']['status'] if playabilityStatus != "OK": playabilityReason = metadata['playabilityStatus'].get('reason', -- 2.39.3