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

Code before:
        srcUID = wvplayer_props.get('srcUID')
        srcVID = wvplayer_props.get('srcVID')
        srcNAME = wvplayer_props.get('srcNAME')
        resolutions = [res for res in wvplayer_props.get('resolutions') if res > 0]
        formats = []
        for res in resolutions:
            format_id = str(-(res // -2) - 1)
            formats.append({
                'acodec': 'mp4a.40.2',
                'ext': 'mp4',
                'format_id': format_id,
                'resolution': resolution_map.get(res),
                'url': f'https://www.wevidi.net/videoplayback/{srcVID}/{srcUID}/{srcNAME}/{format_id}',
                'vcodec': 'avc1.42E01E',
            })

        return formats

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        title = get_element_by_class('video_title', webpage)
        wvplayer_props = json.loads(js_to_json(self._search_regex(
            r'WVPlayer\(({.+?)autoplay', webpage,
            'wvplayer_props', flags=re.DOTALL) + '}'))

        return {
            'id': video_id,
            'title': title,
            'description': clean_html(get_element_by_class('descr_long', webpage)),
            'uploader': get_element_by_class('username', webpage),
            'formats': self._extract_formats(wvplayer_props),
            'thumbnail': self._og_search_thumbnail(webpage),
            'duration': float_or_none(wvplayer_props.get('duration')),
        }


Review comment (suggestion):
Better to use `_search_json`, though it's almost as brittle:
```suggestion
        wvplayer_props = self._search_json(
            r'WVPlayer\(', webpage, 'player', video_id,
            transform_source=lambda x: js_to_json(x.replace('autoplay', '}')))
```
&nbsp;
`js_to_json` doesn't handle `||` operators, which is why we need to stop parsing before the `autoplay` var. So it might be better to do this, in case the `autoplay` definition isn't always the first to use `||`:
```suggestion
        wvplayer_props = self._search_json(
            r'WVPlayer\(', webpage, 'player', video_id,
            transform_source=lambda x: js_to_json(x.replace('||', '}')))
```
&nbsp;
for reference, webpage source:
```html
<script>
				var playerUserSettings = {};
				
				var player = $("#wvplayer").WVPlayer({
					srcUID: "ej49OpUc7hI",
					srcVID: "wJnRqDHNe_u",
					srcNAME: "vR3ubbEpUDB",
					thumbNAME: "LchSkadeBN9",
					stripNAME: "SpcjGwh9eVF",
					strips: 100,
					duration: 630.451,
					resolutions: [2, 4, 6],
					autoplay: playerUserSettings.autoplay || false,
					controls: playerUserSettings.controls || false,
					resolution: playerUserSettings.resolution || 6,
					onexpand: function(exp) {
```

Code after:
        # Taken from WeVidi player JS: https://wevidi.net/layouts/default/static/player.min.js
        resolution_map = {
            1: 144,
            2: 240,
            3: 360,
            4: 480,
            5: 720,
            6: 1080
        }

        src_path = f'{wvplayer_props["srcVID"]}/{wvplayer_props["srcUID"]}/{wvplayer_props["srcNAME"]}'
        for res in traverse_obj(wvplayer_props, ('resolutions', ..., {int}, {lambda x: x or None})):
            format_id = str(-(res // -2) - 1)
            yield {
                'acodec': 'mp4a.40.2',
                'ext': 'mp4',
                'format_id': format_id,
                'height': resolution_map.get(res),
                'url': f'https://www.wevidi.net/videoplayback/{src_path}/{format_id}',
                'vcodec': 'avc1.42E01E',
            }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        wvplayer_props = self._search_json(
            r'WVPlayer\(', webpage, 'player', video_id,
            transform_source=lambda x: js_to_json(x.replace('||', '}')))

        return {
            'id': video_id,
            'title': clean_html(get_element_by_class('video_title', webpage)),
            'description': clean_html(get_element_by_class('descr_long', webpage)),
            'uploader': clean_html(get_element_by_class('username', webpage)),
            'formats': list(self._extract_formats(wvplayer_props)),
            'thumbnail': self._og_search_thumbnail(webpage),
            'duration': float_or_none(wvplayer_props.get('duration')),
        }