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

Code before:
            if v.get('bandwidth'):
                format.update({'tbr': v['bandwidth'] / 1000})
                if v.get('duration'):
                    format.update({'filesize_approx': v['bandwidth'] * v['duration'] / 8000})
            if v.get('codec'):
                format.update(parse_codecs(v['codec']))
            if v.get('resolution'):
                format.update({'width': v['resolution'][0], 'height': v['resolution'][1]})

            formats.append(format)
        return formats

    def extract_formats(self, spl_url, play_list):
        formats = []

        if play_list.get('http_stream') and play_list['http_stream'].get('qualities'):
            formats.extend(self._extract(None, spl_url, play_list['http_stream']['qualities']))

        if play_list.get('mp4'):
            formats.extend(self._extract('mp4', spl_url, play_list['mp4']))

        self._sort_formats(formats)
        return formats

    def _real_extract(self, url):
        display_id, video_id = re.match(self._VALID_URL, url).groups()

        data = self._download_json(
            self._GRAPHQL_URL, video_id, 'Downloading GraphQL result',
            data=json.dumps({
                'query': self._GRAPHQL_QUERY,
                'variables': {'urlName': video_id}
            }).encode('utf-8'),
            headers={'Content-Type': 'application/json;charset=UTF-8'}
        )['data']

        spl_url = data['episode']['spl'] + 'spl2,3'
        metadata = self._download_json(spl_url, video_id, 'Downloading playlist')
        if 'Location' in metadata and 'data' not in metadata:
            # they sometimes wants to redirect
            spl_url = metadata['Location']
            metadata = self._download_json(spl_url, video_id, 'Redirected -> Downloading playlist')
        play_list = metadata['data']

        return {
            'id': video_id,
            'display_id': display_id,
            'title': data['episode'].get('name'),
            'description': data['episode'].get('perex'),
            'subtitles': self.extract_subtitles(spl_url, play_list.get('subtitles')),
            'formats': self.extract_formats(spl_url, play_list)

Review comment (suggestion):
```suggestion
        display_id, video_id = self._match_valid_url(url).groups()
```

Code after:
                    }'''
            }).encode('utf-8'),
            headers={'Content-Type': 'application/json;charset=UTF-8'}
        )['data']['episode']

        spl_url = data['spl'] + 'spl2,3'
        metadata = self._download_json(spl_url, video_id, 'Downloading playlist')
        if 'Location' in metadata and 'data' not in metadata:
            spl_url = metadata['Location']
            metadata = self._download_json(spl_url, video_id, 'Downloading redirected playlist')
        video = metadata['data']

        subtitles = {}
        for subs in video.get('subtitles', {}).values():
            if not subs.get('language'):
                continue
            for ext, sub_url in subs.get('urls').items():
                subtitles.setdefault(subs['language'], []).append({
                    'ext': ext,
                    'url': urljoin(spl_url, sub_url)
                })

        formats = list(self._extract_formats(spl_url, video))
        self._sort_formats(formats)

        return {
            'id': video_id,
            'display_id': display_id,
            'title': data.get('name'),
            'description': data.get('perex'),
            'duration': float_or_none(data.get('duration')),
            'view_count': int_or_none(data.get('views')),
            'formats': formats,
            'subtitles': subtitles,
        }