From eebc2d6ae10c4d1d57e4aba8f74cf5ad083b76c0 Mon Sep 17 00:00:00 2001 From: ptlydpr Date: Sun, 18 May 2025 21:52:56 +0900 Subject: [PATCH 1/3] [pandatv] Add extractor --- yt_dlp/extractor/_extractors.py | 1 + yt_dlp/extractor/pandatv.py | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 yt_dlp/extractor/pandatv.py diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py index e7dcb9853e..89a8a47b33 100644 --- a/yt_dlp/extractor/_extractors.py +++ b/yt_dlp/extractor/_extractors.py @@ -1490,6 +1490,7 @@ PalcoMP3IE, PalcoMP3VideoIE, ) +from .pandatv import PandatvLiveIE from .panopto import ( PanoptoIE, PanoptoListIE, diff --git a/yt_dlp/extractor/pandatv.py b/yt_dlp/extractor/pandatv.py new file mode 100644 index 0000000000..2ce5ed83a1 --- /dev/null +++ b/yt_dlp/extractor/pandatv.py @@ -0,0 +1,68 @@ +from .common import InfoExtractor +from ..utils import ( + ExtractorError, + UserNotLive, + int_or_none, + traverse_obj, + unified_strdate, + url_or_none, + urlencode_postdata, +) + + +class PandatvLiveIE(InfoExtractor): + _VALID_URL = r'(?Phttps?://(?:www\.|m\.)?pandalive\.co\.kr)/play/(?P[\da-z]+)' + _TESTS = [{ + 'url': 'https://www.pandalive.co.kr/play/bebenim', + 'info_dict': { + 'id': 'bebenim', + 'ext': 'mp4', + 'channel': '릴리ෆ', + 'title': r're:앙앙❤ \d{4}-\d{2}-\d{2} \d{2}:\d{2}', + 'thumbnail': r're:https://cdn\.pandalive\.co\.kr/ivs/v1/.+/thumb.jpg', + 'concurrent_view_count': int, + 'like_count': int, + 'live_status': 'is_live', + 'upload_date': str, + }, + 'skip': 'The channel is not currently live', + }] + + def _real_extract(self, url): + base_url, channel_id = self._match_valid_url(url).groups() + 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}), + }), + } From 1600e083ea242222b5460d98de1f768fc7266df4 Mon Sep 17 00:00:00 2001 From: ptlydpr Date: Thu, 5 Jun 2025 02:25:33 +0900 Subject: [PATCH 2/3] [ie/pandatv] Add extractor --- yt_dlp/extractor/_extractors.py | 2 +- yt_dlp/extractor/pandatv.py | 46 +++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py index 89a8a47b33..0b910c9e6c 100644 --- a/yt_dlp/extractor/_extractors.py +++ b/yt_dlp/extractor/_extractors.py @@ -1490,7 +1490,7 @@ PalcoMP3IE, PalcoMP3VideoIE, ) -from .pandatv import PandatvLiveIE +from .pandatv import PandaTVIE from .panopto import ( PanoptoIE, PanoptoListIE, diff --git a/yt_dlp/extractor/pandatv.py b/yt_dlp/extractor/pandatv.py index 2ce5ed83a1..053b6e2242 100644 --- a/yt_dlp/extractor/pandatv.py +++ b/yt_dlp/extractor/pandatv.py @@ -10,8 +10,8 @@ ) -class PandatvLiveIE(InfoExtractor): - _VALID_URL = r'(?Phttps?://(?:www\.|m\.)?pandalive\.co\.kr)/play/(?P[\da-z]+)' +class PandaTVIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.|m\.)?pandalive\.co\.kr/play/(?P[\da-z]+)' _TESTS = [{ 'url': 'https://www.pandalive.co.kr/play/bebenim', 'info_dict': { @@ -29,33 +29,41 @@ class PandatvLiveIE(InfoExtractor): }] def _real_extract(self, url): - base_url, channel_id = self._match_valid_url(url).groups() - http_headers = {'Origin': base_url} + channel_id = self._match_id(url) + http_headers = {'Origin': 'https://www.pandalive.co.kr'} - # 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)) + 'https://api.pandalive.co.kr/v1/live/play', channel_id, + 'Downloading video meta data', 'Unable to download video meta data', + data=urlencode_postdata({ + 'action': 'watch', + 'userId': channel_id, + 'password': self.get_param('videopassword'), + 'shareLinkType': '', + }), expected_status=400) - # Check video metadata if not video_meta.get('result'): - if traverse_obj(video_meta, ('errorData', 'code')) == 'castEnd': + error_code = traverse_obj(video_meta, ('errorData', 'code', {str})) + if error_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) + 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 == 'wrongPw': + raise ExtractorError('Wrong or no stream password. Use --video-password option.', expected=True) + else: + raise ExtractorError(f'API returned an error code: {error_code}') 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), + video_meta['PlayList']['hls'][0]['url'], channel_id, 'mp4', headers=http_headers, live=True), 'http_headers': http_headers, **traverse_obj(video_meta.get('media'), { 'title': ('title', {str}), From 78a3365c9ae45626e672911fee401469de7d5f0f Mon Sep 17 00:00:00 2001 From: ptlydpr Date: Thu, 5 Jun 2025 02:27:30 +0900 Subject: [PATCH 3/3] [ie/pandatv] Add extractor --- yt_dlp/extractor/pandatv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt_dlp/extractor/pandatv.py b/yt_dlp/extractor/pandatv.py index 053b6e2242..654b311c61 100644 --- a/yt_dlp/extractor/pandatv.py +++ b/yt_dlp/extractor/pandatv.py @@ -55,7 +55,7 @@ def _real_extract(self, url): elif error_code == 'needUnlimitItem': raise ExtractorError('Ticket purchase is required for this stream', expected=True) elif error_code == 'wrongPw': - raise ExtractorError('Wrong or no stream password. Use --video-password option.', expected=True) + raise ExtractorError('Password protected video, use --video-password ', expected=True) else: raise ExtractorError(f'API returned an error code: {error_code}')