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

Code before:
        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(
                bangumi_info, (('episodes', ('section', ..., 'episodes')), ..., {dict})), 1)
            if str_or_none(ep.get('id')) == episode_id), (1, {}))

        season_id = bangumi_info.get('season_id')
        season_number, season_title = season_id and next((
            (idx + 1, e.get('season_title')) for idx, e in enumerate(
                traverse_obj(bangumi_info, ('seasons', ...)))
            if e.get('season_id') == season_id
        ), (None, None))

        aid = episode_info.get('aid')

        return {
            'id': episode_id,

Review comment (suggestion):
I *think* the `x and` is unnecessary? But lemme know if it's not
```suggestion
            'result', 'play_check', 'play_detail', {lambda x: x == 'PLAY_PREVIEW'}),  # vs 'PLAY_WHOLE'
            ('raw', 'data', 'play_video_type', {lambda x: x == 'preview'}),  # vs 'whole'
```

Code after:
        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((
            (idx, ep) for idx, ep in enumerate(traverse_obj(
                bangumi_info, (('episodes', ('section', ..., 'episodes')), ..., {dict})), 1)
            if str_or_none(ep.get('id')) == episode_id), (1, {}))

        season_id = bangumi_info.get('season_id')
        season_number, season_title = season_id and next((
            (idx + 1, e.get('season_title')) for idx, e in enumerate(
                traverse_obj(bangumi_info, ('seasons', ...)))
            if e.get('season_id') == season_id
        ), (None, None))

        aid = episode_info.get('aid')

        return {