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

Code before:
            'timestamp': 1594432800,
        },
        'params': {
            # m3u8 download
            'skip_download': True,
        },
        'skip': 'Geo-restricted to China',
    }, {
        'url': 'https://www.acfun.cn/bangumi/aa6002917_36188_1745457?ac=2',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)

        has_ac_idx = False
        mobj = re.match(r'(?P<id>aa[_\d]+)(?:\?ac=(?P<ac_idx>\d+))?', video_id)
        if mobj.group('ac_idx'):
            has_ac_idx = True
            video_id = f"{mobj.group('id')}_ac={mobj.group('ac_idx')}"

        webpage = self._download_webpage(url, video_id)
        json_bangumi_data = self._search_json(r'window.bangumiData\s*=\s*', webpage, 'bangumiData', video_id)

        other_info = {}
        if not has_ac_idx:
            video_info = json_bangumi_data['currentVideoInfo']
            title = json_bangumi_data['showTitle']
            season_id = json_bangumi_data.get('bangumiId')
            all_season_list = json_bangumi_data.get('relatedBangumis', [])

            season_number = None
            for e_idx, e in enumerate(all_season_list):
                if e.get('id') == season_id:
                    season_number = e_idx + 1
                    break

            json_bangumi_list = self._search_json(r'window.bangumiList\s*=\s*', webpage, 'bangumiList', video_id) or {}
            video_internal_id = int_or_none(traverse_obj(json_bangumi_data, ('currentVideoInfo', 'id')))
            episode_number = None
            if video_internal_id:
                for e_idx, e in enumerate(json_bangumi_list.get('items', [])):
                    if e.get('videoId') == video_internal_id:
                        episode_number = e_idx + 1
                        break

            other_info.update({
                'thumbnail': json_bangumi_data.get('image'),
                'comment_count': int_or_none(json_bangumi_data.get('commentCount')),
                'season': json_bangumi_data.get('bangumiTitle'),
                'season_id': season_id,

Review comment (suggestion):
can be simplified to:
```py
webpage = ...
json_bangumi_data = ...
ac_id, ac_idx = self._search_regex(...) or (None, None)
if ac_idx:
    ...
else:
    ...
```

Code after:
            'ext': 'mp4',
            'title': '【7月】租借女友 水原千鹤角色曲『DATE』特别PV',
            'upload_date': '20200916',
            'timestamp': 1600243813,
            'duration': 92.091,
        },
    }, {
        'url': 'https://www.acfun.cn/bangumi/aa5023171_36188_1750645',
        'info_dict': {
            'id': 'aa5023171_36188_1750645',
            'ext': 'mp4',
            'title': '红孩儿之趴趴蛙寻石记 第5话 ',
            'duration': 760.0,
            'season': '红孩儿之趴趴蛙寻石记',
            'season_id': 5023171,
            'season_number': 1,  # series has only 1 season
            'episode': 'Episode 5',
            'episode_number': 5,
            'upload_date': '20181223',
            'timestamp': 1545552185,
            'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)',
            'comment_count': int,
        },
    }, {
        'url': 'https://www.acfun.cn/bangumi/aa6065485_36188_1885061',
        'info_dict': {
            'id': 'aa6065485_36188_1885061',
            'ext': 'mp4',
            'title': '叽歪老表（第二季） 第5话 坚不可摧',
            'season': '叽歪老表（第二季）',
            'season_number': 2,
            'season_id': 6065485,
            'episode': '坚不可摧',
            'episode_number': 5,
            'upload_date': '20220324',
            'timestamp': 1648082786,
            'duration': 105.002,
            'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)',
            'comment_count': int,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        ac_idx = parse_qs(url).get('ac', [None])[-1]
        video_id = f'{video_id}{format_field(ac_idx, template="__%s")}'

        webpage = self._download_webpage(url, video_id)
        json_bangumi_data = self._search_json(r'window.bangumiData\s*=\s*', webpage, 'bangumiData', video_id)

        if ac_idx: