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

Code before:
        'url': 'https://www.huya.com/video/play/556054543.html',
        'info_dict': {
            'id': '556054543',
            'title': '我不挑事 也不怕事',
            'thumbnail': r're:https://.*\.jpg*',
            'format_id': '1080P',
            'url': r're:https?://.*\.mp4*',
            'ext': 'mp4',
            'width': 1920,
            'height': 1080,
            'filesize': 368724330,
            'protocol': 'http',
            'format_note': '1080P - 1920x1080',
            'duration': 1864,
            'uploader': '卡尔',
            'uploader_id': '367138632',
            'upload_date': '20210811',
            'view_count': int,
            'comment_count': int,
            'like_count': int,
        }, 'params': {
            'skip_download': True,
        },
    }]

    def _real_extract(self, url: str) -> dict:
        video_id = self._match_id(url)
        api_url = f'https://liveapi.huya.com/moment/getMomentContent?videoId={video_id}'

        try:
            response = self._download_json(api_url, video_id)
        except Exception as e:
            raise ExtractorError(f'Failed to download JSON data: {e}', expected=True)

        video_data = traverse_obj(response, ('data', 'moment', 'videoInfo'))

        if not isinstance(video_data, dict):
            raise ExtractorError('No video data found')

        formats = []
        for definition in video_data.get('definitions', []):
            format_info = {
                'format_id': definition.get('defName'),
                'url': definition.get('url'),
                'ext': determine_ext(definition.get('url', '')),
                'width': int_or_none(definition.get('width')),
                'height': int_or_none(definition.get('height')),
                'filesize': int_or_none(definition.get('size')),
                'protocol': 'http',  # Assuming HTTP protocol
                'format_note': f'{definition.get("defName", "")} - {definition.get("width", "")}x{definition.get("height", "")}',
            }

Review comment (refactor):
Since none of the other extractors use type hints, we should keep this consistent
```suggestion
    def _real_extract(self, url):
```

Code after:
            'view_count': int,
            'comment_count': int,
            'like_count': int,
        },
    }]

    def _real_extract(self, url: str):
        video_id = self._match_id(url)
        video_data = self._download_json(
            'https://liveapi.huya.com/moment/getMomentContent', video_id,
            query={'videoId': video_id})['data']['moment']['videoInfo']

        formats = []
        for definition in traverse_obj(video_data, ('definitions', lambda _, v: url_or_none(v['url']))):
            formats.append({
                'url': definition['url'],
                **traverse_obj(definition, {
                    'format_id': ('defName', {str}),
                    'width': ('width', {int_or_none}),
                    'height': ('height', {int_or_none}),
                    'filesize': ('size', {int_or_none}),
                }),
            })

        return {
            'id': video_id,
            'formats': formats,
            **traverse_obj(video_data, {
                'title': ('videoTitle', {str}),
                'thumbnail': ('videoCover', {url_or_none}),
                'duration': ('videoDuration', {parse_duration}),
                'uploader': ('nickName', {str}),
                'uploader_id': ('uid', {str_or_none}),
                'upload_date': ('videoUploadTime', {unified_strdate}),
                'view_count': ('videoPlayNum', {int_or_none}),
                'comment_count': ('videoCommentNum', {int_or_none}),
                'like_count': ('favorCount', {int_or_none}),
            }),
        }