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

Code before:
    _VALID_URL = r'https?://(?:www\.)?1tv\.ru/live/?'
    _GEO_BYPASS = False
    _GEO_COUNTRIES = ['RU']

    _TESTS = [
        {
            'url': 'https://www.1tv.ru/live',
            'info_dict': {
                'id': 'live',
                'ext': 'mp4',
                'title': 'ПЕРВЫЙ КАНАЛ ПРЯМОЙ ЭФИР СМОТРЕТЬ ОНЛАЙН',
                'is_live': True,
            },
        },
    ]

    def _real_extract(self, url):
        display_id = 'live'
        webpage = self._download_webpage(url, display_id)

        streams_list = self._download_json('https://stream.1tv.ru/api/playlist/1tvch-v1_as_array.json', 'live')
        mpd_url = traverse_obj(streams_list, ('mpd', ..., {url_or_none}, any, {require('mpd url')}))
        hls_url = traverse_obj(streams_list, ('hls', ..., {url_or_none}, any, {require('hls url')}))
        mpd_formats, subtitles = self._extract_mpd_formats_and_subtitles(mpd_url, display_id, mpd_id='dash', fatal=True)
        hls_formats = self._extract_m3u8_formats(hls_url, display_id, 'mp4', m3u8_id='hls', live=True, fatal=False)
        formats = mpd_formats + hls_formats
        # It is mandatory to use the '-re' option for ffmpeg,
        # otherwise the recording of fragments will stop after
        # a while due to the speed n-times faster than real time.
        for f in formats:
            f.update({'downloader_options': {'ffmpeg_args': ['-re']}})

        return {
            'id': display_id,
            'title': self._html_extract_title(webpage),
            'ext': 'mp4',
            'formats': formats,
            'subtitles': subtitles,
            'is_live': True,
        }


Review comment (refactor):
- We shouldn't require both DASH and HLS. One or the other
- We can't download live subs
- extend `formats`
```suggestion
        mpd_url = traverse_obj(streams_list, ('mpd', ..., {url_or_none}, any))
        formats = self._extract_mpd_formats(mpd_url, display_id, mpd_id='dash', fatal=False)
        hls_url = traverse_obj(streams_list, ('hls', ..., {url_or_none}, any))
        formats.extend(self._extract_m3u8_formats(hls_url, display_id, 'mp4', m3u8_id='hls', live=True, fatal=False))
        if not formats:
            raise ExtractorError('Unable to extract any stream')
```

Code after:
    _VALID_URL = r'https?://(?:www\.)?1tv\.ru/live'

    _TESTS = [{
        'url': 'https://www.1tv.ru/live',
        'info_dict': {
            'id': 'live',
            'ext': 'mp4',
            'title': r're:ПЕРВЫЙ КАНАЛ ПРЯМОЙ ЭФИР СМОТРЕТЬ ОНЛАЙН \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
            'live_status': 'is_live',
        },
        'params': {'skip_download': 'livestream'},
    }]

    def _real_extract(self, url):
        display_id = 'live'
        webpage = self._download_webpage(url, display_id, fatal=False)

        streams_list = self._download_json('https://stream.1tv.ru/api/playlist/1tvch-v1_as_array.json', display_id)
        mpd_url = traverse_obj(streams_list, ('mpd', ..., {url_or_none}, any, {require('mpd url')}))
        # FFmpeg needs to be passed -re to not seek past live window. This is handled by core
        formats, _ = self._extract_mpd_formats_and_subtitles(mpd_url, display_id, mpd_id='dash')

        return {
            'id': display_id,
            'title': self._html_extract_title(webpage),
            'formats': formats,
            'is_live': True,
        }