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

Code before:
        },
        'params': {
            'skip_download': True,
        }

    }]

    def _get_best_stream_url(self, stream):
        best_stream = list(filter(None, [v for k, v in stream.items()]))
        return best_stream.pop(0) if len(best_stream) else None

    def _get_stream_urls_shows(self, video_dict):
        stream_dict = video_dict.get('stream', {'provider': {}})
        stream_provider = stream_dict.get('provider')
        stream_provider_dict = stream_dict.get(stream_provider)
        if not stream_dict[stream_provider]:
            message = 'No stream provider found'
            raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)

        streams = []
        if stream_provider_dict['dashUrl']:
            streams.append(('dash', stream_provider_dict['dashUrl']))
        if stream_provider_dict['hlsUrl']:
            streams.append(('hls', stream_provider_dict['hlsUrl']))
        return streams

    def _get_stream_urls(self, video_dict):
        stream_dict = video_dict.get('stream', {'provider': {}})
        stream_provider = stream_dict.get('provider')

        if not stream_dict[stream_provider]:
            message = 'No stream provider found'
            raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)

        streams = []
        for stream_name, v in stream_dict[stream_provider].items():
            if stream_name in VALID_STREAMS:
                stream_url = self._get_best_stream_url(v)
                if stream_url is None:
                    continue
                streams.append((stream_name, stream_url))
        return streams

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        video_slug = mobj.group('slug')
        video_type = mobj.group('type').split('/')[0]
        video_id = video_slug.split('-')[-1]

        webpage = self._download_webpage(url, video_id)


Review comment (suggestion):
A lot of code reused from `_get_stream_urls`. Generalize into a single function

Code after:
        'params': {
            'skip_download': True,
        }
    }, {
        'url': 'https://www.mxplayer.in/show/watch-aashram/chapter-1/duh-swapna-online-d445579792b0135598ba1bc9088a84cb',
        'info_dict': {
            'id': 'd445579792b0135598ba1bc9088a84cb',
            'ext': 'mp4',
            'title': 'Duh Swapna',
            'description': 'md5:35ff39c4bdac403c53be1e16a04192d8',
            'season': 'Chapter 1',
            'series': 'Aashram'
        },
        'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
        'params': {
            'skip_download': True,
            'format': 'bestvideo'
        }
    }]

    def _get_stream_urls(self, video_dict):
        stream_provider_dict = try_get(
            video_dict,
            lambda x: x['stream'][x['stream']['provider']])
        if not stream_provider_dict:
            raise ExtractorError('No stream provider found', expected=True)

        for stream_name, stream in stream_provider_dict.items():
            if stream_name in ('hls', 'dash', 'hlsUrl', 'dashUrl'):
                stream_type = stream_name.replace('Url', '')
                if isinstance(stream, dict):
                    for quality, stream_url in stream.items():
                        if stream_url:
                            yield stream_type, quality, stream_url
                else:
                    yield stream_type, 'base', stream

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

        source = self._parse_json(
            js_to_json(self._html_search_regex(
                r'(?s)<script>window\.state\s*[:=]\s(\{.+\})\n(\w+).*(</script>).*',
                webpage, 'WindowState')),
            video_id)
        if not source:
            raise ExtractorError('Cannot find source', expected=True)

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