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

Code before:
            'ext': 'mp4',
            'title': 'Извержение вулкана из спичек: зрелищный опыт',
            'description': 'md5:053ad3c61b5596d510c9a199dc8ee633',
            'thumbnail': 're:^https://avatars.dzeninfra.ru/',
            'uploader': 'TechInsider',
            'upload_date': '20210123',
            'timestamp': 1611378221,
        },
        'params': {'skip_download': 'm3u8'},
    }, {
        'url': 'https://zen.yandex.ru/media/id/606fd806cc13cb3c58c05cf5/novyi-samsung-fold-3-moskvich-barahlit-612f93b7f8d48e7e945792a2?from=channel&rid=2286618386.482.1630817595976.42360',
        'only_matching': True,
    }, {
        'url': 'https://dzen.ru/media/id/606fd806cc13cb3c58c05cf5/novyi-samsung-fold-3-moskvich-barahlit-612f93b7f8d48e7e945792a2?from=channel&rid=2286618386.482.1630817595976.42360',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        redirect = self._search_json(r'var it\s*=', webpage, 'redirect', id, default={}).get('retpath')
        if redirect:
            video_id = self._match_id(redirect)
            webpage = self._download_webpage(redirect, video_id, note='Redirecting')
        data_json = self._search_json(
            r'data\s*=', webpage, 'metadata', video_id, contains_pattern=r'{["\']_*serverState_*video.+}')
        serverstate = self._search_regex(r'(_+serverState_+video-site_[^_]+_+)',
                                         webpage, 'server state').replace('State', 'Settings')
        uploader = self._search_regex(r'(<a\s*class=["\']card-channel-link[^"\']+["\'][^>]+>)',
                                      webpage, 'uploader', default='<a>')
        uploader_name = extract_attributes(uploader).get('aria-label')
        video_json = try_get(data_json, lambda x: x[serverstate]['exportData']['video'], dict)
        stream_urls = try_get(video_json, lambda x: x['video']['streams'])
        formats = []
        for s_url in stream_urls:
            ext = determine_ext(s_url)
            if ext == 'mpd':
                formats.extend(self._extract_mpd_formats(s_url, video_id, mpd_id='dash'))
            elif ext == 'm3u8':
                formats.extend(self._extract_m3u8_formats(s_url, video_id, 'mp4'))
        return {
            'id': video_id,
            'title': video_json.get('title') or self._og_search_title(webpage),
            'formats': formats,
            'duration': int_or_none(video_json.get('duration')),
            'view_count': int_or_none(video_json.get('views')),
            'timestamp': int_or_none(video_json.get('publicationDate')),
            'uploader': uploader_name or data_json.get('authorName') or try_get(data_json, lambda x: x['publisher']['name']),
            'description': self._og_search_description(webpage) or try_get(data_json, lambda x: x['og']['description']),
            'thumbnail': self._og_search_thumbnail(webpage) or try_get(data_json, lambda x: x['og']['imageUrl']),
        }

Review comment (suggestion):
```suggestion
            r'"data"\s*[=:]', webpage, 'metadata', video_id, contains_pattern=r'{["\']_*serverState_*video.+}')
```

Just in case. Same below

Code after:
            'ext': 'mp4',
            'title': 'Извержение вулкана из спичек: зрелищный опыт',
            'description': 'md5:053ad3c61b5596d510c9a199dc8ee633',
            'thumbnail': 're:^https://avatars.dzeninfra.ru/',
            'uploader': 'TechInsider',
            'upload_date': '20210123',
            'timestamp': 1611378221,
        },
        'params': {'skip_download': 'm3u8'},
    }, {
        'url': 'https://zen.yandex.ru/media/id/606fd806cc13cb3c58c05cf5/novyi-samsung-fold-3-moskvich-barahlit-612f93b7f8d48e7e945792a2?from=channel&rid=2286618386.482.1630817595976.42360',
        'only_matching': True,
    }, {
        'url': 'https://dzen.ru/media/id/606fd806cc13cb3c58c05cf5/novyi-samsung-fold-3-moskvich-barahlit-612f93b7f8d48e7e945792a2?from=channel&rid=2286618386.482.1630817595976.42360',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        redirect = self._search_json(r'var it\s*=', webpage, 'redirect', id, default={}).get('retpath')
        if redirect:
            video_id = self._match_id(redirect)
            webpage = self._download_webpage(redirect, video_id, note='Redirecting')
        data_json = self._search_json(
            r'("data"\s*:|data\s*=)', webpage, 'metadata', video_id, contains_pattern=r'{["\']_*serverState_*video.+}')
        serverstate = self._search_regex(r'(_+serverState_+video-site_[^_]+_+)',
                                         webpage, 'server state').replace('State', 'Settings')
        uploader = self._search_regex(r'(<a\s*class=["\']card-channel-link[^"\']+["\'][^>]+>)',
                                      webpage, 'uploader', default='<a>')
        uploader_name = extract_attributes(uploader).get('aria-label')
        video_json = try_get(data_json, lambda x: x[serverstate]['exportData']['video'], dict)
        stream_urls = try_get(video_json, lambda x: x['video']['streams'])
        formats, subtitles = [], {}
        for s_url in stream_urls:
            ext = determine_ext(s_url)
            if ext == 'mpd':
                fmts, subs = self._extract_mpd_formats_and_subtitles(s_url, video_id, mpd_id='dash')
            elif ext == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(s_url, video_id, 'mp4')
            formats.extend(fmts)
            subtitles = self._merge_subtitles(subtitles, subs)
        return {
            'id': video_id,
            'title': video_json.get('title') or self._og_search_title(webpage),
            'formats': formats,
            'subtitles': subtitles,
            'duration': int_or_none(video_json.get('duration')),
            'view_count': int_or_none(video_json.get('views')),
            'timestamp': int_or_none(video_json.get('publicationDate')),
            'uploader': uploader_name or data_json.get('authorName') or try_get(data_json, lambda x: x['publisher']['name']),