Skip to content

Commit

Permalink
[youtube] use api key and client version from page
Browse files Browse the repository at this point in the history
  • Loading branch information
insaneracist committed Nov 10, 2020
1 parent 0137a78 commit b2a462a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions youtube_dlc/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit b2a462a

Please sign in to comment.