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

Code before:
        video_id = traverse_obj(query, ('show', 0, {int_or_none}))

        if not video_id:
            video_id = traverse_obj(query, ('id', 0, {int_or_none}))

        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)

        entries = []
        for item in traverse_obj(media_json, (('audio', 'video'), ...)):
            formats = []
            for source_url in traverse_obj(item, ('sources', ..., 'file', {url_or_none})):
                if source_url.endswith('.m3u8'):
                    formats.extend(self._extract_m3u8_formats(source_url, video_id))
                else:
                    formats.append({'url': source_url})

            id = item.get('id')
            title = item.get('title')
            if id and id.startswith('v') and not title:
                title = traverse_obj(
                    media_json, ('audio', lambda _, v: v['id'][1:] == id[1:], 'title',
                                 {lambda x: x and f'{x} - Video Version'}), get_all=False)

            entries.append({
                'formats': formats,
                'thumbnail': urljoin(url, player_json.get('poster')),
                'id': id,
                'title': title,
                'duration': traverse_obj(item, ('duration', {int_or_none})),
            })

        if len(entries) == 1:
            return entries[0]

        return self.playlist_result(entries, video_id)


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',

Review comment (suggestion):
```suggestion
            if id_.startswith('v') and not title:
```

Code after:
        'only_matching': True,
    }, {
        'url': 'https://lr1.lsm.lv/lv/pleijeris/?embed=0&id=48205&time=00%3A00&idx=0',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        query = parse_qs(url)
        video_id = traverse_obj(query, (
            ('show', 'id'), 0, {int_or_none}, {lambda x: x or None}, {str_or_none}), get_all=False)
        webpage = self._download_webpage(url, video_id)

        player_data, media_data = self._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, transform_source=js_to_json, fatal=False) or {}
        media_json = self._parse_json(media_data, video_id, transform_source=js_to_json)

        entries = []
        for item in traverse_obj(media_json, (('audio', 'video'), lambda _, v: v['id'])):
            formats = []
            for source_url in traverse_obj(item, ('sources', ..., 'file', {url_or_none})):
                if determine_ext(source_url) == 'm3u8':
                    formats.extend(self._extract_m3u8_formats(source_url, video_id, fatal=False))
                else:
                    formats.append({'url': source_url})

            id_ = item['id']
            title = item.get('title')
            if id_.startswith('v') and not title:
                title = traverse_obj(
                    media_json, ('audio', lambda _, v: v['id'][1:] == id_[1:], 'title',
                                 {lambda x: x and f'{x} - Video Version'}), get_all=False)

            entries.append({
                'formats': formats,
                'thumbnail': urljoin(url, player_json.get('poster')),
                'id': id_,
                'title': title,
                'duration': traverse_obj(item, ('duration', {int_or_none})),
            })

        if len(entries) == 1:
            return entries[0]

        return self.playlist_result(entries, video_id)


class LSMLTVEmbedIE(InfoExtractor):