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

Code before:
            'id': '2000420320',
            'ext': 'mp4',
            'title': 'Kuris senovės romėnų poetas aprašė Narcizo mitą?',
            'description': 'Intelektinė viktorina. Ved. Arūnas Valinskas ir Andrius Tapinas.',
            'channel': 'Auksinis protas. Vasara',
            'thumbnail': 'https://www.lrt.lt/img/2025/06/09/2094343-987905-1287x836.jpg',
            'tags': ['LRT TELEVIZIJA', 'Auksinis protas'],
            'timestamp': 1749851040,
            'upload_date': '20250613',
        },
    }, {
        'url': 'https://archyvai.lrt.lt/mediateka/video/ziniu-riteriai-ir-damos?episode=49685&season=%2Fmediateka%2Fvideo%2Fziniu-riteriai-ir-damos%2F2013',
        'only_matching': True,
    }, {
        'url': 'https://archyvai.lrt.lt/mediateka/irasas/2000077058/panorama-1989-baltijos-kelias',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        # TODO: Use _search_nextjs_v13_data once fixed
        canonical_url = (self._search_regex(
            r'\\"(?:article|data)\\":{[^}]*\\"url\\":\\"(/[^"]+)\\"', webpage, 'content', fatal=False) or self._search_regex(
            r'<link\s+rel="canonical"\s*href="([^"]+)"', webpage, 'canonical URL'))

        media = self._download_json(
            'https://www.lrt.lt/servisai/stream_url/vod/media_info/',
            video_id, query={'url': canonical_url})
        jw_data = self._parse_jwplayer_data(
            media['playlist_item'], video_id, base_url=url)

        return {
            **jw_data,
            **traverse_obj(media, {
                'id': ('id', {str}),
                'title': ('title', {str}),
                'description': ('content', {clean_html}),
                'timestamp': ('date', {lambda x: x.replace('.', '/')}, {unified_timestamp}),
                'tags': ('tags', ..., 'name', {str}),
            }),
        }


class LRTRadioIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?lrt\.lt/radioteka/irasas/(?P<id>\d+)/(?P<path>[^?#/]+)'
    _TESTS = [{
        # m3u8 download
        'url': 'https://www.lrt.lt/radioteka/irasas/2000359728/nemarios-eiles-apie-pragarus-ir-skaistyklas-su-aiste-kiltinaviciute',
        'info_dict': {

Review comment (suggestion):
```suggestion
        canonical_url = (
            self._search_regex(r'\\"(?:article|data)\\":{[^}]*\\"url\\":\\"(/[^"]+)\\"', webpage, 'content', fatal=False)
            or self._search_regex(r'<link\s+rel="canonical"\s*href="(/[^"]+)"', webpage, 'canonical URL'))
```

Code after:
            'id': '2000420320',
            'ext': 'mp4',
            'title': 'Kuris senovės romėnų poetas aprašė Narcizo mitą?',
            'description': 'Intelektinė viktorina. Ved. Arūnas Valinskas ir Andrius Tapinas.',
            'channel': 'Auksinis protas. Vasara',
            'thumbnail': 'https://www.lrt.lt/img/2025/06/09/2094343-987905-1287x836.jpg',
            'tags': ['LRT TELEVIZIJA', 'Auksinis protas'],
            'timestamp': 1749851040,
            'upload_date': '20250613',
        },
    }, {
        'url': 'https://archyvai.lrt.lt/mediateka/video/ziniu-riteriai-ir-damos?episode=49685&season=%2Fmediateka%2Fvideo%2Fziniu-riteriai-ir-damos%2F2013',
        'only_matching': True,
    }, {
        'url': 'https://archyvai.lrt.lt/mediateka/irasas/2000077058/panorama-1989-baltijos-kelias',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        # TODO: Use _search_nextjs_v13_data once fixed
        canonical_url = (
            self._search_regex(r'\\"(?:article|data)\\":{[^}]*\\"url\\":\\"(/[^"]+)\\"', webpage, 'content URL', fatal=False)
            or self._search_regex(r'<link\s+rel="canonical"\s*href="(/[^"]+)"', webpage, 'canonical URL'))

        media = self._download_json(
            'https://www.lrt.lt/servisai/stream_url/vod/media_info/',
            video_id, query={'url': canonical_url})
        jw_data = self._parse_jwplayer_data(
            media['playlist_item'], video_id, base_url=url)

        return {
            **jw_data,
            **traverse_obj(media, {
                'id': ('id', {str}),
                'title': ('title', {str}),
                'description': ('content', {clean_html}),
                'timestamp': ('date', {lambda x: x.replace('.', '/')}, {unified_timestamp}),
                'tags': ('tags', ..., 'name', {str}),
            }),
        }


class LRTRadioIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?lrt\.lt/radioteka/irasas/(?P<id>\d+)/(?P<path>[^?#/]+)'
    _TESTS = [{
        # m3u8 download
        'url': 'https://www.lrt.lt/radioteka/irasas/2000359728/nemarios-eiles-apie-pragarus-ir-skaistyklas-su-aiste-kiltinaviciute',
        'info_dict': {