diff --git a/yt_dlp/extractor/pialive.py b/yt_dlp/extractor/pialive.py index d662f372da..7274bfb2dc 100644 --- a/yt_dlp/extractor/pialive.py +++ b/yt_dlp/extractor/pialive.py @@ -1,7 +1,7 @@ from .common import InfoExtractor from .piaulizaportal import PIAULIZAPortalAPIIE from ..networking import Request -from ..utils import multipart_encode, smuggle_url +from ..utils import ExtractorError, multipart_encode, smuggle_url class PiaLiveIE(InfoExtractor): @@ -9,6 +9,21 @@ class PiaLiveIE(InfoExtractor): PIA_LIVE_API_URL = 'https://api.pia-live.jp' _VALID_URL = r'https?://player\.pia-live\.jp/stream/(?P[\w-]+)' + def handle_embed_player(self, player_tag, video_id, info_dict={}): + player_data_url = self._search_regex([PIAULIZAPortalAPIIE.TAG_REGEX_PATTERN], + player_tag, 'player data url', fatal=False) + + if PIAULIZAPortalAPIIE.BASE_URL in player_data_url: + return self.url_result( + smuggle_url( + player_data_url, + {'video_id': video_id, 'referer': self.PLAYER_ROOT_URL, 'info_dict': info_dict}, + ), + ie=PIAULIZAPortalAPIIE.ie_key(), + ) + + raise ExtractorError('Unsupported streaming platform', expected=True) + def _real_extract(self, url): video_key = self._match_id(url) webpage = self._download_webpage(url, video_key) @@ -38,18 +53,11 @@ class PiaLiveIE(InfoExtractor): program_code, ) - player_data_url = self._search_regex(PIAULIZAPortalAPIIE.SCRIPT_TAG_REGEX_PATTERN, - player_tag_list['data']['movie_one_tag'], 'player data url') - - return { - **self.url_result( - smuggle_url( - player_data_url, - {'video_id': program_code, 'referer': self.PLAYER_ROOT_URL, 'info_dict': { - 'id': program_code, - 'title': self._html_extract_title(webpage), - }}, - ), - ie=PIAULIZAPortalAPIIE.ie_key(), - ), - } + return self.handle_embed_player( + player_tag_list['data']['movie_one_tag'], + video_id=program_code, + info_dict={ + 'id': program_code, + 'title': self._html_extract_title(webpage), + }, + ) diff --git a/yt_dlp/extractor/piaulizaportal.py b/yt_dlp/extractor/piaulizaportal.py index b42f89c4d7..0f23a6a37e 100644 --- a/yt_dlp/extractor/piaulizaportal.py +++ b/yt_dlp/extractor/piaulizaportal.py @@ -4,7 +4,8 @@ from ..utils import ExtractorError, int_or_none, parse_qs, smuggle_url, time_sec class PIAULIZAPortalAPIIE(InfoExtractor): IE_DESC = 'https://player-api.p.uliza.jp - PIA ULIZA m3u8' - SCRIPT_TAG_REGEX_PATTERN = r'