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

Code before:
            data += i['content'] + '\n\n'
        return 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
            sub_data = self._download_json(sub_url, ep_id)
            subtitles.setdefault(sub.get('key', 'en'), []).append({
                'ext': 'srt',
                'data': self.json2srt(sub_data, ep_id)
            })
        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', {})
            video_info = vid.get('stream_info', {})
            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'),
            })


Review comment (suggestion):
keep `or`. It handles cases where the `video_resource` is literally `None`

Code after:
                'data': self.json2srt(sub_data)
            })
        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

    def _extract_ep_info(self, type, episode_data, ep_id):
        return {
            'id': ep_id,
            'title': episode_data.get('long_title') or episode_data['title'],
            'thumbnail': episode_data.get('cover'),
            'episode_number': str_to_int(episode_data.get('title')),
            'formats': self._get_formats(type, ep_id),
            'subtitles': self._get_subtitles(type, ep_id),
            'extractor_key': BiliIntlIE.ie_key(),
        }