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

Code before:
    }, {
        'url': 'https://replay.lsm.lv/lv/ieraksts/lr/183522/138-nepilniga-kompensejamo-zalu-sistema-pat-menesiem-dzena-pacientus-pa-aptiekam',
        'md5': '719b33875cd1429846eeeaeec6df2830',
        'info_dict': {
            'id': 'a342781',
            'ext': 'mp3',
            'duration': 1823,
            'title': '#138 Nepilnīgā kompensējamo zāļu sistēma pat mēnešiem dzenā pacientus pa aptiekām',
            'thumbnail': 'https://pic.latvijasradio.lv/public/assets/media/9/d/large_fd4675ac.jpg',
            'upload_date': '20231102',
            'timestamp': 1698921060,
            'description': 'md5:7bac3b2dd41e44325032943251c357b1',
        }
    }, {
        'url': 'https://replay.lsm.lv/ru/statja/ltv/311130/4-studija-zolitudes-tragedija-un-incupes-stacija',
        'only_matching': True,
    }]

    def fix_nuxt_data(self, webpage):
        return re.sub(r'Object\.create\(null(?:,(\{.+\}))?\)', lambda m: m.group(1) or 'null', webpage)

    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, context_name='__REPLAY__')

        return {
            '_type': 'url_transparent',
            'id': video_id,
            **traverse_obj(json, {
                'url': ('playback', 'service', 'url', {url_or_none}),
                'title': ('mediaItem', 'title'),
                'description': ('mediaItem', ('lead', 'body')),
                'duration': ('mediaItem', 'duration', {int_or_none}),
                'timestamp': ('mediaItem', 'aired_at', {parse_iso8601}),
                'thumbnail': ('mediaItem', 'largeThumbnail', {url_or_none}),
            }, get_all=False),
        }


Review comment (suggestion):
don't use `json` as var name
```suggestion
        data = self._search_nuxt_data(
            self._fix_nuxt_data(webpage), video_id, context_name='__REPLAY__')
```

Code after:
            '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',
        }
    }, {
        'url': 'https://replay.lsm.lv/lv/ieraksts/lr/183522/138-nepilniga-kompensejamo-zalu-sistema-pat-menesiem-dzena-pacientus-pa-aptiekam',
        'md5': '719b33875cd1429846eeeaeec6df2830',
        'info_dict': {
            'id': 'a342781',
            'ext': 'mp3',
            'duration': 1823,
            'title': '#138 Nepilnīgā kompensējamo zāļu sistēma pat mēnešiem dzenā pacientus pa aptiekām',
            'thumbnail': 'https://pic.latvijasradio.lv/public/assets/media/9/d/large_fd4675ac.jpg',
            'upload_date': '20231102',
            'timestamp': 1698921060,
            'description': 'md5:7bac3b2dd41e44325032943251c357b1',
        }
    }, {
        'url': 'https://replay.lsm.lv/ru/statja/ltv/311130/4-studija-zolitudes-tragedija-un-incupes-stacija',
        'only_matching': True,
    }]

    def _fix_nuxt_data(self, webpage):
        return re.sub(r'Object\.create\(null(?:,(\{.+\}))?\)', lambda m: m.group(1) or 'null', webpage)

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

        data = self._search_nuxt_data(
            self._fix_nuxt_data(webpage), video_id, context_name='__REPLAY__')

        return {
            '_type': 'url_transparent',
            'id': video_id,
            **traverse_obj(data, {
                'url': ('playback', 'service', 'url', {url_or_none}),
                'title': ('mediaItem', 'title'),
                'description': ('mediaItem', ('lead', 'body')),
                'duration': ('mediaItem', 'duration', {int_or_none}),
                'timestamp': ('mediaItem', 'aired_at', {parse_iso8601}),
                'thumbnail': ('mediaItem', 'largeThumbnail', {url_or_none}),
            }, get_all=False),
        }