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

Code before:
            '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 = self._match_valid_url(url).groups()
        self._API_URL = self._API_URL.format(type)
        data_json = self._call_api(f'/web/view/ogv_collection?season_id={season_id}', id)
        for episode in data_json.get('episodes', []):
            if str(episode.get('ep_id')) == id:
                episode_data = episode
                break
        return self._extract_ep_info(episode_data, id)


class BiliIntlSeriesIE(BiliIntlBaseIE):
    _VALID_URL = r'https?://(?:www\.)?bili(?P<type>bili\.tv|intl.com)/(?:[a-z]{2}/)?play/(?P<id>\d+)$'
    _TESTS = [{
        'url': 'https://www.bilibili.tv/en/play/34613',
        'playlist_mincount': 15,
        'info_dict': {
            'id': '34613',
        },
        'params': {
            'skip_download': True,
            'format': 'bv',
        },
    }, {
        'url': 'https://www.biliintl.com/en/play/34613',
        'playlist_mincount': 15,
        'info_dict': {
            'id': '34613',

Review comment (bug):
why r u saving it back to `self._API_URL`? This will break if you give 2 urls at once. Just pass `type` or the url to `_call_api`

Code after:

class BiliIntlIE(BiliIntlBaseIE):
    _VALID_URL = r'https?://(?:www\.)?bili(?P<type>bili\.tv|intl.com)/(?:[a-z]{2}/)?play/(?P<season_id>\d+)/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.bilibili.tv/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',
        },
    }, {
        '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 = self._match_valid_url(url).groups()
        data_json = self._call_api(type, f'/web/view/ogv_collection?season_id={season_id}', id)
        episode_data = next(
            episode for episode in data_json.get('episodes', [])
            if str(episode.get('ep_id')) == id)
        return self._extract_ep_info(type, episode_data, id)


class BiliIntlSeriesIE(BiliIntlBaseIE):
    _VALID_URL = r'https?://(?:www\.)?bili(?P<type>bili\.tv|intl.com)/(?:[a-z]{2}/)?play/(?P<id>\d+)$'
    _TESTS = [{
        'url': 'https://www.bilibili.tv/en/play/34613',
        'playlist_mincount': 15,
        'info_dict': {
            'id': '34613',
        },
        'params': {
            'skip_download': True,
            'format': 'bv',
        },
    }, {