Skip to content

Commit

Permalink
[youtube:tab] Switch continuation to browse API (closes ytdl-org#28289,
Browse files Browse the repository at this point in the history
closes ytdl-org#28327)

Until further investigation.
  • Loading branch information
dstftw authored and leshasmlesha committed Apr 3, 2021
1 parent 9c9401c commit a109dad
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2478,34 +2478,44 @@ def _entries(self, tab, identity_token):
headers = {
'x-youtube-client-name': '1',
'x-youtube-client-version': '2.20201112.04.01',
'content-type': 'application/json',
}
if identity_token:
headers['x-youtube-identity-token'] = identity_token

data = {
'context': {
'client': {
'clientName': 'WEB',
'clientVersion': '2.20201021.03.00',
}
},
}

for page_num in itertools.count(1):
if not continuation:
break
data['continuation'] = continuation['continuation']
data['clickTracking'] = {
'clickTrackingParams': continuation['itct']
}
count = 0
retries = 3
while count <= retries:
try:
# Downloading page may result in intermittent 5xx HTTP error
# that is usually worked around with a retry
browse = self._download_json(
'https://www.youtube.com/browse_ajax', None,
'Downloading page %d%s'
% (page_num, ' (retry #%d)' % count if count else ''),
headers=headers, query=continuation)
response = self._download_json(
'https://www.youtube.com/youtubei/v1/browse?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
None, 'Downloading page %d%s' % (page_num, ' (retry #%d)' % count if count else ''),
headers=headers, data=json.dumps(data).encode('utf8'))
break
except ExtractorError as e:
if isinstance(e.cause, compat_HTTPError) and e.cause.code in (500, 503):
count += 1
if count <= retries:
continue
raise
if not browse:
break
response = try_get(browse, lambda x: x[1]['response'], dict)
if not response:
break

Expand Down

0 comments on commit a109dad

Please sign in to comment.