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

Code before:
            'comment_count': int,
            'channel_id': 'UCNMrnafwXD2XKeeQOyfkFCw',
            'channel_follower_count': int,
            'categories': ['Entertainment'],
            'duration': 5269,
            'upload_date': '20220514',
            'age_limit': 0,
            'channel': 'LTV_16plus',
            'playable_in_embed': True,
            'tags': [],
            'uploader_url': 'https://www.youtube.com/@LTV16plus',
            'like_count': int,
            'description': 'md5:7ff0c42ba971e3c13e4b8a2ff03b70b5',
            'media_type': 'livestream',
            'timestamp': 1652550741,
        },
    }]

    def _real_extract(self, url):
        video_id = urllib.parse.unquote(self._match_id(url))
        webpage = self._download_webpage(url, video_id)
        data = self._search_json(
            r'window\.ltvEmbedPayload\s*=', webpage, 'embed json', video_id)
        embed_type = traverse_obj(data, ('source', 'name', {str}))

        if embed_type == 'backscreen':
            ie_key = 'CloudyCDN'
            embed_url = traverse_obj(data, ('source', 'embed_url', {url_or_none}))
        elif embed_type == 'youtube':
            ie_key = 'Youtube'
            embed_url = traverse_obj(data, ('source', 'id', {str}))
        else:
            raise ExtractorError(f'Unsupported embed type {embed_type!r}')

        return self.url_result(
            embed_url, ie_key, video_id, **traverse_obj(data, {
                'title': ('parentInfo', 'title'),
                'duration': ('parentInfo', 'duration', {int_or_none}),
                'thumbnail': ('source', 'poster', {url_or_none}),
            }))


class LSMReplayIE(InfoExtractor):
    _VALID_URL = r'https?://replay\.lsm\.lv/[^/?#]+/(?:skaties|klausies)/(?:ieraksts|statja)/[^/?#]+/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://replay.lsm.lv/lv/skaties/ieraksts/ltv/311130/4-studija-zolitudes-tragedija-un-incupes-stacija',
        'md5': '64f72a360ca530d5ed89c77646c9eee5',
        'info_dict': {
            'id': '46k_d23-6000-105',
            'ext': 'mp4',
            'timestamp': 1700586300,

Review comment (suggestion):
assuming it's not harmful, could we do this
```suggestion
        if embed_type in ('backscreen', 'telia'):  # 'telia' only for backwards compat
```

Code after:
            'comment_count': int,
            'channel_id': 'UCNMrnafwXD2XKeeQOyfkFCw',
            'channel_follower_count': int,
            'categories': ['Entertainment'],
            'duration': 5269,
            'upload_date': '20220514',
            'age_limit': 0,
            'channel': 'LTV_16plus',
            'playable_in_embed': True,
            'tags': [],
            'uploader_url': 'https://www.youtube.com/@LTV16plus',
            'like_count': int,
            'description': 'md5:7ff0c42ba971e3c13e4b8a2ff03b70b5',
            'media_type': 'livestream',
            'timestamp': 1652550741,
        },
    }]

    def _real_extract(self, url):
        video_id = urllib.parse.unquote(self._match_id(url))
        webpage = self._download_webpage(url, video_id)
        data = self._search_json(
            r'window\.ltvEmbedPayload\s*=', webpage, 'embed json', video_id)
        embed_type = traverse_obj(data, ('source', 'name', {str}))

        if embed_type in ('backscreen', 'telia'):  # 'telia' only for backwards compat
            ie_key = 'CloudyCDN'
            embed_url = traverse_obj(data, ('source', 'embed_url', {url_or_none}))
        elif embed_type == 'youtube':
            ie_key = 'Youtube'
            embed_url = traverse_obj(data, ('source', 'id', {str}))
        else:
            raise ExtractorError(f'Unsupported embed type {embed_type!r}')

        return self.url_result(
            embed_url, ie_key, video_id, **traverse_obj(data, {
                'title': ('parentInfo', 'title'),
                'duration': ('parentInfo', 'duration', {int_or_none}),
                'thumbnail': ('source', 'poster', {url_or_none}),
            }))


class LSMReplayIE(InfoExtractor):
    _VALID_URL = r'https?://replay\.lsm\.lv/[^/?#]+/(?:skaties/|klausies/)?(?:ieraksts|statja)/[^/?#]+/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://replay.lsm.lv/lv/skaties/ieraksts/ltv/311130/4-studija-zolitudes-tragedija-un-incupes-stacija',
        'md5': '64f72a360ca530d5ed89c77646c9eee5',
        'info_dict': {
            'id': '46k_d23-6000-105',
            'ext': 'mp4',
            'timestamp': 1700586300,