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

Code before:
            'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)$',
        },
    }]

    def _real_extract(self, url):
        episode_id = self._match_id(url)
        headers = self.geo_verification_headers()
        webpage = self._download_webpage(url, episode_id, headers=headers)

        if '您所在的地区无法观看本片' in webpage:
            raise GeoRestrictedError('This video is restricted')
        elif '正在观看预览，大会员免费看全片' in webpage:
            self.raise_login_required('This video is for premium members only')

        headers['Referer'] = url

        play_info = (
            self._search_json(
                r'playurlSSRData\s*=', webpage, 'embedded page info', episode_id,
                end_pattern='\n', default=None)
            or self._download_json(
                'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id,
                'Extracting episode', query={'fnval': 12240, 'ep_id': episode_id},
                headers=headers))

        geo_blocked = traverse_obj(play_info, ('raw', 'data', 'plugins', lambda _, v: v['name'] == 'AreaLimitPanel', 'config', 'is_block', {bool}, any))
        premium_only = play_info.get('code') == -10403

        video_info = traverse_obj(play_info, (('result', ('raw', 'data')), 'video_info', {dict}, any)) or {}
        formats = self.extract_formats(video_info)

        if not formats:
            if geo_blocked:
                self.raise_geo_restricted()
            elif premium_only or '成为大会员抢先看' in webpage or '开通大会员观看' in webpage:
                self.raise_login_required('This video is for premium members only')

        if traverse_obj(play_info, (
            'result', 'play_check', 'play_detail', {lambda x: x and x == 'PLAY_PREVIEW'}),  # vs 'PLAY_WHOLE'
            ('raw', 'data', 'play_video_type', {lambda x: x and x == 'preview'}),  # vs 'whole'
        ):
            self.report_warning(
                'Only preview format is available, '
                f'you have to become a premium member to access full video. {self._login_hint()}')

        bangumi_info = self._download_json(
            'https://api.bilibili.com/pgc/view/web/season', episode_id, 'Get episode details',
            query={'ep_id': episode_id}, headers=headers)['result']

        episode_number, episode_info = next((
            (idx, ep) for idx, ep in enumerate(traverse_obj(

Review comment (refactor):
line too long
```suggestion
        geo_blocked = traverse_obj(play_info, (
            'raw', 'data', 'plugins', lambda _, v: v['name'] == 'AreaLimitPanel', 'config', 'is_block', {bool}, any))
```

Code after:
            'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)$',
        },
    }]

    def _real_extract(self, url):
        episode_id = self._match_id(url)
        headers = self.geo_verification_headers()
        webpage = self._download_webpage(url, episode_id, headers=headers)

        if '您所在的地区无法观看本片' in webpage:
            raise GeoRestrictedError('This video is restricted')
        elif '正在观看预览，大会员免费看全片' in webpage:
            self.raise_login_required('This video is for premium members only')

        headers['Referer'] = url

        play_info = (
            self._search_json(
                r'playurlSSRData\s*=', webpage, 'embedded page info', episode_id,
                end_pattern='\n', default=None)
            or self._download_json(
                'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id,
                'Extracting episode', query={'fnval': 12240, 'ep_id': episode_id},
                headers=headers))

        geo_blocked = traverse_obj(play_info, (
            'raw', 'data', 'plugins', lambda _, v: v['name'] == 'AreaLimitPanel', 'config', 'is_block', {bool}, any))
        premium_only = play_info.get('code') == -10403

        video_info = traverse_obj(play_info, (('result', ('raw', 'data')), 'video_info', {dict}, any)) or {}
        formats = self.extract_formats(video_info)

        if not formats:
            if geo_blocked:
                self.raise_geo_restricted()
            elif premium_only or '成为大会员抢先看' in webpage or '开通大会员观看' in webpage:
                self.raise_login_required('This video is for premium members only')

        if traverse_obj(play_info, ((
            ('result', 'play_check', 'play_detail'),  # 'PLAY_PREVIEW' vs 'PLAY_WHOLE'
            ('raw', 'data', 'play_video_type'),  # 'preview' vs 'whole'
        ), any, {lambda x: x in ('PLAY_PREVIEW', 'preview')})):
            self.report_warning(
                'Only preview format is available, '
                f'you have to become a premium member to access full video. {self._login_hint()}')

        bangumi_info = self._download_json(
            'https://api.bilibili.com/pgc/view/web/season', episode_id, 'Get episode details',
            query={'ep_id': episode_id}, headers=headers)['result']

        episode_number, episode_info = next((