Repository: yt-dlp/yt-dlp

Issue:
[RTBF] "ERROR:  An extractor error has occurred." using "--cookies-from-browser" or --cookies
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

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

### Checklist

- [X] I'm reporting a bug unrelated to a specific site
- [X] I've verified that I'm running yt-dlp version **2022.08.14** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [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/ytdl-org/youtube-dl#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 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)

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

[Note: existing issue  #4671 is still open but I was advised to open a new issue.]

Since updating to 2022.08.14, I cannot download videos from RTBF with the option "--cookies-from-browser". I can indeed download videos using -u username -p password.

Not sure if this helps, but I have saved two dumps here:
https://gist.github.com/Ottaviocr/057f03cf1145a521f39b16c5ab826430


### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
$ yt-dlp -vU
[debug] Command-line config: ['-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.14 [5593720] (zip)
[debug] Python 3.9.2 (CPython 64bit) - Linux-5.18.0-0.bpo.1-amd64-x86_64-with-glibc2.33 (glibc 2.33)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.0-static (setts), ffprobe 5.0-static
[debug] Optional libraries: Cryptodome-3.9.7, brotli-1.0.9, certifi-2020.06.20, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.08.14, Current version: 2022.08.14
yt-dlp is up to date (2022.08.14)

$ yt-dlp --cookies-from-browser firefox https://www.rtbf.be/auvio/detail_jt-19h30?id=2929547 -v
[debug] Command-line config: ['--cookies-from-browser', 'firefox', 'https://www.rtbf.be/auvio/detail_jt-19h30?id=2929547', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.14 [5593720] (zip)
[debug] Python 3.9.2 (CPython 64bit) - Linux-5.18.0-0.bpo.1-amd64-x86_64-with-glibc2.33 (glibc 2.33)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.0-static (setts), ffprobe 5.0-static
[debug] Optional libraries: Cryptodome-3.9.7, brotli-1.0.9, certifi-2020.06.20, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[Cookies] Extracting cookies from firefox
[debug] Extracting cookies from: "/home/oc/.mozilla/firefox/i0z6z7rn.default/cookies.sqlite"
[Cookies] Extracted 289 cookies from firefox
[debug] Proxy map: {}
[debug] [RTBF] Extracting URL: https://www.rtbf.be/auvio/detail_jt-19h30?id=2929547
[RTBF] 2929547: Downloading webpage
[RTBF] 2929547: Downloading JSON metadata
ERROR: 2929547: An extractor error has occurred. (caused by KeyError('id_token')); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/common.py", line 666, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/redbee.py", line 345, in _real_extract
    fmts, subs = self._get_formats_and_subtitles(url, media_id)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/redbee.py", line 254, in _get_formats_and_subtitles
    session_jwt = self._download_json(
KeyError: 'id_token'
```



Discussion:
Can you try using my latest branch? https://github.com/elyse0/yt-dlp/tree/rtbf-stream

This is a link to download the source code: https://github.com/elyse0/yt-dlp/archive/refs/heads/rtbf-stream.zip
[elyse0](https://github.com/elyse0), I compiled your version. I have a binary in ~/test/yt-dlp-rtbf-stream/yt-dlp

<pre>
$ test/yt-dlp-rtbf-stream/yt-dlp --cookies-from-browser firefox  https://www.rtbf.be/auvio/detail_jt-13h?id=2929608 -v
	[debug] Command-line config: ['--cookies-from-browser', 'firefox', 'https://www.rtbf.be/auvio/detail_jt-13h?id=2929608', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.08 [3157158f7] (zip)
[debug] Plugins: ['SamplePluginIE', 'SamplePluginPP']
[debug] Python 3.9.2 (CPython 64bit) - Linux-5.18.0-0.bpo.1-amd64-x86_64-with-glibc2.33 (glibc 2.33)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.0-static (setts), ffprobe 5.0-static
[debug] Optional libraries: Cryptodome-3.9.7, brotli-1.0.9, certifi-2020.06.20, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[Cookies] Extracting cookies from firefox
[debug] Extracting cookies from: "/home/oc/.mozilla/firefox/i0z6z7rn.default/cookies.sqlite"
[Cookies] Extracted 288 cookies from firefox
[debug] Proxy map: {}
[debug] [RTBF] Extracting URL: https://www.rtbf.be/auvio/detail_jt-13h?id=2929608
[RTBF] 2929608: Downloading webpage
[RTBF] 2929608: Downloading JSON metadata
ERROR: 2929608: An extractor error has occurred. (caused by KeyError('id_token')); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/home/oc/test/yt-dlp-rtbf-stream/yt-dlp/yt_dlp/extractor/common.py", line 666, in extract
    ie_result = self._real_extract(url)
  File "/home/oc/test/yt-dlp-rtbf-stream/yt-dlp/yt_dlp/extractor/redbee.py", line 364, in _real_extract
    fmts, subs = self._get_formats_and_subtitles(url, f'live_{media_id}' if is_live else media_id)
  File "/home/oc/test/yt-dlp-rtbf-stream/yt-dlp/yt_dlp/extractor/redbee.py", line 258, in _get_formats_and_subtitles
    session_jwt = self._download_json(
KeyError: 'id_token'
</pre>

Unless I've done something wrong, I get the same error.


I have edited the title to reflect that even the "-cookies" switch fails when using the "Cookies.txt" Firefox extension:

<pre>
 $ yt-dlp -U
Latest version: 2022.08.14, Current version: 2022.08.14
yt-dlp is up to date (2022.08.14)
 $ yt-dlp --cookies cookies.txt  https://www.rtbf.be/auvio/detail_jt-13h?id=2929608 -v
[debug] Command-line config: ['--cookies', 'cookies.txt', 'https://www.rtbf.be/auvio/detail_jt-13h?id=2929608', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.14 [5593720] (zip)
[debug] Python 3.9.2 (CPython 64bit) - Linux-5.18.0-0.bpo.1-amd64-x86_64-with-glibc2.33 (glibc 2.33)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.0-static (setts), ffprobe 5.0-static
[debug] Optional libraries: Cryptodome-3.9.7, brotli-1.0.9, certifi-2020.06.20, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] [RTBF] Extracting URL: https://www.rtbf.be/auvio/detail_jt-13h?id=2929608
[RTBF] 2929608: Downloading webpage
[RTBF] 2929608: Downloading JSON metadata
ERROR: 2929608: An extractor error has occurred. (caused by KeyError('id_token')); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/common.py", line 666, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/redbee.py", line 345, in _real_extract
    fmts, subs = self._get_formats_and_subtitles(url, media_id)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/redbee.py", line 254, in _get_formats_and_subtitles
    session_jwt = self._download_json(
KeyError: 'id_token
</pre>

I can post the content of cookies.txt if necessary.
Mmmm weird 🤔 

Have you tried cleaning your firefox cookies and logging again?
The latest update from [pukkandan] (https://github.com/pukkandan)fixes the issue using "--cookies cookies.txt"

<pre>
$ yt-dlp -U
Latest version: 2022.08.19, Current version: 2022.08.19
yt-dlp is up to date (2022.08.19)

$ yt-dlp --cookies cookies.txt https://www.rtbf.be/auvio/detail_jt-13h?id=2930255 -v
[debug] Command-line config: ['--cookies', 'cookies.txt', 'https://www.rtbf.be/auvio/detail_jt-13h?id=2930255', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.19 [48c88e0] (zip)
[debug] Python 3.9.2 (CPython 64bit) - Linux-5.18.0-0.bpo.1-amd64-x86_64-with-glibc2.33 (glibc 2.33)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.0-static (setts), ffprobe 5.0-static
[debug] Optional libraries: Cryptodome-3.9.7, brotli-1.0.9, certifi-2020.06.20, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] [RTBF] Extracting URL: https://www.rtbf.be/auvio/detail_jt-13h?id=2930255
[RTBF] 2930255: Downloading webpage
[RTBF] 2930255: Downloading JSON metadata
[RTBF] 2930255: Downloading JSON metadata
[RTBF] 2930255: Downloading JSON metadata
[RTBF] 2930255: Downloading MPD manifest
[RTBF] 2930255: Downloading m3u8 information
[RTBF] 2930255: Downloading ISM manifest
[debug] Sort order given by extractor: res, proto
[debug] Formats sorted by: hasvid, ie_pref, res, proto, lang, quality, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 2930255: Downloading 1 format(s): 5642+130
[debug] Invoking hlsnative downloader on "https://C9851Ec-az-westeurope.fsly.cdn.ebsd.ericsson.net/rtbf/auvio/assets/2930255_6BA97Bb/materials/LN9ou9ekAY_6BA97Bb/vod-idx.ism/vod-idx-video=5200000.m3u8"
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 319
[download] Destination: 19.08.2022 [2930255].f5642.mp4
[download]   1.9% of ~1.15GiB at    1.80MiB/s ETA 03:54 (frag 6/319)
</pre>


... but not using "--cookies-from-browser firefox"

<pre>
$ yt-dlp --cookies-from-browser firefox https://www.rtbf.be/auvio/detail_jt-13h?id=2930255 -v
[debug] Command-line config: ['--cookies-from-browser', 'firefox', 'https://www.rtbf.be/auvio/detail_jt-13h?id=2930255', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.19 [48c88e0] (zip)
[debug] Python 3.9.2 (CPython 64bit) - Linux-5.18.0-0.bpo.1-amd64-x86_64-with-glibc2.33 (glibc 2.33)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.0-static (setts), ffprobe 5.0-static
[debug] Optional libraries: Cryptodome-3.9.7, brotli-1.0.9, certifi-2020.06.20, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[Cookies] Extracting cookies from firefox
[debug] Extracting cookies from: "/home/oc/.mozilla/firefox/i0z6z7rn.default/cookies.sqlite"
[Cookies] Extracted 289 cookies from firefox
[debug] Proxy map: {}
[debug] [RTBF] Extracting URL: https://www.rtbf.be/auvio/detail_jt-13h?id=2930255
[RTBF] 2930255: Downloading webpage
[RTBF] 2930255: Downloading JSON metadata
ERROR: 2930255: An extractor error has occurred. (caused by KeyError('id_token')); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/common.py", line 666, in extract
    ie_result = self._real_extract(url)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/redbee.py", line 364, in _real_extract
    fmts, subs = self._get_formats_and_subtitles(url, f'live_{media_id}' if is_live else media_id)
  File "/usr/local/bin/yt-dlp/yt_dlp/extractor/redbee.py", line 258, in _get_formats_and_subtitles
    session_jwt = self._download_json(
KeyError: 'id_token'
</pre>
 
Are these session cookies? It is impossible for yt-dlp to load session cookies from browser directly
> Mmmm weird 🤔
> 
> Have you tried cleaning your firefox cookies and logging again?

[elyse0](https://github.com/elyse0) your build works exactly the same as the master build, as referenced above. Yes, I did clear cookies before trying.
> Are these session cookies? It is impossible for yt-dlp to load session cookies from browser directly

[pukkandan](https://github.com/pukkandan) I'm buffled because I definitely used to use "--cookies-from-browser firefox" for RTBF videos with previous builds, on condition that they were not DRM videos, in which case it obviously didn't work. But the JT 13H is not DRM protected. 
[pukkandan](https://github.com/pukkandan), here's an old build:

<pre>$ ./yt-dlp_linux-2022.06.22.1 --version
2022.06.22.1
</pre>

And an old episode of "Le grand Cactus" using "--cookies-from-browser"


<pre>
$ ./yt-dlp_linux-2022.06.22.1 --cookies-from-browser firefox   https://www.rtbf.be/auvio/detail_le-grand-cactus?id=2735244
[Cookies] Extracting cookies from firefox
[Cookies] Extracted 292 cookies from firefox
[RTBF] 2735244: Downloading webpage
[RTBF] 2735244: Downloading m3u8 information
[RTBF] 2735244: Downloading MPD manifest
[info] 2735244: Downloading 1 format(s): hls-4233
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 796
[download] Destination: Le Grand Cactus [2735244].mp4
[download]   0.1% of ~3.13GiB at    1.14MiB/s ETA 16:37 (frag 1/796)
</pre>
In that case, this appears to be some regression in 2a5e5477bcb70d62de20556924a405857d071e09
While I don't rule out the possibility of a regression, I just want to point out that you're testing different videos

[Le grand cactus](https://www.rtbf.be/auvio/detail_le-grand-cactus?id=2735244) is an "old"  video that uses the old api (Freecaster), it doesn't need cookies and still works on the lastest version 2022.08.19

```bash
[debug] Command-line config: ['https://www.rtbf.be/auvio/detail_le-grand-cactus?id=2735244', '-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.19 [48c88e088]
[debug] Lazy loading extractors is disabled
[debug] Python 3.8.10 (CPython 64bit) - Linux-5.4.0-124-generic-x86_64-with-glibc2.29 (glibc 2.31)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg n5.0.1-8-g11eff7739a-20220712 (setts), ffprobe n5.0.1-8-g11eff7739a-20220712, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, secretstorage-2.3.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.08.19, Current version: 2022.08.19
yt-dlp is up to date (2022.08.19)
[debug] [RTBF] Extracting URL: https://www.rtbf.be/auvio/detail_le-grand-cactus?id=2735244
[RTBF] 2735244: Downloading webpage
[RTBF] 2735244: Downloading m3u8 information
[RTBF] 2735244: Downloading MPD manifest
[debug] Sort order given by extractor: res, proto
[debug] Formats sorted by: hasvid, ie_pref, res, proto, lang, quality, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 2735244: Downloading 1 format(s): hls-4233
[debug] Invoking hlsnative downloader on "https://rtbf-vod.fl.freecaster.net/vod/rtbf/geo/open/j/jlilD8L3vl/jlilD8L3vl-audio_fra=127000-video=3866000.m3u8"
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 796
[download] Destination: La 100e ! Avec les grands personnages de l'Histoire, Kiki Lantino, et Frank Michaël [2735244].mp4
[download]   0.8% of ~3.07GiB at   16.40KiB/s ETA 16:51
```

[The JT 13H](https://www.rtbf.be/auvio/detail_jt-13h?id=2930255) on the other hand is new and needs to use Redbee

```bash
[debug] Command-line config: ['https://www.rtbf.be/auvio/detail_jt-13h?id=2930255', '-vU', '--cookies-from-browser', 'firefox']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.08.19 [48c88e088]
[debug] Lazy loading extractors is disabled
[debug] Python 3.8.10 (CPython 64bit) - Linux-5.4.0-124-generic-x86_64-with-glibc2.29 (glibc 2.31)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg n5.0.1-8-g11eff7739a-20220712 (setts), ffprobe n5.0.1-8-g11eff7739a-20220712, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, secretstorage-2.3.1, sqlite3-2.6.0, websockets-10.3
[Cookies] Extracting cookies from firefox
[debug] Extracting cookies from: "/home/amish/.mozilla/firefox/ckczlffq.default-release/cookies.sqlite"
[Cookies] Extracted 442 cookies from firefox
[debug] Proxy map: {}
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.08.19, Current version: 2022.08.19
yt-dlp is up to date (2022.08.19)
[debug] [RTBF] Extracting URL: https://www.rtbf.be/auvio/detail_jt-13h?id=2930255
[RTBF] 2930255: Downloading webpage
[RTBF] 2930255: Downloading JSON metadata
[RTBF] 2930255: Downloading JSON metadata
[RTBF] 2930255: Downloading JSON metadata
[RTBF] 2930255: Downloading MPD manifest
[RTBF] 2930255: Downloading m3u8 information
[RTBF] 2930255: Downloading ISM manifest
[debug] Sort order given by extractor: res, proto
[debug] Formats sorted by: hasvid, ie_pref, res, proto, lang, quality, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, source, id
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 2930255: Downloading 1 format(s): 5642+130
[debug] Invoking hlsnative downloader on "https://C9851Ec-az-westeurope.fsly.cdn.ebsd.ericsson.net/rtbf/auvio/assets/2930255_6BA97Bb/materials/LN9ou9ekAY_6BA97Bb/vod-idx.ism/vod-idx-video=5200000.m3u8"
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 319
[download] Destination: 19.08.2022 [2930255].f5642.mp4
[download]   1.3% of ~1.15GiB at    2.97MiB/s ETA 06:29 (frag 4/319)
```

https://github.com/ytdl-org/youtube-dl/issues/31114#issuecomment-1220299096
@Ottaviocr If you want, I could look into this if you can send me your credentials. This is my email: elyse0@proton.me

And by the way, what distro are you using?
> @Ottaviocr If you want, I could look into this if you can send me your credentials. 

Check your inbox.

Resolving patch:
diff --git a/yt_dlp/extractor/redbee.py b/yt_dlp/extractor/redbee.py
--- a/yt_dlp/extractor/redbee.py
+++ b/yt_dlp/extractor/redbee.py
@@ -11,6 +11,7 @@
     int_or_none,
     strip_or_none,
     traverse_obj,
+    try_call,
     unified_timestamp,
 )
 
@@ -255,7 +256,7 @@ def _get_formats_and_subtitles(self, url, media_id):
         if not login_token:
             self.raise_login_required()
 
-        session_jwt = self._download_json(
+        session_jwt = try_call(lambda: self._get_cookies(url)['rtbf_jwt'].value) or self._download_json(
             'https://login.rtbf.be/accounts.getJWT', media_id, query={
                 'login_token': login_token.value,
                 'APIKey': self._GIGYA_API_KEY,


Test patch: