From f4f751af409a1db86215b87cc424960a8236ee93 Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sun, 11 Apr 2021 20:23:04 +0000 Subject: [PATCH] [youtube] Parse API parameters from initial webpage (#230) * Obtain innertube_context, api_key and x-goog-visitor-id from webpage * Generalize the header & Innertube_context extraction across YouTube extractors Related: https://github.com/ytdl-org/youtube-dl/commit/1b0a13f33cfb3644cc718d35951ea85bb1905459 Authored by: colethedj --- yt_dlp/extractor/youtube.py | 130 ++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 50 deletions(-) diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 168103377..ea09ad358 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -284,21 +284,8 @@ def _real_initialize(self): if not self._login(): return - _YT_WEB_CLIENT_VERSION = '2.20210301.08.00' - _DEFAULT_API_DATA = { - 'context': { - 'client': { - 'clientName': 'WEB', - 'clientVersion': _YT_WEB_CLIENT_VERSION, - } - }, - } - - _DEFAULT_BASIC_API_HEADERS = { - 'X-YouTube-Client-Name': '1', - 'X-YouTube-Client-Version': _YT_WEB_CLIENT_VERSION - } - + _YT_WEB_CLIENT_VERSION = '2.20210407.08.00' + _YT_INNERTUBE_API_KEY = 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' _YT_INITIAL_DATA_RE = r'(?:window\s*\[\s*["\']ytInitialData["\']\s*\]|ytInitialData)\s*=\s*({.+?})\s*;' _YT_INITIAL_PLAYER_RESPONSE_RE = r'ytInitialPlayerResponse\s*=\s*({.+?})\s*;' _YT_INITIAL_BOUNDARY_RE = r'(?:var\s+meta|