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

Code before:
            lambda idx: self._get_entries(self._fetch_page(playlist_id, idx, **kwargs) if idx else first_page, **kwargs),
            metadata['page_count'], metadata['page_size'])
        return metadata, pagedlist

    def _extract_playlist(self, url):
        playlist_id = self._match_id(url)

        metadata, pagedlist = self._extract_internal(playlist_id)

        return self.playlist_result(pagedlist, playlist_id, metadata['title'])


class BilibiliSpaceVideoIE(BilibiliSpaceBaseIE):
    _VALID_URL = r'https?://space\.bilibili\.com/(?P<id>\d+)(?P<video>/video)?$'
    _TESTS = [{
        'url': 'https://space.bilibili.com/3985676/video',
        'info_dict': {
            'id': '3985676',
        },
        'playlist_mincount': 178,
    }]

    def _fetch_page(self, playlist_id, page_idx, **kwargs):
        return self._download_json('https://api.bilibili.com/x/space/arc/search', playlist_id,
                                   note=f'Downloading page {page_idx}',
                                   query={'mid': playlist_id, 'pn': page_idx, 'jsonp': 'jsonp'})['data']

    def _get_metadata(self, page_data, **kwargs):
        page_size = page_data['page']['ps']
        entry_count = page_data['page']['count']
        return {
            'page_count': math.ceil(entry_count / page_size),
            'page_size': page_size,
            'entry_count': entry_count,
            'title': None
        }

    def _get_entries(self, page_data, **kwargs):
        for entry in traverse_obj(page_data, ('list', 'vlist')) or []:
            yield self.url_result(f'https://www.bilibili.com/video/{entry["bvid"]}',
                                  BiliBiliIE.ie_key(), entry['bvid'])

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)
        if not mobj.group('video'):
            self.to_screen(f'{url} may have multiple media types. This run will only download videos.\n'
                           + f'For example, use {url}/audio for audios.')

        return self._extract_playlist(url)



Review comment (suggestion):
```suggestion
        return self._download_json(
            'https://api.bilibili.com/x/space/arc/search', playlist_id, note=f'Downloading page {page_idx}',
            query={'mid': playlist_id, 'pn': page_idx, 'jsonp': 'jsonp'})['data']
```

Code after:
        'playlist_mincount': 178,
    }]

    def _real_extract(self, url):
        playlist_id, is_video_url = self._match_valid_url(url).group('id', 'video')
        if not is_video_url:
            self.to_screen('A channel URL was given. Only the channel\'s videos will be downloaded. '
                           'To download audios, add a "/audio" to the URL')

        def fetch_page(page_idx):
            return self._download_json(
                'https://api.bilibili.com/x/space/arc/search', playlist_id,
                note=f'Downloading page {page_idx}',
                query={'mid': playlist_id, 'pn': page_idx, 'jsonp': 'jsonp'})['data']

        def get_metadata(page_data):
            page_size = page_data['page']['ps']
            entry_count = page_data['page']['count']
            return {
                'page_count': math.ceil(entry_count / page_size),
                'page_size': page_size,
            }

        def get_entries(page_data):
            for entry in traverse_obj(page_data, ('list', 'vlist')) or []:
                yield self.url_result(f'https://www.bilibili.com/video/{entry["bvid"]}', BiliBiliIE, entry['bvid'])

        metadata, paged_list = self._extract_playlist(fetch_page, get_metadata, get_entries)
        return self.playlist_result(paged_list, playlist_id)


class BilibiliSpaceAudioIE(BilibiliSpaceBaseIE):
    _VALID_URL = r'https?://space\.bilibili\.com/(?P<id>\d+)/audio'
    _TESTS = [{
        'url': 'https://space.bilibili.com/3985676/audio',
        'info_dict': {
            'id': '3985676',
        },
        'playlist_mincount': 1,
    }]

    def _real_extract(self, url):
        playlist_id = self._match_id(url)

        def fetch_page(page_idx):
            return self._download_json(
                'https://api.bilibili.com/audio/music-service/web/song/upper', playlist_id,
                note=f'Downloading page {page_idx}',
                query={'uid': playlist_id, 'pn': page_idx, 'ps': 30, 'order': 1, 'jsonp': 'jsonp'})['data']

        def get_metadata(page_data):