Skip to content

Commit

Permalink
[youtube:tab] Fix extraction with cookies provided (closes ytdl-org#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
dstftw committed Nov 16, 2020
1 parent 91dcde8 commit 6699b6c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2723,7 +2723,7 @@ def _extract_continuation(cls, renderer):
'itct': ctp,
}

def _entries(self, tab):
def _entries(self, tab, identity_token):
continuation = None
slr_contents = tab['sectionListRenderer']['contents']
for slr_content in slr_contents:
Expand Down Expand Up @@ -2768,16 +2768,20 @@ def _entries(self, tab):
if not continuation:
continuation = self._extract_continuation(is_renderer)

headers = {
'x-youtube-client-name': '1',
'x-youtube-client-version': '2.20201112.04.01',
}
if identity_token:
headers['x-youtube-identity-token'] = identity_token

for page_num in itertools.count(1):
if not continuation:
break
browse = self._download_json(
'https://www.youtube.com/browse_ajax', None,
'Downloading page %d' % page_num,
headers={
'x-youtube-client-name': '1',
'x-youtube-client-version': '2.20201030.01.00',
}, query=continuation, fatal=False)
headers=headers, query=continuation, fatal=False)
if not browse:
break
response = try_get(browse, lambda x: x[1]['response'], dict)
Expand Down Expand Up @@ -2848,8 +2852,11 @@ def _real_extract(self, url):
title = channel_title or channel_id
if tab_title:
title += ' - %s' % tab_title
identity_token = self._search_regex(
r'\bID_TOKEN["\']\s*:\s*["\'](.+?)["\']', webpage,
'identity token', default=None)
return self.playlist_result(
self._entries(selected_tab['content']),
self._entries(selected_tab['content'], identity_token),
playlist_id=channel_external_id or channel_id,
playlist_title=title)

Expand Down

0 comments on commit 6699b6c

Please sign in to comment.