Repository: yt-dlp/yt-dlp

Issue:
[yandexvideo] Failed video download on dzen.ru
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting that yt-dlp is broken on a **supported** site
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

Germany/Europe

### Provide a description that is worded well enough to be understood

Downloading this video fails:

https://dzen.ru/video/watch/65f897a5d901db5e49ed39d6?rid=3126738634.50.1714225125937.28233&encoded_pulse_user_info=iHmAxSejZvCwjcoDkLxmGwVxNmYob4zbbcKRQyWu24QYXXwZEGZQOG2jwL4rTZRkel6wS2B0xEFoZ9ghe8L_KA%3A1714225126182&from_site=mail

Regarding whether this is a supported site: dzen.ru is not listed in --list-extractors, but as you can see in the log, it gets redirected to the yandexvideo extractor, so I assume dzen.ru should be working.

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
python3 yt-dlp -vU 'https://dzen.ru/video/watch/65f897a5d901db5e49ed39d6?rid=3126738634.50.1714225125937.28233&encoded_pulse_user_info=iHmAxSejZvCwjcoDkLxmGwVxNmYob4zbbcKRQyWu24QYXXwZEGZQOG2jwL4rTZRkel6wS2B0xEFoZ9ghe8L_KA%3A1714225126182&from_site=mail'
[debug] Command-line config: ['-vU', 'https://dzen.ru/video/watch/65f897a5d901db5e49ed39d6?rid=3126738634.50.1714225125937.28233&encoded_pulse_user_info=iHmAxSejZvCwjcoDkLxmGwVxNmYob4zbbcKRQyWu24QYXXwZEGZQOG2jwL4rTZRkel6wS2B0xEFoZ9ghe8L_KA%3A1714225126182&from_site=mail']
[debug] Portable config "/home/matthias/Videos/yt-dlp.conf": ['--no-mtime', '--remux-video', 'mkv', '--paths', 'temp:/tmp', '--abort-on-unavailable-fragments']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2024.04.09 from yt-dlp/yt-dlp [ff0779267] (zip)
[debug] Python 3.11.7 (CPython x86_64 64bit) - Linux-6.7.4-artix1-1-x86_64-with-glibc2.39 (OpenSSL 3.2.1 30 Jan 2024, glibc 2.39)
[debug] exe versions: ffmpeg 6.1.1 (setts), ffprobe 6.1.1
[debug] Optional libraries: certifi-2024.02.02, requests-2.31.0, sqlite3-3.45.1, urllib3-1.26.18
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests
[debug] Loaded 1810 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: stable@2024.04.09 from yt-dlp/yt-dlp
yt-dlp is up to date (stable@2024.04.09 from yt-dlp/yt-dlp)
[ZenYandex] Extracting URL: https://dzen.ru/video/watch/65f897a5d901db5e49ed39d6?rid=3126738634.50.1714225125937.28233&encoded_pulse_user_info=iHmAxSejZvCwjcoDkLxmGwVxNmYob4zbbcKRQyWu24QYXXwZEGZQOG2jwL4rTZRkel6wS2B0xEFoZ9ghe8L_KA%3A1714225126182&from_site=mail
[ZenYandex] 65f897a5d901db5e49ed39d6: Downloading webpage
[ZenYandex] 65f897a5d901db5e49ed39d6: Redirecting
ERROR: 'NoneType' object is not iterable
Traceback (most recent call last):
  File "/home/matthias/Videos/yt-dlp/yt_dlp/YoutubeDL.py", line 1606, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matthias/Videos/yt-dlp/yt_dlp/YoutubeDL.py", line 1741, in __extract_info
    ie_result = ie.extract(url)
                ^^^^^^^^^^^^^^^
  File "/home/matthias/Videos/yt-dlp/yt_dlp/extractor/common.py", line 734, in extract
    ie_result = self._real_extract(url)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matthias/Videos/yt-dlp/yt_dlp/extractor/yandexvideo.py", line 270, in _real_extract
    for s_url in stream_urls:
TypeError: 'NoneType' object is not iterable
```



Discussion:
Apparently they changed the JSON's format a bit, will make a PR

Resolving patch:
diff --git a/yt_dlp/extractor/yandexvideo.py b/yt_dlp/extractor/yandexvideo.py
--- a/yt_dlp/extractor/yandexvideo.py
+++ b/yt_dlp/extractor/yandexvideo.py
@@ -259,15 +259,15 @@ def _real_extract(self, url):
             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')
+        serverstate = self._search_regex(r'(_+serverState_+video-site_[^_]+_+)', webpage, 'server state')
         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'])
+        item_id = traverse_obj(data_json, (serverstate, 'videoViewer', 'openedItemId', {str}))
+        video_json = traverse_obj(data_json, (serverstate, 'videoViewer', 'items', item_id, {dict})) or {}
+
         formats, subtitles = [], {}
-        for s_url in stream_urls:
+        for s_url in traverse_obj(video_json, ('video', 'streams', ..., {url_or_none})):
             ext = determine_ext(s_url)
             if ext == 'mpd':
                 fmts, subs = self._extract_mpd_formats_and_subtitles(s_url, video_id, mpd_id='dash')


Test patch: