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

Code before:
        author = try_get(comment_renderer, lambda x: x['authorText']['simpleText'], compat_str)
        author_id = try_get(comment_renderer,
                            lambda x: x['authorEndpoint']['browseEndpoint']['browseId'], compat_str)
        votes = str_to_int(try_get(comment_renderer, (lambda x: x['voteCount']['simpleText'],
                                                      lambda x: x['likeCount']), compat_str)) or 0
        author_thumbnail = try_get(comment_renderer,
                                   lambda x: x['authorThumbnail']['thumbnails'][-1]['url'], compat_str)

        author_is_uploader = try_get(comment_renderer, lambda x: x['authorIsChannelOwner'], bool)
        is_liked = try_get(comment_renderer, lambda x: x['isLiked'], bool)

        return {
            'id': comment_id,
            'text': text,
            'time_text': time_text,
            'votes': votes,
            'is_liked': is_liked,
            'author': author,
            'author_id': author_id,
            'author_thumbnail': author_thumbnail,
            'author_is_uploader': author_is_uploader,
            'parent': parent or 'root'
        }

    def _comment_entry(self, comment_renderer, parent=None):
        if comment_renderer.get('commentId'):
            return self._extract_comment(comment_renderer, parent)

    def _comment_entries(self, root_continuation_data, identity_token, account_syncid, session_token_list, parent=None):

        def extract_thread(parent_renderer):
            contents = try_get(parent_renderer, lambda x: x['contents'], list) or []

            for content in contents:
                if not isinstance(content, dict):
                    continue
                comment_thread_renderer = try_get(content, lambda x: x['commentThreadRenderer'])
                comment_renderer = try_get(content, (lambda x: x['commentThreadRenderer']['comment']['commentRenderer'],
                                                     lambda x: x['commentRenderer']), dict)
                if not comment_renderer:
                    continue
                comment = self._comment_entry(comment_renderer, parent)
                if not comment:
                    continue
                yield comment
                # Attempt to get the replies
                comment_replies_renderer = try_get(comment_thread_renderer, lambda x: x['replies']['commentRepliesRenderer'], dict)
                if comment_replies_renderer:
                    for reply_comment in self._comment_entries(comment_replies_renderer,
                                                               identity_token,
                                                               account_syncid,

Review comment (refactor):
this check can be moved directly to `_extract_comment`

Code after:
        time_text = self._join_text_entries(comment_time_text)

        author = try_get(comment_renderer, lambda x: x['authorText']['simpleText'], compat_str)
        author_id = try_get(comment_renderer,
                            lambda x: x['authorEndpoint']['browseEndpoint']['browseId'], compat_str)
        votes = str_to_int(try_get(comment_renderer, (lambda x: x['voteCount']['simpleText'],
                                                      lambda x: x['likeCount']), compat_str)) or 0
        author_thumbnail = try_get(comment_renderer,
                                   lambda x: x['authorThumbnail']['thumbnails'][-1]['url'], compat_str)

        author_is_uploader = try_get(comment_renderer, lambda x: x['authorIsChannelOwner'], bool)
        is_liked = try_get(comment_renderer, lambda x: x['isLiked'], bool)

        return {
            'id': comment_id,
            'text': text,
            # TODO: This should be parsed to timestamp
            'time_text': time_text,
            'like_count': votes,
            'is_favorited': is_liked,
            'author': author,
            'author_id': author_id,
            'author_thumbnail': author_thumbnail,
            'author_is_uploader': author_is_uploader,
            'parent': parent or 'root'
        }

    def _comment_entries(self, root_continuation_data, identity_token, account_syncid,
                         session_token_list, parent=None, comment_counts=None):

        def extract_thread(parent_renderer):
            contents = try_get(parent_renderer, lambda x: x['contents'], list) or []
            if not parent:
                comment_counts[2] = 0
            for content in contents:
                comment_thread_renderer = try_get(content, lambda x: x['commentThreadRenderer'])
                comment_renderer = try_get(
                    comment_thread_renderer, (lambda x: x['comment']['commentRenderer'], dict)) or try_get(
                    content, (lambda x: x['commentRenderer'], dict))

                if not comment_renderer:
                    continue
                comment = self._extract_comment(comment_renderer, parent)
                if not comment:
                    continue
                comment_counts[0] += 1
                yield comment
                # Attempt to get the replies
                comment_replies_renderer = try_get(
                    comment_thread_renderer, lambda x: x['replies']['commentRepliesRenderer'], dict)