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

Code before:

        webpage = self._download_webpage(url, video_id)

        window_state_json = self._html_search_regex(
            r'(?s)<script>window\.state\s*[:=]\s(\{.+\})\n(\w+).*(</script>).*',
            webpage, 'WindowState')

        source = self._parse_json(js_to_json(window_state_json), video_id)
        if not source:
            raise ExtractorError('Cannot find source', expected=True)

        config_dict = source['config']
        video_dict = source['entities'][video_id]

        if video_type == 'movie':
            title = self._og_search_title(webpage, fatal=True, default=video_dict['title'])
            stream_urls = self._get_stream_urls(video_dict)
            formats = []
            headers = {'Referer': url}
            for stream_name, stream_url in stream_urls:
                if stream_name == 'dash':
                    format_url = url_or_none(urljoin(config_dict['videoCdnBaseUrl'], stream_url))
                    if not format_url:
                        continue
                    formats.extend(self._extract_mpd_formats(
                        format_url, video_id, mpd_id='dash', headers=headers))
                elif stream_name == 'hls':
                    format_url = url_or_none(urljoin(config_dict['videoCdnBaseUrl'], stream_url))
                    if not format_url:
                        continue
                    formats.extend(self._extract_m3u8_formats(format_url, video_id, fatal=False))
                self._sort_formats(formats)
            info = {
                'id': video_id,
                'title': title,
                'description': video_dict.get('description'),
                'formats': formats
            }

        elif video_type == 'show':
            title = video_dict['title']
            season = video_dict['container']['title']
            series = video_dict['container']['container']['title']
            stream_urls = self._get_stream_urls_shows(video_dict)
            formats = []
            headers = {'Referer': url}
            for stream_name, stream_url in stream_urls:
                if stream_name == 'dash':
                    formats.extend(self._extract_mpd_formats(
                        stream_url, video_id, mpd_id='dash', headers=headers))
                elif stream_name == 'hls':

Review comment (refactor):
```suggestion
                    if format_url:
                        formats.extend(self._extract_mpd_formats(
                            format_url, video_id, mpd_id='dash', headers=headers))
```

may be more readable. Just a suggestion, not a needed change

Code after:

        config_dict = source['config']
        video_dict = source['entities'][video_id]

        thumbnails = []
        for i in video_dict.get('imageInfo') or []:
            thumbnails.append({
                'url': urljoin(config_dict['imageBaseUrl'], i['url']),
                'width': i['width'],
                'height': i['height'],
            })

        formats = []
        get_quality = qualities(['main', 'base', 'high'])
        for stream_type, quality, stream_url in self._get_stream_urls(video_dict):
            format_url = url_or_none(urljoin(config_dict['videoCdnBaseUrl'], stream_url))
            if not format_url:
                continue
            if stream_type == 'dash':
                dash_formats = self._extract_mpd_formats(
                    format_url, video_id, mpd_id='dash-%s' % quality, headers={'Referer': url})
                for frmt in dash_formats:
                    frmt['quality'] = get_quality(quality)
                formats.extend(dash_formats)
            elif stream_type == 'hls':
                formats.extend(self._extract_m3u8_formats(
                    format_url, video_id, fatal=False,
                    m3u8_id='hls-%s' % quality, quality=get_quality(quality)))

        self._sort_formats(formats)
        return {
            'id': video_id,
            'display_id': display_id.replace('/', '-'),
            'title': video_dict['title'] or self._og_search_title(webpage),
            'formats': formats,
            'description': video_dict.get('description'),
            'season': try_get(video_dict, lambda x: x['container']['title']),
            'series': try_get(video_dict, lambda x: x['container']['container']['title']),
            'thumbnails': thumbnails,
        }