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

Code before:
        'info_dict': {
            'id': '341736',
            'ext': 'mp4',
            'title': 'The First Night',
            'thumbnail': 'https://i0.hdslb.com/bfs/intl/management/91e30e5521235d9b163339a26a0b030ebda54310.png',
            'episode_number': 2,
        },
        'params': {
            'format': 'bv',
        },
    }, {
        'url': 'https://www.biliintl.com/en/play/34613/341736',
        'info_dict': {
            'id': '341736',
            'ext': 'mp4',
            'title': 'The First Night',
            'thumbnail': 'https://i0.hdslb.com/bfs/intl/management/91e30e5521235d9b163339a26a0b030ebda54310.png',
            'episode_number': 2,
        },
        'params': {
            'format': 'bv',
        },
    }]

    def _real_extract(self, url):
        type, season_id, id = re.match(self._VALID_URL, url).groups()
        api_url = f'https://api.bili{type}/intl/gateway'
        data_json = self._download_json(f'{api_url}/web/view/ogv_collection?season_id={season_id}', id)['data']
        for episode in data_json.get('episodes', []):
            if str(episode.get('ep_id')) == id:
                episode_data = episode
                break
        video_json = self._download_json(f'{api_url}/web/playurl?ep_id={id}&platform=web', id)['data']
        if not video_json:
            self.raise_login_required(method='cookies')
        video_json = video_json['playurl']
        formats = []
        for vid in video_json.get('video', []):
            video_res = vid['video_resource']
            video_info = vid['stream_info']
            if video_res.get('url'):
                formats.append({
                    'url': video_res['url'],
                    'ext': 'mp4',
                    'format_note': video_info.get('desc_words'),
                    'width': video_res.get('width'),
                    'height': video_res.get('height'),
                    'vbr': video_res.get('bandwidth'),
                    'acodec': 'none',
                    'vcodec': video_res.get('codecs'),
                    'filesize': video_res.get('size'),

Review comment (suggestion):
```suggestion
        type, season_id, id = self._match_valid_url(url).groups()
```

Code after:
        return self._download_json(self._API_URL.format(type, endpoint), id)['data']

    def _get_subtitles(self, type, ep_id):
        sub_json = self._call_api(type, f'/m/subtitle?ep_id={ep_id}&platform=web', ep_id)
        subtitles = {}
        for sub in sub_json.get('subtitles', []):
            sub_url = sub.get('url')
            if not sub_url:
                continue
            subtitles.setdefault(sub.get('key', 'en'), []).append({
                'url': sub_url,
            })
        return subtitles

    def _get_formats(self, type, ep_id):
        video_json = self._call_api(type, f'/web/playurl?ep_id={ep_id}&platform=web', ep_id)
        if not video_json:
            self.raise_login_required(method='cookies')
        video_json = video_json['playurl']
        formats = []
        for vid in video_json.get('video', []):
            video_res = vid.get('video_resource') or {}
            video_info = vid.get('stream_info') or {}
            if not video_res.get('url'):
                continue
            formats.append({
                'url': video_res['url'],
                'ext': 'mp4',
                'format_note': video_info.get('desc_words'),
                'width': video_res.get('width'),
                'height': video_res.get('height'),
                'vbr': video_res.get('bandwidth'),
                'acodec': 'none',
                'vcodec': video_res.get('codecs'),
                'filesize': video_res.get('size'),
            })
        for aud in video_json.get('audio_resource', []):
            if not aud.get('url'):
                continue
            formats.append({
                'url': aud['url'],
                'ext': 'mp4',
                'abr': aud.get('bandwidth'),
                'acodec': aud.get('codecs'),
                'vcodec': 'none',
                'filesize': aud.get('size'),
            })

        self._sort_formats(formats)
        return formats