Repository: yt-dlp/yt-dlp

Issue:
Yt-dlp cannot fetch video list information in a channel of bilibili
### 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

china

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

Yt-dlp cannot fetch video list information in a channel of bilibili.
It can still downloads single bilibili video.

yt-dlp https://space.bilibili.com/1984487658/video
[BilibiliSpaceVideo] Extracting URL: https://space.bilibili.com/1984487658/video
[BilibiliSpaceVideo] 1984487658: Downloading JSON metadata
[BilibiliSpaceVideo] 1984487658: Downloading page 0
ERROR: 1984487658: An extractor error has occurred. (caused by KeyError('page')); 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

I'm using the latest yt-dlp.
[debug] yt-dlp version stable@2024.03.10 from yt-dlp/yt-dlp [615a84447] (pip)

### 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] 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
D:\myweb\test\turtle_diary_test>yt-dlp -vU https://space.bilibili.com/1984487658/video
[debug] Command-line config: ['-vU', 'https://space.bilibili.com/1984487658/video']
[debug] Encodings: locale cp936, fs utf-8, pref cp936, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2024.03.10 from yt-dlp/yt-dlp [615a84447] (pip)
[debug] Python 3.8.10 (CPython AMD64 32bit) - Windows-10-10.0.26085-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: ffmpeg git-2020-02-18-ebee808, ffprobe git-2020-02-18-ebee808, rtmpdump 2.3
[debug] Optional libraries: Cryptodome-3.19.0, brotli-1.1.0, certifi-2023.07.22, mutagen-1.47.0, requests-2.31.0, sqlite3-3.35.5, urllib3-2.2.1, websockets-12.0
[debug] Proxy map: {'http': 'http://127.0.0.1:10809', 'https': 'http://127.0.0.1:10809', 'ftp': 'http://127.0.0.1:10809'}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1803 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: stable@2024.03.10 from yt-dlp/yt-dlp
yt-dlp is up to date (stable@2024.03.10 from yt-dlp/yt-dlp)
[BilibiliSpaceVideo] Extracting URL: https://space.bilibili.com/1984487658/video
[BilibiliSpaceVideo] 1984487658: Downloading JSON metadata
[BilibiliSpaceVideo] 1984487658: Downloading page 0
ERROR: 1984487658: An extractor error has occurred. (caused by KeyError('page')); 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 "C:\Python\lib\site-packages\yt_dlp\extractor\common.py", line 732, in extract
    ie_result = self._real_extract(url)
  File "C:\Python\lib\site-packages\yt_dlp\extractor\bilibili.py", line 1069, in _real_extract
    metadata, paged_list = self._extract_playlist(fetch_page, get_metadata, get_entries)
  File "C:\Python\lib\site-packages\yt_dlp\extractor\bilibili.py", line 973, in _extract_playlist
    metadata = get_metadata(first_page)
  File "C:\Python\lib\site-packages\yt_dlp\extractor\bilibili.py", line 1058, in get_metadata
    page_size = page_data['page']['ps']
KeyError: 'page'
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/bilibili.py b/yt_dlp/extractor/bilibili.py
--- a/yt_dlp/extractor/bilibili.py
+++ b/yt_dlp/extractor/bilibili.py
@@ -1049,9 +1049,10 @@ def fetch_page(page_idx):
                     raise ExtractorError(
                         'Request is blocked by server (412), please add cookies, wait and try later.', expected=True)
                 raise
-            if response['code'] == -401:
+            if response['code'] in (-352, -401):
                 raise ExtractorError(
-                    'Request is blocked by server (401), please add cookies, wait and try later.', expected=True)
+                    f'Request is blocked by server ({-response["code"]}), '
+                    'please add cookies, wait and try later.', expected=True)
             return response['data']
 
         def get_metadata(page_data):


Test patch: