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

Code before:
            'page_count': page_data['pageCount'],
            'page_size': page_data['pageSize'],
            'entry_count': page_data['totalSize'],
            'title': None
        }

    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'])


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 _real_extract(self, url):
        mobj = self._match_valid_url(url)
        mid, sid = mobj.group('mid'), mobj.group('sid')
        id = f'{mid}_{sid}'

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

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

    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', []):

Review comment (suggestion):
```python
mid, sid = self._match_valid_url(url).group('mid', 'sid')
```

Code after:
        'info_dict': {
            'id': '2142762_57445',
            'title': '《底特律 变人》'
        },
        'playlist_mincount': 31,
    }]

    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
        }
    }]