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

Code before:
        'only_matching': True,
    }]

    @staticmethod
    def parse_format(info):
        vcodec, acodec = None, None

        codec_str = info.get('codecs') or ''
        m = re.match('(?P<vc>[^,]+),(?P<ac>[^,]+)', codec_str)
        if m:
            vcodec = m.group("vc")
            acodec = m.group("ac")

        return {
            'url': info.get('url'),
            'fps': int_or_none(info.get('frameRate')),
            'width': int_or_none(info.get('width')),
            'height': int_or_none(info.get('height')),
            'vcodec': vcodec,
            'acodec': acodec,
            'tbr': float_or_none(info.get('avgBitrate'))
        }

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)
        video_id = mobj.group('id')

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

        video_info = json_all['currentVideoInfo']
        playjson = self._parse_json(video_info['ksPlayJson'], video_id)
        video_inner_id = traverse_obj(json_all, ('currentVideoInfo', 'id'))

        ext = determine_ext(video_info.get('fileName'), 'mp4')

        formats = []
        for video in traverse_obj(playjson, ('adaptationSet', 0, 'representation')):
            fmt = AcFunVideoIE.parse_format(video)
            formats.append({**fmt, 'ext': ext})

        self._sort_formats(formats)

        video_list = json_all['videoList']
        p_idx, video_info = [(idx + 1, v) for (idx, v) in enumerate(video_list)
                             if v['id'] == video_inner_id
                             ][0]

        title = json_all['title']
        if len(video_list) > 1:
            title = f"{title} P{p_idx:02d} {video_info['title']}"

Review comment (suggestion):
i think the `mobj` is unnecessary as the url will be get checked first, you can group `video_id` directly here

Code after:
        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            'duration': float_or_none(video_info.get('durationMillis'), 1000),
            'timestamp': int_or_none(video_info.get('uploadTime'), 1000),
            'http_headers': {'Referer': 'https://www.acfun.cn/'},
        }


class AcFunVideoIE(AcFunVideoBaseIE):
    _VALID_URL = r'https?://www\.acfun\.cn/v/ac(?P<id>[_\d]+)'

    _TESTS = [{
        'url': 'https://www.acfun.cn/v/ac35457073',
        'info_dict': {
            'id': '35457073',
            'ext': 'mp4',
            'duration': 174.208,
            'timestamp': 1656403967,
            'title': '1 8 岁 现 状',
            'description': '“赶紧回去！班主任查班了！”',
            'uploader': '锤子game',
            'uploader_id': '51246077',
            'thumbnail': r're:^https?://.*\.(jpg|jpeg)',
            'upload_date': '20220628',
            'like_count': int,
            'view_count': int,
            'comment_count': int,
            'tags': list,
        },
    }, {
        # example for len(video_list) > 1
        'url': 'https://www.acfun.cn/v/ac35468952_2',
        'info_dict': {
            'id': '35468952_2',
            'ext': 'mp4',
            'title': '【动画剧集】Rocket & Groot Season 1（2022）/火箭浣熊与格鲁特第1季 P02 S01E02 十拿九穩',
            'duration': 90.459,
            'uploader': '比令',
            'uploader_id': '37259967',
            'upload_date': '20220629',
            'timestamp': 1656479962,
            'tags': list,
            'like_count': int,
            'view_count': int,
            'comment_count': int,
            'thumbnail': r're:^https?://.*\.(jpg|jpeg)',
            'description': 'md5:67583aaf3a0f933bd606bc8a2d3ebb17',
        }
    }]