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

Code before:
        if not self._match_valid_url(urlh.url):
            return self.url_result(urlh.url)

        headers['Referer'] = url

        initial_state = self._search_json(r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', video_id)

        if traverse_obj(initial_state, ('error', 'trueCode')) == -403:
            self.raise_login_required()
        if traverse_obj(initial_state, ('error', 'trueCode')) == -404:
            raise ExtractorError(
                'This video may be deleted or geo-restricted. '
                'You might want to try a VPN or a proxy server (with --proxy)', expected=True)

        is_festival = 'videoData' not in initial_state
        if is_festival:
            video_data = initial_state['videoInfo']
        else:
            video_data = initial_state['videoData']

        if video_data.get('is_upower_exclusive'):
            high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level'))
            support_title = traverse_obj(high_level, 'title', default='')
            support_subtitle = traverse_obj(high_level, 'sub_title', default='')
            raise ExtractorError(
                f'This is a supporter-only video: {support_title}，{support_subtitle}. '
                f'{self._login_hint()}', expected=True)

        video_id, title = video_data['bvid'], video_data.get('title')

        # Bilibili anthologies are similar to playlists but all videos share the same video ID as the anthology itself.
        page_list_json = not is_festival and traverse_obj(
            self._download_json(
                'https://api.bilibili.com/x/player/pagelist', video_id,
                fatal=False, query={'bvid': video_id, 'jsonp': 'jsonp'},
                note='Extracting videos in anthology', headers=headers),
            'data', expected_type=list) or []
        is_anthology = len(page_list_json) > 1

        part_id = int_or_none(parse_qs(url).get('p', [None])[-1])
        if is_anthology and not part_id and self._yes_playlist(video_id, video_id):
            return self.playlist_from_matches(
                page_list_json, video_id, title, ie=BiliBiliIE,
                getter=lambda entry: f'https://www.bilibili.com/video/{video_id}?p={entry["page"]}')

        if is_anthology:
            part_id = part_id or 1
            title += f' p{part_id:02d} {traverse_obj(page_list_json, (part_id - 1, "part")) or ""}'

        aid = video_data.get('aid')
        old_video_id = format_field(aid, None, f'%s_part{part_id or 1}')

Review comment (refactor):
```suggestion
            raise ExtractorError(
                f'{join_nonempty("title", "sub_title", from_dict=high_level, delim="，")}. '
```

Code after:
        if not self._match_valid_url(urlh.url):
            return self.url_result(urlh.url)

        headers['Referer'] = url

        initial_state = self._search_json(r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', video_id)

        if traverse_obj(initial_state, ('error', 'trueCode')) == -403:
            self.raise_login_required()
        if traverse_obj(initial_state, ('error', 'trueCode')) == -404:
            raise ExtractorError(
                'This video may be deleted or geo-restricted. '
                'You might want to try a VPN or a proxy server (with --proxy)', expected=True)

        is_festival = 'videoData' not in initial_state
        if is_festival:
            video_data = initial_state['videoInfo']
        else:
            video_data = initial_state['videoData']

        if video_data.get('is_upower_exclusive'):
            high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level', {dict})) or {}
            raise ExtractorError(
                'This is a supporter-only video: '
                f'{join_nonempty("title", "sub_title", from_dict=high_level, delim="，")}. '
                f'{self._login_hint()}', expected=True)

        video_id, title = video_data['bvid'], video_data.get('title')

        # Bilibili anthologies are similar to playlists but all videos share the same video ID as the anthology itself.
        page_list_json = not is_festival and traverse_obj(
            self._download_json(
                'https://api.bilibili.com/x/player/pagelist', video_id,
                fatal=False, query={'bvid': video_id, 'jsonp': 'jsonp'},
                note='Extracting videos in anthology', headers=headers),
            'data', expected_type=list) or []
        is_anthology = len(page_list_json) > 1

        part_id = int_or_none(parse_qs(url).get('p', [None])[-1])
        if is_anthology and not part_id and self._yes_playlist(video_id, video_id):
            return self.playlist_from_matches(
                page_list_json, video_id, title, ie=BiliBiliIE,
                getter=lambda entry: f'https://www.bilibili.com/video/{video_id}?p={entry["page"]}')

        if is_anthology:
            part_id = part_id or 1
            title += f' p{part_id:02d} {traverse_obj(page_list_json, (part_id - 1, "part")) or ""}'

        aid = video_data.get('aid')
        old_video_id = format_field(aid, None, f'%s_part{part_id or 1}')
        cid = traverse_obj(video_data, ('pages', part_id - 1, 'cid')) if part_id else video_data.get('cid')