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

Code before:
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        return self.url_result(
            'http://www.bilibili.tv/video/av%s/' % video_id,
            ie=BiliBiliIE.ie_key(), video_id=video_id)


class BiliIntlBaseIE(InfoExtractor):
    _API_URL = 'https://api.bili{}/intl/gateway'

    def _call_api(self, endpoint, id):
        return self._download_json(self._API_URL + endpoint, id)['data']

    def _extract_formats_and_subtitles(self, ep_id):
        video_json = self._call_api(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['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'),
                })
        for aud in video_json.get('audio_resource', []):
            if aud.get('url'):
                formats.append({
                    'url': aud['url'],
                    'ext': 'mp4',
                    'abr': aud.get('bandwidth'),
                    'acodec': aud.get('codecs'),
                    'vcodec': 'none',
                    'filesize': aud.get('size'),
                })
        sub_json = self._call_api(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:

Review comment (suggestion):
isnt it better to do
```
if not video_res.get('url'):
    continue
formats.append(...)
```

same below

Code after:
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        return self.url_result(
            'http://www.bilibili.tv/video/av%s/' % video_id,
            ie=BiliBiliIE.ie_key(), video_id=video_id)


class BiliIntlBaseIE(InfoExtractor):
    _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'):