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

Code before:
        conf_data = self._download_json(
            api_url, video_id, note='Downloading player configuration')

        video_info = conf_data.get('video')
        if not video_info:
            raise ExtractorError('Failed to retrieve video information from API.', expected=True)

        title = video_info['title']
        formats = []
        media_sources = video_info.get('media_sources', {})

        hls_sources = media_sources.get('hls', {})
        for format_id, hls_url in hls_sources.items():
            if not hls_url:
                continue

            height_str = format_id.split('_')[-1]
            height = int(height_str) if height_str.isdigit() else None

            formats.append({
                'url': hls_url,
                'format_id': f'hls-{height_str}',
                'height': height,
                'protocol': 'm3u8_native',
                'ext': 'mp4',
            })

        mp4_sources = media_sources.get('mp4', {})
        for format_id, mp4_url in mp4_sources.items():
            if not mp4_url:
                continue

            height_str = format_id.split('_')[-1]
            height = int(height_str) if height_str.isdigit() else None

            formats.append({
                'url': mp4_url,
                'format_id': f'mp4-{height_str}',
                'height': height,
                'ext': 'mp4',
            })

        yt_id = video_info.get('yt_id')
        if yt_id:
            return self.url_result(yt_id, 'Youtube')

        if not formats:
            raise ExtractorError('No video formats found.', expected=True)

        return {
            'id': video_id,

Review comment (refactor):
Here I would only extract the auto hls format (i.e. the master playlist) and then let core code handle the parsing
```py
        formats = []
        subtitles = {}
        if hls_url := traverse_obj(video_info, ('media_sources', 'hls', 'hls_auto', {url_or_none})):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)
```

Code after:

        formats = []
        subtitles = {}

        if hls_url := traverse_obj(video_info, ('media_sources', 'hls', 'hls_auto', {url_or_none})):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        for format_id, mp4_url in traverse_obj(video_info, ('media_sources', 'mp4', {dict.items}, ...)):
            if not mp4_url:
                continue
            formats.append({
                'url': mp4_url,
                'format_id': format_id,
                'height': int_or_none(format_id.partition('_')[2]),
                'ext': 'mp4',
            })

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(video_info, {
                'title': ('title', {str}),
                'thumbnail': ('image', {url_or_none}),
                'duration': ('duration', {int_or_none}),
                'timestamp': ('creationDate', {int_or_none}),
                'uploader_id': ('ownerId', {str}),
            }),
        }