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

Code before:
    _API_URL = 'https://api.bili{}/intl/gateway{}'

    def _call_api(self, type, endpoint, id):
        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')
            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):
```suggestion
            video_info = vid.get('stream_info') or {}
```

Code after:
    _API_URL = 'https://api.bili{}/intl/gateway{}'

    def _call_api(self, type, endpoint, id):
        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'),
            })