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

Code before:
    _TESTS = [{
        'url': 'https://www.lrt.lt/mediateka/tiesiogiai/lrt-opus',
        'info_dict': {
            'id': 'lrt-opus',
            'live_status': 'is_live',
            'title': 're:^LRT Opus.+$',
            'ext': 'm3u8'
        }
    }]

    def _real_extract(self, url):
        matches = self._match_valid_url(url).groupdict()
        _match_id = matches['id']

        webpage = self._download_webpage(url, _match_id)
        token_url = self._extract_js_var(webpage, 'tokenURL')
        stream_title = self._extract_js_var(webpage, 'video_title', 'LRT')
        title = self._og_search_title(webpage)

        streams_data = self._download_json(token_url, _match_id)

        stream_formats = []
        stream_subtitles = {}

        for stream_url in traverse_obj(streams_data, ('response', 'data', lambda k, _: k.startswith('content')), expected_type=url_or_none):
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(stream_url, _match_id, m3u8_id='hls', live=True)

            stream_formats.extend(formats)
            stream_subtitles = self._merge_subtitles(stream_subtitles, subtitles)

        self._sort_formats(formats)

        return {
            'id': _match_id,
            'formats': stream_formats,
            'subtitles': stream_subtitles,
            'is_live': True,
            'title': f'{title} - {stream_title}'
        }


class LRTVODIE(LRTBaseIE):
    _VALID_URL = r'https?://(?:www\.)?lrt\.lt(?P<path>/mediateka/irasas/(?P<id>[0-9]+))'
    _TESTS = [{
        # m3u8 download
        'url': 'https://www.lrt.lt/mediateka/irasas/2000127261/greita-ir-gardu-sicilijos-ikvepta-klasikiniu-makaronu-su-baklazanais-vakariene',
        'info_dict': {
            'id': '2000127261',
            'ext': 'mp4',
            'title': 'Greita ir gardu: Sicilijos įkvėpta klasikinių makaronų su baklažanais vakarienė',
            'description': 'md5:ad7d985f51b0dc1489ba2d76d7ed47fa',

Review comment (refactor):
```suggestion
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(stream_url, _match_id, 'mp4', m3u8_id='hls', live=True)
```

Code after:
    _TESTS = [{
        'url': 'https://www.lrt.lt/mediateka/tiesiogiai/lrt-opus',
        'info_dict': {
            'id': 'lrt-opus',
            'live_status': 'is_live',
            'title': 're:^LRT Opus.+$',
            'ext': 'mp4'
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        streams_data = self._download_json(self._extract_js_var(webpage, 'tokenURL'), video_id)

        formats, subtitles = [], {}
        for stream_url in traverse_obj(streams_data, (
                'response', 'data', lambda k, _: k.startswith('content')), expected_type=url_or_none):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(stream_url, video_id, 'mp4', m3u8_id='hls', live=True)
            formats.extend(fmts)
            subtitles = self._merge_subtitles(subtitles, subs)
        self._sort_formats(formats)

        stream_title = self._extract_js_var(webpage, 'video_title', 'LRT')
        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            'is_live': True,
            'title': f'{self._og_search_title(webpage)} - {stream_title}'
        }


class LRTVODIE(LRTBaseIE):
    _VALID_URL = r'https?://(?:www\.)?lrt\.lt(?P<path>/mediateka/irasas/(?P<id>[0-9]+))'
    _TESTS = [{
        # m3u8 download
        'url': 'https://www.lrt.lt/mediateka/irasas/2000127261/greita-ir-gardu-sicilijos-ikvepta-klasikiniu-makaronu-su-baklazanais-vakariene',
        'info_dict': {
            'id': '2000127261',
            'ext': 'mp4',
            'title': 'Greita ir gardu: Sicilijos įkvėpta klasikinių makaronų su baklažanais vakarienė',
            'description': 'md5:ad7d985f51b0dc1489ba2d76d7ed47fa',
            'duration': 3035,
            'timestamp': 1604079000,
            'upload_date': '20201030',
            'tags': ['LRT TELEVIZIJA', 'Beatos virtuvė', 'Beata Nicholson', 'Makaronai', 'Baklažanai', 'Vakarienė', 'Receptas'],
            'thumbnail': 'https://www.lrt.lt/img/2020/10/30/764041-126478-1287x836.jpg'
        },
    }, {
        # direct mp3 download