From 83b6249fe6994f81cb6e1db53bb64ec305734a8f Mon Sep 17 00:00:00 2001 From: girst Date: Tue, 29 Mar 2022 16:55:53 +0200 Subject: [PATCH] port yt-dlp#3233 agegate bypass the change in embedUrl was cargo-culted from there, no idea if needed. --- app/common/common.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/common/common.py b/app/common/common.py index 06a627a..3dfb297 100644 --- a/app/common/common.py +++ b/app/common/common.py @@ -203,6 +203,13 @@ def update_channel(db, xmldata, from_webhook=False): return True +def is_agegated(metadata): + playabilityStatus = metadata['playabilityStatus'] + return bool( + playabilityStatus.get("status") == "CONTENT_CHECK_REQUIRED" + or playabilityStatus.get("desktopLegacyAgeGateReason") + ) + def get_video_info(video_id, *, metaOnly=False, _embed=True): """ returns: best-quality muxed video stream, stream map, player_response, error-type/mesage @@ -215,7 +222,6 @@ def get_video_info(video_id, *, metaOnly=False, _embed=True): cookies = dict(c.fetchall()) today = datetime.now(timezone.utc).strftime("%Y%m%d") # XXX: anticaptcha hasn't been adapted - # XXX: this is not cached any more! key = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8" r = requests.post("https://www.youtube-nocookie.com/youtubei/v1/player", params={'key': key}, json={ 'videoId': video_id, @@ -223,12 +229,12 @@ def get_video_info(video_id, *, metaOnly=False, _embed=True): 'client': { 'gl': 'US', 'hl': 'en', - # ANDROID returns streams that are not throttled or cipher-scambled, but less metadata than WEB - 'clientName': 'ANDROID' if not metaOnly else 'WEB', - 'clientVersion': f'16.20' if not metaOnly else f'2.{today}.01.01', - **({'clientScreen': 'EMBED'} if _embed else {}), + # ANDROID returns streams that are not throttled or cipher-scambled, but less metadata than WEB. + # TVHTML5* returns throttled and possibly ciphered streams, but bypasses age-gate. we don't decode them currently. + 'clientName': ('ANDROID' if _embed else 'TVHTML5_SIMPLY_EMBEDDED_PLAYER') if not metaOnly else 'WEB', + 'clientVersion': (f'16.20' if _embed else '2.0') if not metaOnly else f'2.{today}.01.01', }, - 'thirdParty': {'embedUrl': 'https://google.com'} + 'thirdParty': {'embedUrl': 'https://www.youtube.com/'} }, }, cookies=cookies) @@ -243,19 +249,14 @@ def get_video_info(video_id, *, metaOnly=False, _embed=True): playabilityReason = metadata['playabilityStatus'].get('reason', '//'.join(metadata['playabilityStatus'].get('messages',[]))) player_error = f"{playabilityStatus}: {playabilityReason}" - # "Watch on YouTube" button is visible => "Playback on other websites - # has been disabled by the video owner." => retry detailpage API - if (playabilityStatus == "UNPLAYABLE" and - 'proceedButton' in metadata['playabilityStatus'] \ - .get('errorScreen',{}).get('playerErrorMessageRenderer',{}) + if (is_agegated(metadata) and not metaOnly # only need metadata (e.g. called from pubsubhubbub) - and _embed - + and _embed # already trying bypass ): _, _, metadata_embed, error_embed, errormsg_embed = get_video_info(video_id, _embed=False) if not error_embed or error_embed in ('livestream','geolocked'): metadata = metadata_embed - elif errormsg_embed == "LOGIN_REQUIRED: Sign in to confirm your age": + elif is_agegated(metadata_embed): # agegate bypass failed? return None, None, metadata, 'agegated', player_error else: return None, None, metadata, error_embed, errormsg_embed -- 2.39.3