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

Code before:
                compat_str)
            chapters.append({
                'start_time': start_time,
                'end_time': end_time,
                'title': title,
            })
        return chapters

    def _extract_yt_initial_variable(self, webpage, regex, video_id, name):
        return self._parse_json(self._search_regex(
            (r'%s\s*%s' % (regex, self._YT_INITIAL_BOUNDARY_RE),
             regex), webpage, name, default='{}'), video_id, fatal=False)

    @staticmethod
    def _text_entries(runs):
        for run in runs:
            if not isinstance(run, dict):
                continue
            sub_text = try_get(run, lambda x: x['text'], compat_str)
            if sub_text:
                yield sub_text

    def _join_text_entries(self, runs):
        text = ''.join(t for t in self._text_entries(runs))
        if text:
            return text

    def _extract_comment(self, comment_renderer, parent=None):
        comment_id = comment_renderer.get('commentId')
        comment_text_runs = try_get(comment_renderer, lambda x: x['contentText']['runs']) or []
        text = self._join_text_entries(comment_text_runs) or ''
        comment_time_text = try_get(comment_renderer, lambda x: x['publishedTimeText']['runs']) or []
        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,
            'time_text': time_text,
            'votes': votes,
            'is_liked': is_liked,

Review comment (suggestion):
seems unnecessary to be 2 seperate functions since we only ever have direct use for `_join_text_entries`

Code after:
                compat_str)
            chapters.append({
                'start_time': start_time,
                'end_time': end_time,
                'title': title,
            })
        return chapters

    def _extract_yt_initial_variable(self, webpage, regex, video_id, name):
        return self._parse_json(self._search_regex(
            (r'%s\s*%s' % (regex, self._YT_INITIAL_BOUNDARY_RE),
             regex), webpage, name, default='{}'), video_id, fatal=False)

    @staticmethod
    def _join_text_entries(runs):
        text = None
        for run in runs:
            if not isinstance(run, dict):
                continue
            sub_text = try_get(run, lambda x: x['text'], compat_str)
            if sub_text:
                if not text:
                    text = sub_text
                    continue
                text += sub_text
        return text

    def _extract_comment(self, comment_renderer, parent=None):
        comment_id = comment_renderer.get('commentId')
        if not comment_id:
            return
        comment_text_runs = try_get(comment_renderer, lambda x: x['contentText']['runs']) or []
        text = self._join_text_entries(comment_text_runs) or ''
        comment_time_text = try_get(comment_renderer, lambda x: x['publishedTimeText']['runs']) or []
        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