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

Code before:
    def _get_entries(self, page_data, **kwargs):
        for entry in page_data.get('data', []):
            yield self.url_result(f'https://www.bilibili.com/audio/au{entry["id"]}',
                                  BilibiliAudioIE.ie_key(), entry['id'])

    def _real_extract(self, url):
        return self._extract_playlist(url)


class BilibiliSpacePlaylistIE(BilibiliSpaceBaseIE):
    _VALID_URL = r'https?://space.bilibili\.com/(?P<mid>\d+)/channel/collectiondetail\?sid=(?P<sid>\d+)'
    _TESTS = [{
        'url': 'https://space.bilibili.com/2142762/channel/collectiondetail?sid=57445',
        'info_dict': {
            'id': '2142762_57445',
            'title': '《底特律 变人》'
        },
        'playlist_mincount': 31,
    }]

    def _fetch_page(self, playlist_id, page_idx, **kwargs):
        mid, sid = kwargs['mid'], kwargs['sid']
        return self._download_json('https://api.bilibili.com/x/polymer/space/seasons_archives_list',
                                   playlist_id, note=f'Downloading page {page_idx}',
                                   query={'mid': mid, 'season_id': sid, 'page_num': page_idx, 'page_size': 30}
                                   )['data']

    def _get_metadata(self, page_data, **kwargs):
        page_size = page_data['page']['page_size']
        entry_count = page_data['page']['total']
        return {
            'page_count': math.ceil(entry_count / page_size),
            'page_size': page_size,
            'entry_count': entry_count,
            'title': traverse_obj(page_data, ('meta', 'name'))
        }

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

    def _real_extract(self, url):
        mid, sid = self._match_valid_url(url).group('mid', 'sid')
        video_id = f'{mid}_{sid}'

        metadata, pagedlist = self._extract_internal(video_id, mid=mid, sid=sid)

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



Review comment (suggestion):
```suggestion
        return self._download_json(
            'https://api.bilibili.com/x/polymer/space/seasons_archives_list',
            playlist_id, note=f'Downloading page {page_idx}',
            query={'mid': mid, 'season_id': sid, 'page_num': page_idx, 'page_size': 30})['data']
```

Code after:

    def _real_extract(self, url):
        mid, sid = self._match_valid_url(url).group('mid', 'sid')
        playlist_id = f'{mid}_{sid}'

        def fetch_page(page_idx):
            return self._download_json(
                'https://api.bilibili.com/x/polymer/space/seasons_archives_list',
                playlist_id, note=f'Downloading page {page_idx}',
                query={'mid': mid, 'season_id': sid, 'page_num': page_idx, 'page_size': 30})['data']

        def get_metadata(page_data):
            page_size = page_data['page']['page_size']
            entry_count = page_data['page']['total']
            return {
                'page_count': math.ceil(entry_count / page_size),
                'page_size': page_size,
                'title': traverse_obj(page_data, ('meta', 'name'))
            }

        def get_entries(page_data):
            for entry in page_data.get('archives', []):
                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, metadata['title'])


class BilibiliCategoryIE(InfoExtractor):
    IE_NAME = 'Bilibili category extractor'
    _MAX_RESULTS = 1000000
    _VALID_URL = r'https?://www\.bilibili\.com/v/[a-zA-Z]+\/[a-zA-Z]+'
    _TESTS = [{
        'url': 'https://www.bilibili.com/v/kichiku/mad',
        'info_dict': {
            'id': 'kichiku: mad',
            'title': 'kichiku: mad'
        },
        'playlist_mincount': 45,
        'params': {
            'playlistend': 45
        }
    }]

    def _fetch_page(self, api_url, num_pages, query, page_num):
        parsed_json = self._download_json(
            api_url, query, query={'Search_key': query, 'pn': page_num},
            note='Extracting results from page %s of %s' % (page_num, num_pages))

        video_list = traverse_obj(parsed_json, ('data', 'archives'), expected_type=list)