Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/youtube.py (Python)

Code before:

        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
            retries = self._downloader.params.get('extractor_retries', 3)
            count = -1
            last_error = None
            while count < retries:
                count += 1
                if last_error:
                    self.report_warning('%s. Retrying ...' % last_error)
                try:
                    response = self._call_api(
                        ep="browse", fatal=True, headers=headers,
                        query={
                            'continuation': continuation['continuation'],
                            'clickTracking': {'clickTrackingParams': continuation['itct']},
                        },
                        note='Downloading API JSON page %d%s' % (page_num, '(retry  # %d)' % count if count else ''))
                except ExtractorError as e:
                    if isinstance(e.cause, compat_HTTPError) and e.cause.code in (500, 503, 404):
                        # Downloading page may result in intermittent 5xx HTTP error
                        # Sometimes a 404 is also recieved. See: https://github.com/ytdl-org/youtube-dl/issues/28289
                        last_error = 'HTTP Error %s' % e.cause.code
                        if count < retries:
                            continue
                    raise
                else:
                    # Youtube sometimes sends incomplete data
                    # See: https://github.com/ytdl-org/youtube-dl/issues/28194
                    if response.get('continuationContents') or response.get('onResponseReceivedActions'):
                        break
                    last_error = 'Incomplete data recieved'
                    if count >= retries:
                        self._downloader.report_error(last_error)

            if not response:
                break

            known_continuation_renderers = {
                'playlistVideoListContinuation': self._playlist_entries,
                'gridContinuation': self._grid_entries,
                'itemSectionContinuation': self._post_thread_continuation_entries,
                'sectionListContinuation': extract_entries,  # for feeds

Review comment (suggestion):
```suggestion
                        note='Downloading API JSON page %d%s' % (page_num, ' (retry #%d)' % count if count else ''))
```

Code after:
                continuation_list[0] = self._extract_continuation(parent_renderer)

        continuation_list = [None]  # Python 2 doesnot support nonlocal
        tab_content = try_get(tab, lambda x: x['content'], dict)
        if not tab_content:
            return
        parent_renderer = (
            try_get(tab_content, lambda x: x['sectionListRenderer'], dict)
            or try_get(tab_content, lambda x: x['richGridRenderer'], dict) or {})
        for entry in extract_entries(parent_renderer):
            yield entry
        continuation = continuation_list[0]

        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
            retries = self._downloader.params.get('extractor_retries', 3)
            count = -1
            last_error = None
            while count < retries:
                count += 1
                if last_error:
                    self.report_warning('%s. Retrying ...' % last_error)
                try:
                    response = self._call_api(
                        ep="browse", fatal=True, headers=headers,
                        video_id='%s page %s' % (item_id, page_num),
                        query={
                            'continuation': continuation['continuation'],
                            'clickTracking': {'clickTrackingParams': continuation['itct']},
                        },
                        note='Downloading API JSON%s' % (' (retry #%d)' % count if count else ''))
                except ExtractorError as e:
                    if isinstance(e.cause, compat_HTTPError) and e.cause.code in (500, 503, 404):
                        # Downloading page may result in intermittent 5xx HTTP error
                        # Sometimes a 404 is also recieved. See: https://github.com/ytdl-org/youtube-dl/issues/28289
                        last_error = 'HTTP Error %s' % e.cause.code
                        if count < retries:
                            continue
                    raise
                else:
                    # Youtube sometimes sends incomplete data
                    # See: https://github.com/ytdl-org/youtube-dl/issues/28194
                    if response.get('continuationContents') or response.get('onResponseReceivedActions'):