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

Code before:
        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 json2srt(self, json, ep_id):
        def sec2time(sec):
            h = int(sec) // 3600
            m = int(sec) // 60 % 60
            s = sec % 60
            f = int(sec * 1000) % 1000
            return "%02d:%02d:%02d,%03d" % (h, m, int(s), f)
        if json is str:
            json = self._parse_json(json, ep_id)

        data = ''
        for count, i in enumerate(json['body']):
            data += str(count + 1) + '\n'
            data += sec2time(i['from']) + ' --> ' + sec2time(i['to']) + '\n'
            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', {})

Review comment (suggestion):
```suggestion
        data = '\n\n'.join(
            f'{i + 1}\n{srt_subtitles_timecode(line["from"])} --> {srt_subtitles_timecode(line["to"])}\n{line["content"]}'
            for i, line in enumerate(json['body']))
```

u can also replace the fstring with `%`/`format` if u think this is too unwieldy

Code after:
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 json2srt(self, json):
        data = '\n\n'.join(
            f'{i + 1}\n{srt_subtitles_timecode(line["from"])} --> {srt_subtitles_timecode(line["to"])}\n{line["content"]}'
            for i, line in enumerate(json['body']))
        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, fatal=False)
            if not sub_data:
                continue
            sub_data = self._parse_json(sub_data)
            subtitles.setdefault(sub.get('key', 'en'), []).append({
                'ext': 'srt',
                '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'),
            })