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

Code before:
        http_headers = {'Origin': base_url}

        # Prepare POST data
        post_data = {'action': 'watch', 'userId': channel_id, 'password': '', 'shareLinkType': ''}
        post_data_bytes = urlencode_postdata(post_data)

        # Fetch video metadata
        video_meta = self._download_json(
            'https://api.pandalive.co.kr/v1/live/play', channel_id, 'Downloading video meta data',
            errnote=' Unable to download video meta data', data=post_data_bytes, expected_status=(200, 400))

        # Check video metadata
        if not video_meta.get('result'):
            if traverse_obj(video_meta, ('errorData', 'code')) == 'castEnd':
                raise UserNotLive(video_id=channel_id)
            elif traverse_obj(video_meta, ('errorData', 'code')) == 'needAdult':
                raise ExtractorError(
                    'Adult verification is required. Check `--cookies` or `--cookies-from-browser` '
                    'method in https://github.com/yt-dlp/yt-dlp#filesystem-options', expected=True)

        return {
            'id': channel_id,
            'is_live': True,
            'formats': self._extract_m3u8_formats(
                traverse_obj(video_meta, ('PlayList', 'hls', 0, 'url')), channel_id, headers=http_headers,
                ext='mp4', fatal=False, live=True),
            'http_headers': http_headers,
            **traverse_obj(video_meta.get('media'), {
                'title': ('title', {str}),
                'upload_date': ('startTime', {unified_strdate}),
                'thumbnail': ('ivsThumbnail', {url_or_none}),
                'channel': ('userNick', {str}),
                'concurrent_view_count': ('user', {int_or_none}),
                'like_count': ('likeCnt', {int_or_none}),
            }),
        }


Review comment (refactor):
There's no point in making this non-fatal IMO
```suggestion
            'formats': self._extract_m3u8_formats(
                video_meta['PlayList']['hls'][0]['url'], channel_id, 'mp4', headers=http_headers, live=True),
```

Code after:

    def _real_extract(self, url):
        channel_id = self._match_id(url)
        video_meta = self._download_json(
            'https://api.pandalive.co.kr/v1/live/play', channel_id,
            'Downloading video meta data', 'Unable to download video meta data',
            data=urlencode_postdata(filter_dict({
                'action': 'watch',
                'userId': channel_id,
                'password': self.get_param('videopassword'),
            })), expected_status=400)

        if error_code := traverse_obj(video_meta, ('errorData', 'code', {str})):
            if error_code == 'castEnd':
                raise UserNotLive(video_id=channel_id)
            elif error_code == 'needAdult':
                self.raise_login_required('Adult verification is required for this stream')
            elif error_code == 'needLogin':
                self.raise_login_required('Login is required for this stream')
            elif error_code == 'needCoinPurchase':
                raise ExtractorError('Coin purchase is required for this stream', expected=True)
            elif error_code == 'needUnlimitItem':
                raise ExtractorError('Ticket purchase is required for this stream', expected=True)
            elif error_code == 'needPw':
                raise ExtractorError('Password protected video, use --video-password <password>', expected=True)
            elif error_code == 'wrongPw':
                raise ExtractorError('Wrong password', expected=True)
            else:
                error_msg = video_meta.get('message')
                raise ExtractorError(join_nonempty(
                    'API returned error code', error_code,
                    error_msg and 'with error message:', error_msg,
                    delim=' '))

        http_headers = {'Origin': 'https://www.pandalive.co.kr'}

        return {
            'id': channel_id,
            'is_live': True,
            'formats': self._extract_m3u8_formats(
                video_meta['PlayList']['hls'][0]['url'], channel_id, 'mp4', headers=http_headers, live=True),
            'http_headers': http_headers,
            **traverse_obj(video_meta, ('media', {
                'title': ('title', {str}),
                'release_timestamp': ('startTime', {parse_iso8601(delim=' ')}),
                'thumbnail': ('ivsThumbnail', {url_or_none}),
                'channel': ('userNick', {str}),
                'concurrent_view_count': ('user', {int_or_none}),
                'like_count': ('likeCnt', {int_or_none}),
            })),
        }