Skip to content

Commit

Permalink
[youtube:tab] Restore retry on browse requests (closes ytdl-org#27313,
Browse files Browse the repository at this point in the history
…closes ytdl-org#27564)
  • Loading branch information
dstftw authored and ThirumalaiK committed Jan 28, 2021
1 parent 1121f85 commit c96bbe9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions youtube_dl/extractor/youtube.py
Expand Up @@ -16,6 +16,7 @@
from ..swfinterp import SWFInterpreter
from ..compat import (
compat_chr,
compat_HTTPError,
compat_parse_qs,
compat_urllib_parse_unquote,
compat_urllib_parse_unquote_plus,
Expand Down Expand Up @@ -3009,10 +3010,24 @@ def _entries(self, tab, 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=headers, query=continuation, fatal=False)
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)
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)
Expand Down

0 comments on commit c96bbe9

Please sign in to comment.