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

Code before:
                        expected_video_comment_count = str_to_int(expected_video_comment_count)
                        self.to_screen("Downloading ~%d comments" % expected_video_comment_count)
                        first_continuation = False

                for entry in known_continuation_renderers[key](continuation_renderer):
                    yield entry

                continuation = YoutubeTabIE._extract_continuation(continuation_renderer)  # TODO
                break

    def _extract_comments(self, ytcfg, video_id, contents, webpage, xsrf_token):
        """Entry for comment extraction"""
        comments = []
        known_entry_comment_renderers = (
            'itemSectionRenderer',
        )
        for entry in contents:
            for key, renderer in entry.items():
                if key not in known_entry_comment_renderers:
                    continue

                comment_iter = self._comment_entries(renderer,
                                                     identity_token=self._extract_identity_token(webpage, item_id=video_id),
                                                     account_syncid=self._extract_account_syncid(ytcfg),
                                                     session_token_list=[xsrf_token])

                for comment in comment_iter:
                    comments.append(comment)
        self.to_screen("Downloaded %d comments" % len(comments))
        return {'comments': comments,
                'comment_count': len(comments)}

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {})
        video_id = self._match_id(url)
        base_url = self.http_scheme() + '//www.youtube.com/'
        webpage_url = base_url + 'watch?v=' + video_id
        webpage = self._download_webpage(
            webpage_url + '&has_verified=1&bpctr=9999999999',
            video_id, fatal=False)

        player_response = None
        if webpage:
            player_response = self._extract_yt_initial_variable(
                webpage, self._YT_INITIAL_PLAYER_RESPONSE_RE,
                video_id, 'initial player response')
        if not player_response:
            player_response = self._call_api(
                'player', {'videoId': video_id}, video_id)

        playability_status = player_response.get('playabilityStatus') or {}

Review comment (refactor):
I prefer this style of code. (No need to change, just a matter of personal preference)
```py
comment_iter = self._comment_entries(
    renderer,
    identity_token=self._extract_identity_token(webpage, item_id=video_id),
    ...)
```

Code after:
            }

            # extract next root continuation from the results
            continuation_contents = try_get(
                response, lambda x: x['continuationContents'], dict) or {}

            for key, value in continuation_contents.items():
                if key not in known_continuation_renderers:
                    continue
                continuation_renderer = value

                if first_continuation:
                    first_continuation = False
                    expected_comment_count = try_get(
                        continuation_renderer,
                        (lambda x: x['header']['commentsHeaderRenderer']['countText']['runs'][0]['text'],
                         lambda x: x['header']['commentsHeaderRenderer']['commentsCount']['runs'][0]['text']),
                        compat_str)

                    if expected_comment_count:
                        comment_counts[1] = str_to_int(expected_comment_count)
                        self.to_screen("Downloading ~%d comments" % str_to_int(expected_comment_count))
                        yield comment_counts[1]

                    # TODO: cli arg.
                    # 1/True for newest, 0/False for popular (default)
                    comment_sort_index = int(True)
                    sort_continuation_renderer = try_get(
                        continuation_renderer,
                        lambda x: x['header']['commentsHeaderRenderer']['sortMenu']['sortFilterSubMenuRenderer']['subMenuItems']
                        [comment_sort_index]['continuation']['reloadContinuationData'], dict)
                    # If this fails, the initial continuation page
                    # starts off with popular anyways.
                    if sort_continuation_renderer:
                        continuation = YoutubeTabIE._build_continuation_query(
                            continuation=sort_continuation_renderer.get('continuation'),
                            ctp=sort_continuation_renderer.get('clickTrackingParams'))
                        self.to_screen("Sorting comments by %s" % ('popular' if comment_sort_index == 0 else 'newest'))
                        break

                for entry in known_continuation_renderers[key](continuation_renderer):
                    yield entry

                continuation = YoutubeTabIE._extract_continuation(continuation_renderer)  # TODO
                break

    def _extract_comments(self, ytcfg, video_id, contents, webpage, xsrf_token):
        """Entry for comment extraction"""
        comments = []
        known_entry_comment_renderers = (
            'itemSectionRenderer',