From fa9b2bd0a1b5d34595d3cd0724615f31c7ef0897 Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 20 May 2021 17:23:31 +0200 Subject: [PATCH] Revert "replace /get_video_info call" This reverts commit c19bf7d000590f032275cb744c86f57dddb48dba. --- app/common/common.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/app/common/common.py b/app/common/common.py index b9926d4..f7d48b9 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -206,32 +206,28 @@ 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, metadata = None, None # for 'exhausted' + player_error = None # for 'exhausted' with sqlite3.connect(cf['global']['database']) as conn: c = conn.cursor() c.execute("SELECT * FROM captcha_cookies") cookies = dict(c.fetchall()) - for el in ['WEB_EMBEDDED_PLAYER', 'WEB']: # sometimes, only one or the other works - today = datetime.now(timezone.utc).strftime("%Y%m%d") - # XXX: anticaptcha hasn't been adapted - # XXX: this is not cached any more! - r = requests.post("https://www.youtube-nocookie.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", json={ - 'videoId': video_id, - 'context': { - 'client': { - 'gl': 'US', - 'hl': 'en', - 'clientName': el, - 'clientVersion': f'2.{today}.01.01', - } - }, - 'playbackContext': {'contentPlaybackContext': {'signatureTimestamp': sts}} + for el in ['embedded', 'detailpage']:#sometimes, only one or the other works + r = requests.get("https://www.youtube.com/get_video_info", { + "video_id": video_id, + "eurl": f"https://youtube.googleapis.com/v/{video_id}", + "el": el, + "sts": sts, + "hl": "en_US", }, cookies=cookies) if r.status_code == 429: return None, None, None, 'banned', 'possible IP ban' - metadata = r.json() + params = parse_qs(r.text) + if 'errorcode' in params: # status=fail + return None, None, None, 'malformed', params['reason'][0] + + metadata = json.loads(params.get('player_response')[0]) playabilityStatus = metadata['playabilityStatus']['status'] if playabilityStatus != "OK": playabilityReason = metadata['playabilityStatus'].get('reason', -- 2.39.3