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

Code before:
                'formats': formats,
            }

        if is_vod:
            player_html = self._download_webpage(
                'https://live.erinn.biz/live.timeshift.fplayer.php', video_id,
                query={'hash': video_id},
                note='Downloading player html',
                errnote='Unable to download player html')

            sources_json = self._search_json(
                r'var\s+fplayer_source\s*=', player_html, 'stream data', video_id,
                contains_pattern=r'\[(?s:.+)\]', transform_source=js_to_json)

            def _parse_segment(segment, id, title):
                path = segment.get('file')
                if not path:
                    return None
                formats = [{
                    'url': urljoin('https://live.erinn.biz', path),
                    'ext': 'mp4',
                    'protocol': 'm3u8_native',
                }]
                return {
                    'id': id,
                    'title': title,
                    'description': description,
                    'timestamp': traverse_obj(segment, ('time_start', {int_or_none})),
                    'thumbnail': thumbnail,
                    'formats': formats,
                }

            is_playlist = len(sources_json) > 1
            if is_playlist:
                entries = []
                for i, segment in enumerate(sources_json):
                    entry = _parse_segment(segment, f'{video_id}_{i}', f'{title} (Part {i + 1})')
                    if not entry:
                        continue
                    entries.append(entry)
                return self.playlist_result(entries, video_id, title, description, multi_video=True)
            else:
                return _parse_segment(sources_json[0], video_id, title)

        raise ExtractorError('Could not detect media type')


Review comment (suggestion):
I think to have it extra clear, I would name these `segment_id`/`segment_title`.
```suggestion
            def parse_segment(segment, segment_id, segment_title):
                path = segment.get('file')
                if not path:
                    return None
                formats = [{
                    'url': urljoin('https://live.erinn.biz', path),
                    'ext': 'mp4',
                    'protocol': 'm3u8_native',
                }]
                return {
                    'id': segment_id,
                    'title': segment_title,
```

Code after:
        player_html = self._download_webpage(
            'https://live.erinn.biz/live.timeshift.fplayer.php', video_id,
            'Downloading player html', 'Unable to download player html', query={'hash': video_id})

        sources = traverse_obj(self._search_json(
            r'var\s+fplayer_source\s*=', player_html, 'stream data', video_id,
            contains_pattern=r'\[(?s:.+)\]', transform_source=js_to_json), lambda _, v: v['file'])

        def entries(segments, playlist=True):
            for i, segment in enumerate(segments, 1):
                yield {
                    'id': f'{video_id}_{i}' if playlist else video_id,
                    'title': f'{title} (Part {i})' if playlist else title,
                    'description': description,
                    'timestamp': traverse_obj(segment, ('time_start', {int_or_none})),
                    'thumbnail': thumbnail,
                    'formats': [{
                        'url': urljoin('https://live.erinn.biz', segment['file']),
                        'ext': 'mp4',
                        'protocol': 'm3u8_native',
                    }],
                }

        if len(sources) == 1:
            return next(entries(sources, playlist=False))

        return self.playlist_result(entries(sources), video_id, title, description, multi_video=True)