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

Code before:
            'view_count': int,
            'like_count': int,
            'dislike_count': int,
            'age_limit': 18,
        }
    }]

    def _real_extract(self, url):
        video_id, host, display_id = self._match_valid_url(url).group('id', 'host', 'display_id')
        group_1 = str(1000 * (int(video_id) // 1000))
        group_2 = str(1000000 * (int(video_id) // 1000000))

        headers = {
            'Referer': url,
            'X-Requested-With': 'XMLHttpRequest',
        }

        video_info = self._download_json(f'https://{host}/api/json/video/86400/{group_2}/{group_1}/{video_id}.json',
                                         video_id, 'Downloading video info', headers=headers)
        if 'error' in video_info:
            raise ExtractorError(f'Txxx said: {video_info["error"]}', expected=True, video_id=video_id)

        video_file = self._download_json(f'https://{host}/api/videofile.php?video_id={video_id}&lifetime=8640000',
                                         video_id, 'Downloading video file info', headers=headers)
        if 'error' in video_file:
            raise ExtractorError(f'Txxx said: {video_file["error"]}', expected=True, video_id=video_id)

        formats = []
        for index, video in enumerate(video_file):
            format_id = self._get_format_id(video.get('format'))
            video_url = self._decode_base64(video.get('video_url'))
            if not video_url:
                continue
            # some hosts only return the path
            if video_url.startswith('/'):
                video_url = urljoin(f'https://{host}', video_url)
            formats.append({
                'url': video_url,
                'format_id': format_id,
                'quality': index,
            })
        self._sort_formats(formats)

        return {
            'id': video_id,
            'display_id': display_id,
            'title': traverse_obj(video_info, ('video', 'title')),
            'uploader': traverse_obj(video_info, ('video', 'user', 'username')),
            'duration': parse_duration(traverse_obj(video_info, ('video', 'duration'))),
            'view_count': int_or_none(traverse_obj(video_info, ('video', 'statistics', 'viewed'))),
            'like_count': int_or_none(traverse_obj(video_info, ('video', 'statistics', 'likes'))),

Review comment (refactor):
Error handling code should be moved to a function like this:
https://github.com/yt-dlp/yt-dlp/blob/c7e4ab278a19e0d4e0eb9626660a4634df964364/yt_dlp/extractor/mildom.py#L19-L36

Code after:
        'md5': '7ff7033340bc88a173198b7c22600e4f',
        'info_dict': {
            'id': '1498858',
            'display_id': 'twistys-malena-morgan-starring-at-dr-morgan-baller',
            'ext': 'mp4',
            'title': 'Twistys - Malena Morgan starring at Dr. Morgan-Baller',
            'uploader': 'mindgeek',
            'duration': 480,
            'view_count': int,
            'like_count': int,
            'dislike_count': int,
            'age_limit': 18,
        }
    }, {
        'url': 'https://vjav.com/videos/11761/yui-hatano-in-if-yui-was-my-girlfriend2/',
        'md5': '6de5bc1f13bdfc3491a77f23edb1676f',
        'info_dict': {
            'id': '11761',
            'display_id': 'yui-hatano-in-if-yui-was-my-girlfriend2',
            'ext': 'mp4',
            'title': 'Yui Hatano in If Yui Was My Girlfriend',
            'uploader': 'Matheus69',
            'duration': 3310,
            'view_count': int,
            'like_count': int,
            'dislike_count': int,
            'age_limit': 18,
        }
    }, {
        'url': 'https://vjav.tube/videos/11761/yui-hatano-in-if-yui-was-my-girlfriend2/',
        'md5': '6de5bc1f13bdfc3491a77f23edb1676f',
        'info_dict': {
            'id': '11761',
            'display_id': 'yui-hatano-in-if-yui-was-my-girlfriend2',
            'ext': 'mp4',
            'title': 'Yui Hatano in If Yui Was My Girlfriend',
            'uploader': 'Matheus69',
            'duration': 3310,
            'view_count': int,
            'like_count': int,
            'dislike_count': int,
            'age_limit': 18,
        }
    }, {
        'url': 'https://voyeurhit.com/videos/332875/charlotte-stokely-elle-alexandra-malena-morgan-lingerie/',
        'md5': '12b4666e9c3e60dafe9182e5d12aae33',
        'info_dict': {
            'id': '332875',
            'display_id': 'charlotte-stokely-elle-alexandra-malena-morgan-lingerie',
            'ext': 'mp4',
            'title': 'Charlotte Stokely, Elle Alexandra, Malena Morgan-Lingerie',