Repository: blackjack4494/yt-dlc
File: youtube_dlc/extractor/vlive.py (Python)

Code before:

        if video_type in ('VOD'):
            encoding_status = video_params["encodingStatus"]
            if encoding_status == 'COMPLETE':
                return self._replay(video_id, webpage, long_video_id, key, params)
            else:
                raise ExtractorError('VOD encoding not yet complete. Please try again later.',
                                     expected=True)
        elif video_type in ('LIVE'):
            video_status = video_params["status"]
            if video_status == 'RESERVED':
                raise ExtractorError('Coming soon!', expected=True)
            else:
                return self._live(video_id, webpage, params)
        else:
            raise ExtractorError('Unknown video type %s' % video_type)

    def _get_common_fields(self, webpage, params):
        title = self._og_search_title(webpage)
        description = self._html_search_meta(
            ['og:description', 'description', 'twitter:description'],
            webpage, 'description', default=None)
        creator = (try_get(params, lambda x: x["channel"]["channel"]["channelName"], compat_str)
                   or self._search_regex(r'on (.*) channel', description or '', 'creator', fatal=False))
        thumbnail = self._og_search_thumbnail(webpage)
        return {
            'title': title,
            'creator': creator,
            'thumbnail': thumbnail,
        }

    def _live(self, video_id, webpage, params):
        init_page = self._download_init_page(video_id)

        live_params = self._search_regex(
            r'"liveStreamInfo"\s*:\s*(".*"),',
            init_page, 'live stream info')
        live_params = self._parse_json(live_params, video_id)
        live_params = self._parse_json(live_params, video_id)

        formats = []
        for vid in live_params.get('resolutions', []):
            formats.extend(self._extract_m3u8_formats(
                vid['cdnUrl'], video_id, 'mp4',
                m3u8_id=vid.get('name'),
                fatal=False, live=True))
        self._sort_formats(formats)

        info = self._get_common_fields(webpage, params)
        info.update({
            'title': self._live_title(info['title']),

Review comment (refactor):
```suggestion
            elif video_status == 'ENDED':
                raise ExtractorError('Uploading for replay. Please wait...',
                                     expected=True)
            else:
```

Code after:
                elif error_msg is not None:
                    raise ExtractorError('V LIVE reported the following error: %s' % error_msg)
                else:
                    raise ExtractorError('Failed to extract video parameters.')
            elif 'post' in url:
                raise ExtractorError('Url does not appear to be a video post.', expected=True)
            else:
                raise ExtractorError('Failed to extract video parameters.')

        video_id = working_id if 'video' in url else str(video_params["videoSeq"])

        video_type = video_params["type"]
        if video_type in ('VOD'):
            encoding_status = video_params["encodingStatus"]
            if encoding_status == 'COMPLETE':
                return self._replay(video_id, webpage, params, video_params)
            else:
                raise ExtractorError('VOD encoding not yet complete. Please try again later.',
                                     expected=True)
        elif video_type in ('LIVE'):
            video_status = video_params["status"]
            if video_status in ('RESERVED'):
                raise ExtractorError('Coming soon!', expected=True)
            elif video_status in ('ENDED', 'END'):
                raise ExtractorError('Uploading for replay. Please wait...', expected=True)
            else:
                return self._live(video_id, webpage, params)
        else:
            raise ExtractorError('Unknown video type %s' % video_type)

    def _get_common_fields(self, webpage, params):
        title = self._og_search_title(webpage)
        description = self._html_search_meta(
            ['og:description', 'description', 'twitter:description'],
            webpage, 'description', default=None)
        creator = (try_get(params, lambda x: x["channel"]["channel"]["channelName"], compat_str)
                   or self._search_regex(r'on (.*) channel', description or '', 'creator', fatal=False))
        thumbnail = self._og_search_thumbnail(webpage)
        return {
            'title': title,
            'creator': creator,
            'thumbnail': thumbnail,
        }

    def _live(self, video_id, webpage, params):
        LIVE_INFO_ENDPOINT = 'https://www.vlive.tv/globalv-web/vam-web/old/v3/live/%s/playInfo' % video_id
        play_info = self._download_json(LIVE_INFO_ENDPOINT, video_id,
                                        headers={"referer": "https://www.vlive.tv"})

        streams = try_get(play_info, lambda x: x["result"]["streamList"], list) or []