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

Code before:
        video_id = urllib.parse.unquote(self._match_id(url))
        webpage = self._download_webpage(url, video_id)

        json = self._search_json(r'window\.ltvEmbedPayload\s*=', webpage, 'embed json', video_id)

        embed_type = traverse_obj(json, ('source', 'name'))

        embed_data = {}
        if embed_type == 'telia':
            embed_data = {
                'ie_key': 'CloudyCDN',
                'url': traverse_obj(json, ('source', 'embed_url', {url_or_none})),
            }
        elif embed_type == 'youtube':
            embed_data = {
                'ie_key': 'Youtube',
                'url': traverse_obj(json, ('source', 'id')),
            }

        return {
            **embed_data,
            '_type': 'url',
            'id': video_id,
            'title': traverse_obj(json, ('parentInfo', 'title')),
            'duration': traverse_obj(json, ('parentInfo', 'duration', {int_or_none})),
            'thumbnail': traverse_obj(json, ('source', 'poster', {url_or_none})),
        }


class LSMLTVIE(LSMBaseIE):
    _VALID_URL = r'https?://ltv\.lsm\.lv/.*/raksts/.*\.id(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://ltv.lsm.lv/lv/raksts/21.11.2023-4-studija-zolitudes-tragedija-un-incupes-stacija.id311130',
        'md5': '64f72a360ca530d5ed89c77646c9eee5',
        'info_dict': {
            'id': '46k_d23-6000-105',
            'ext': 'mp4',
            'timestamp': 1700586300,
            'duration': 1442,
            'upload_date': '20231121',
            'title': '4. studija. Zolitūdes traģēdija un Inčupes stacija',
            'thumbnail': 'https://ltv.lsm.lv/storage/media/8/7/large/5/1f9604e1.jpg',
        }
    }]

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

        json = self._search_nuxt_data(self.fix_nuxt_data(webpage), video_id)
        embed_id = traverse_obj(json, ('article', 'videoMediaItem', 'video', 'embed_id'))

Review comment (suggestion):
```suggestion
            **traverse_obj(json, {
                'title': ('parentInfo', 'title'),
                'duration': ('parentInfo', 'duration', {int_or_none}),
                'thumbnail': ('source', 'poster', {url_or_none}),
            }),
```

Code after:
            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):
    _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',
        }
    }, {
        'url': 'https://ltv.lsm.lv/embed?enablesdkjs=1&c=eyJpdiI6IncwVzZmUFk2MU12enVWK1I3SUcwQ1E9PSIsInZhbHVlIjoid3FhV29vamc3T2sxL1RaRmJ5Rm1GTXozU0o2dVczdUtLK0cwZEZJMDQ2a3ZIRG5DK2pneGlnbktBQy9uazVleHN6VXhxdWIweWNvcHRDSnlISlNYOHlVZ1lpcTUrcWZSTUZPQW14TVdkMW9aOUtRWVNDcFF4eWpHNGcrT0VZbUNFQStKQk91cGpndW9FVjJIa0lpbkh3PT0iLCJtYWMiOiIyZGI1NDJlMWRlM2QyMGNhOGEwYTM2MmNlN2JlOGRhY2QyYjdkMmEzN2RlOTEzYTVkNzI1ODlhZDlhZjU4MjQ2IiwidGFnIjoiIn0=',
        'md5': 'a1711e190fe680fdb68fd8413b378e87',
        'info_dict': {
            'id': 'wUnFArIPDSY',
            'ext': 'mp4',
            'uploader': 'LTV_16plus',
            'release_date': '20220514',
            'channel_url': 'https://www.youtube.com/channel/UCNMrnafwXD2XKeeQOyfkFCw',
            'view_count': int,