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

Code before:
        'only_matching': True,
    }, {
        'url': 'https://radioteatris.lsm.lv/lv/embed/?id=176439&show=0&theme=white&size=16x9',
        'only_matching': True,
    }]

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

        player_data, media_data = self._html_search_regex(
            r'LR\.audio\.Player\s*\([^{]*(?P<player>\{.*?\}),(?P<media>\{.*\})\);',
            webpage, 'player json', group=('player', 'media'))

        player_json = self._parse_json(player_data, video_id, js_to_json)
        media_json = self._parse_json(media_data, video_id, js_to_json)

        formats = []
        for source in traverse_obj(media_json, ('audio', 0, 'sources')):
            url = source.get('file')

            if url is not None:
                if url.endswith('.m3u8'):
                    formats.extend(self._extract_m3u8_formats(url, video_id))
                else:
                    formats.append({'url': url})

        return {
            'id': video_id,
            'title': traverse_obj(media_json, ('audio', 0, 'title')),
            'formats': formats,
            'duration': traverse_obj(media_json, ('audio', 0, 'duration', {int_or_none})),
            'thumbnail': url_or_none(player_json.get('poster')),
        }


class LSMLTVEmbedIE(InfoExtractor):
    _VALID_URL = r'https?://ltv\.lsm\.lv/embed.*[?&]c=(?P<id>[^&]+)'
    _TESTS = [{
        'url': 'https://ltv.lsm.lv/embed?c=eyJpdiI6IjQzbHVUeHAyaDJiamFjcjdSUUFKdnc9PSIsInZhbHVlIjoiMHl3SnJNRmd2TmFIdnZwOGtGUUpzODFzUEZ4SVVsN2xoRjliSW9vckUyMWZIWG8vbWVzaFFkY0lhNmRjbjRpaCIsIm1hYyI6ImMzNjdhMzFhNTFhZmY1ZmE0NWI5YmFjZGI1YmJiNGEyNjgzNDM4MjUzMWEwM2FmMDMyZDMwYWM1MDFjZmM5MGIiLCJ0YWciOiIifQ==',
        'md5': '64f72a360ca530d5ed89c77646c9eee5',
        'info_dict': {
            'id': '46k_d23-6000-105',
            'ext': 'mp4',
            'timestamp': 1700589151,
            'duration': 1442,
            'upload_date': '20231121',
            'title': 'D23-6000-105_cetstud',
            'thumbnail': 'https://store.cloudycdn.services/tmsp00060/assets/media/660858/placeholder1700589200.jpg',
        }
    }, {

Review comment (refactor):
Are there any pages with multiple audio tracks?
Since we only need the URL we can also do:
```suggestion
        for url in traverse_obj(media_json, ('audio', 0, 'sources', ..., 'file', {url_or_none})):
            if url.endswith('.m3u8'):
                formats.extend(self._extract_m3u8_formats(url, video_id))
            else:
                formats.append({'url': url})
```

Code after:
                'title': 'Eriks Emanuels Šmits "Pilāta evaņģēlijs". 1. daļa',
                'thumbnail': 'https://radioteatris.lsm.lv/public/assets/shows/62f131ae81e3c.jpg',
                'duration': 3300,
            },
        }],
    }, {
        'url': 'https://radioteatris.lsm.lv/lv/embed/?id=&show=1269&theme=white&size=16x9',
        'md5': '24810d4a961da2295d9860afdcaf4f5a',
        'info_dict': {
            'id': 'a230690',
            'ext': 'mp3',
            'title': 'Jens Ahlboms "Spārni". Radioizrāde ar Mārtiņa Freimaņa mūziku',
            'thumbnail': 'https://radioteatris.lsm.lv/public/assets/shows/62f13023a457c.jpg',
            'duration': 1788,
        }
    }, {
        'url': 'https://lr1.lsm.lv/lv/embed/?id=166557&show=0&theme=white&size=16x9',
        'info_dict': {
            'id': '166557',
        },
        'playlist_count': 2,
        'playlist': [{
            'md5': '6a8b0927572f443f09c6e50a3ad65f2d',
            'info_dict': {
                'id': 'a303104',
                'ext': 'mp3',
                'thumbnail': 'https://pic.latvijasradio.lv/public/assets/media/c/5/gallery_a83ad2c2.jpg',
                'title': 'Krustpunktā Lielā intervija: Valsts prezidents Egils Levits',
                'duration': 3222,
            },
        }, {
            'md5': '5d5e191e718b7644e5118b7b4e093a6d',
            'info_dict': {
                'id': 'v303104',
                'ext': 'mp4',
                'thumbnail': 'https://pic.latvijasradio.lv/public/assets/media/c/5/gallery_a83ad2c2.jpg',
                'title': 'Krustpunktā Lielā intervija: Valsts prezidents Egils Levits - Video Version',
                'duration': 3222,
            },
        }],
    }, {
        'url': 'https://lr1.lsm.lv/lv/embed/?id=183522&show=0&theme=white&size=16x9',
        'only_matching': True,
    }, {
        'url': 'https://lr2.lsm.lv/lv/embed/?id=182126&show=0&theme=white&size=16x9',
        'only_matching': True,
    }, {
        'url': 'https://klasika.lsm.lv/lv/embed/?id=110806&show=0&theme=white&size=16x9',
        'only_matching': True,
    }, {
        'url': 'https://lr4.lsm.lv/lv/embed/?id=184282&show=0&theme=white&size=16x9',