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

Code before:
        webpage = self._download_webpage(url, video_id=video_id)
        domain = self.find_value_with_regex(var='requireNewDomain', webpage=webpage)
        vid = self.find_value_with_regex(var='vid', webpage=webpage)
        app_key = self.find_value_with_regex(var='modeServerAppKey', webpage=webpage)
        api = update_url_query(f'{domain}/mod/api/v2/media/{vid}', {'appKey': app_key})
        data = self._download_json(api, video_id=video_id)['data']
        formats, subtitles = [], {}
        for k, v in data.get('resource').items():
            if k in ('dash', 'hls'):
                v_url = v.get('url')
                if not v_url:
                    continue
                fmts, subs = [], {}
                if k == 'dash':
                    fmts, subs = self._extract_mpd_formats_and_subtitles(v_url, video_id=video_id)
                elif k == 'hls':
                    fmts, subs = self._extract_m3u8_formats_and_subtitles(v_url, video_id=video_id)
                formats.extend(fmts)
                subtitles = self._merge_subtitles(subtitles, subs)
            elif k == 'progressive':
                formats.extend([{
                    'url': url_or_none(prog.get('url')),
                    'width': int_or_none(prog.get('width')),
                    'height': int_or_none(prog.get('height')),
                    'ext': 'mp4',
                } for prog in v if prog.get('url')])

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': data.get('title'),
            'description': data.get('description'),
            'duration': int_or_none(data.get('duration')),
            'categories': data.get('categories'),
            'keywords': data.get('keywords'),
            'thumbnail': data.get('cover'),
            'uploader': try_get(data, lambda x: x['owner']['username']),
            'uploader_id': try_get(data, lambda x: x['owner']['id']),
            'formats': formats,
            'subtitles': subtitles,
        }

    def find_value_with_regex(self, var, webpage):
        return self._search_regex(rf'var\s{var}\s=\s\"(?P<vid>[^\"]+)\"', webpage, name=var)


Review comment (suggestion):
```suggestion
                } for prog in v if prog.get('url') or []])
```

Code after:
        webpage = self._download_webpage(url, video_id=video_id)
        domain = self.find_value_with_regex(var='requireNewDomain', webpage=webpage)
        vid = self.find_value_with_regex(var='vid', webpage=webpage)
        app_key = self.find_value_with_regex(var='modeServerAppKey', webpage=webpage)
        api = update_url_query(f'{domain}/mod/api/v2/media/{vid}', {'appKey': app_key})
        data = self._download_json(api, video_id=video_id)['data']
        formats, subtitles = [], {}
        for k, v in data.get('resource').items():
            if k in ('dash', 'hls'):
                v_url = v.get('url')
                if not v_url:
                    continue
                if k == 'dash':
                    fmts, subs = self._extract_mpd_formats_and_subtitles(v_url, video_id=video_id)
                elif k == 'hls':
                    fmts, subs = self._extract_m3u8_formats_and_subtitles(v_url, video_id=video_id)
                formats.extend(fmts)
                subtitles = self._merge_subtitles(subtitles, subs)
            elif k == 'progressive':
                formats.extend([{
                    'url': url_or_none(prog.get('url')),
                    'width': int_or_none(prog.get('width')),
                    'height': int_or_none(prog.get('height')),
                    'ext': 'mp4',
                } for prog in v if prog.get('url') or []])

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': data.get('title'),
            'description': data.get('description'),
            'duration': int_or_none(data.get('duration')),
            'categories': data.get('categories'),
            'keywords': data.get('keywords'),
            'thumbnail': data.get('cover'),
            'uploader': try_get(data, lambda x: x['owner']['username']),
            'uploader_id': try_get(data, lambda x: x['owner']['id']),
            'formats': formats,
            'subtitles': subtitles,
        }

    def find_value_with_regex(self, var, webpage):
        return self._search_regex(rf'var\s{var}\s=\s\"(?P<vid>[^\"]+)\"', webpage, name=var)