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

Code before:
            'uploader': 'Mimicc',
            'timestamp': 1605580939,
            'upload_date': '20201117',
            'uploader_id': '5156321',
            'thumbnail': 'https://cdn.medal.tv/5156321/thumbnail-36787208-360p.jpg?t=1080p&c=202046&missing',
            'uploader_url': 'https://medal.tv/users/5156321',
            'comment_count': int,
            'view_count': int,
            'like_count': int,
            'duration': 9,
        }
    }, {
        'url': 'https://medal.tv/games/valorant/clips/37rMeFpryCC-9',
        'only_matching': True,
    }, {
        'url': 'https://medal.tv/games/valorant/clips/2WRj40tpY_EU9',
        'only_matching': True,
    }]

    @classmethod
    def _match_path(cls, url):
        return cls._match_valid_url(url).group('path')

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

        webpage = self._download_webpage(url, video_id)

        next_data = self._parse_json(self._search_regex(
            r'<script[^>]*__NEXT_DATA__[^>]*>\s*({.+?})\s*</script>',
            webpage, 'next data', default='{}'), video_id)

        build_id = next_data.get('buildId')
        if not build_id:
            raise ExtractorError(
                'Could not find build ID.', video_id=video_id)

        locale = next_data.get('locale', 'en')

        api_url = 'https://medal.tv/_next/data/{0}/{1}/{2}/{3}.json'.format(build_id, locale, path, video_id)
        api_response = self._download_json(api_url, video_id)

        clip = try_get(api_response, lambda x: x['pageProps']['clip'], dict) or {}
        if not clip:
            raise ExtractorError(
                'Could not find video information.', video_id=video_id)

        title = clip['contentTitle']

        source_width = int_or_none(clip.get('sourceWidth'))

Review comment (refactor):
```suggestion
    def _real_extract(self, url):
        video_id, path = self._match_valid_url(url).group('id', 'path')
```

Code after:
            'uploader': 'Mimicc',
            'timestamp': 1605580939,
            'upload_date': '20201117',
            'uploader_id': '5156321',
            'thumbnail': 'https://cdn.medal.tv/5156321/thumbnail-36787208-360p.jpg?t=1080p&c=202046&missing',
            'uploader_url': 'https://medal.tv/users/5156321',
            'comment_count': int,
            'view_count': int,
            'like_count': int,
            'duration': 9,
        }
    }, {
        'url': 'https://medal.tv/games/valorant/clips/37rMeFpryCC-9',
        'only_matching': True,
    }, {
        'url': 'https://medal.tv/games/valorant/clips/2WRj40tpY_EU9',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        path = self._match_valid_url(url).group('path')

        webpage = self._download_webpage(url, video_id)

        next_data = self._search_json(
            '<script[^>]*__NEXT_DATA__[^>]*>', webpage,
            'next data', video_id, end_pattern='</script>', fatal=False)

        build_id = next_data.get('buildId')
        if not build_id:
            raise ExtractorError(
                'Could not find build ID.', video_id=video_id)

        locale = next_data.get('locale', 'en')

        api_response = self._download_json(
            f'https://medal.tv/_next/data/{build_id}/{locale}/{path}/{video_id}.json', video_id)

        clip = traverse_obj(api_response, ('pageProps', 'clip')) or {}
        if not clip:
            raise ExtractorError(
                'Could not find video information.', video_id=video_id)

        title = clip['contentTitle']

        source_width = int_or_none(clip.get('sourceWidth'))
        source_height = int_or_none(clip.get('sourceHeight'))

        aspect_ratio = source_width / source_height if source_width and source_height else 16 / 9