From 0a1991beef62f0183beb6f8b66184a0f3cd9d3c1 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 3 Jul 2021 10:16:11 +0200 Subject: [PATCH] reintroduce TVHTML5 get_video_info some age-gates can't be bypassed by the new api --- app/common/common.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/common/common.py b/app/common/common.py index 7a57c8d..fcf1a03 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -212,7 +212,7 @@ def get_video_info(video_id, sts=0, algo="", _embed=False): today = datetime.now(timezone.utc).strftime("%Y%m%d") # XXX: anticaptcha hasn't been adapted # XXX: this is not cached any more! - # note: age-gated works as long as it's embeddable (HtVdAasjOgU ok, XgnwCQzjau8 bad) + # note: age-gated works as long as it's embeddable (HtVdAasjOgU ok, XgnwCQzjau8 bad, SkRSXFQerZs tvhtml5-only) r = requests.post("https://www.youtube-nocookie.com/youtubei/v1/player?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", json={ 'videoId': video_id, 'context': { @@ -250,6 +250,20 @@ def get_video_info(video_id, sts=0, algo="", _embed=False): metadata['streamingData'] = metadata_embed['streamingData'] metadata['playabilityStatus'] = metadata_embed['playabilityStatus'] else: + try: + r2 = requests.get("https://www.youtube.com/get_video_info", dict( + video_id=video_id, + html5="1", + c="TVHTML5", + cver="6.20180913", + el="embedded", + eurl=f"https://youtube.googleapis.com/v/{video_id}", + )) + metadata_tvhtml5 = json.loads(parse_qs(r2.text).get('player_response',['{}'])[0]) + # has 'playabilityStatus', 'streamingData', 'videoDetails', but not 'microformat' keys + metadata['streamingData'] = metadata_tvhtml5['streamingData'] + metadata['playabilityStatus'] = metadata_tvhtml5['playabilityStatus'] + except: return None, None, metadata, 'agegated', player_error else: # without videoDetails, there's only the error message -- 2.39.3