From b2a462a24c217ce8b414a293c6d27bde03a28459 Mon Sep 17 00:00:00 2001 From: insaneracist Date: Tue, 10 Nov 2020 06:14:25 -0800 Subject: [PATCH] [youtube] use api key and client version from page --- youtube_dlc/extractor/youtube.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/youtube_dlc/extractor/youtube.py b/youtube_dlc/extractor/youtube.py index 6c5c729e3..188892585 100644 --- a/youtube_dlc/extractor/youtube.py +++ b/youtube_dlc/extractor/youtube.py @@ -2896,6 +2896,12 @@ def _extract_playlist(self, playlist_id): playlist_items = try_get(yt_initial, lambda x: x['contents']['twoColumnBrowseResultsRenderer']['tabs'][0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['playlistVideoListRenderer']['contents'], list) entries = [] playlist_page = 1 + api_key = self._search_regex( + r'"INNERTUBE_API_KEY":"([^"]+)"', + page, 'api key', default="AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", fatal=False) + api_client_version = self._search_regex( + r'"INNERTUBE_CONTEXT_CLIENT_VERSION":"([^"]+)"', + page, 'client version', fatal=False) while playlist_items: item = playlist_items.pop(0) item_video = try_get(item, lambda x: x['playlistVideoRenderer'], dict) @@ -2919,18 +2925,18 @@ def _extract_playlist(self, playlist_id): 'context': { 'client': { 'clientName': 'WEB', - 'clientVersion': '2.20201021.03.00', + 'clientVersion': api_client_version, } }, 'continuation': continuation_token } response = self._download_json( - 'https://www.youtube.com/youtubei/v1/browse?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', + 'https://www.youtube.com/youtubei/v1/browse?key=%s' % api_key, data=json.dumps(request_data).encode('utf8'), errnote='Unable to download playlist page', fatal=False, headers={'Content-Type': 'application/json'}, note='Downloading page %s' % playlist_page, - video_id='playlist page %s' % playlist_page) + video_id=playlist_id) playlist_items_new = try_get(response, lambda x: x['onResponseReceivedActions'][0]['appendContinuationItemsAction']['continuationItems'], list) if playlist_items_new: playlist_items.extend(playlist_items_new)