From c19bf7d000590f032275cb744c86f57dddb48dba Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 20 May 2021 16:18:29 +0200 Subject: [PATCH] replace /get_video_info call this has sporadically returned errors for the last few days, and now does it all the time. youtube.com/watch and /embed have moved to this endpoint, with the same key as is used elsewhere in the innertube api. this probably is the beginning of the end of the seperate /browse endpoint, as innertube is now required in core. --- app/common/common.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/common/common.py b/app/common/common.py index f7d48b9..b9926d4 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -206,28 +206,32 @@ 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") cookies = dict(c.fetchall()) - 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", + 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}} }, cookies=cookies) if r.status_code == 429: return None, None, None, 'banned', 'possible IP ban' - 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]) + metadata = r.json() playabilityStatus = metadata['playabilityStatus']['status'] if playabilityStatus != "OK": playabilityReason = metadata['playabilityStatus'].get('reason', -- 2.39.3