feat: add embed player handler

This commit is contained in:
ChocoLZS 2024-08-21 14:55:09 +08:00
parent 9c2a6fa449
commit 0639489bc5
2 changed files with 27 additions and 18 deletions

View File

@ -1,7 +1,7 @@
from .common import InfoExtractor from .common import InfoExtractor
from .piaulizaportal import PIAULIZAPortalAPIIE from .piaulizaportal import PIAULIZAPortalAPIIE
from ..networking import Request from ..networking import Request
from ..utils import multipart_encode, smuggle_url from ..utils import ExtractorError, multipart_encode, smuggle_url
class PiaLiveIE(InfoExtractor): class PiaLiveIE(InfoExtractor):
@ -9,6 +9,21 @@ class PiaLiveIE(InfoExtractor):
PIA_LIVE_API_URL = 'https://api.pia-live.jp' PIA_LIVE_API_URL = 'https://api.pia-live.jp'
_VALID_URL = r'https?://player\.pia-live\.jp/stream/(?P<id>[\w-]+)' _VALID_URL = r'https?://player\.pia-live\.jp/stream/(?P<id>[\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): def _real_extract(self, url):
video_key = self._match_id(url) video_key = self._match_id(url)
webpage = self._download_webpage(url, video_key) webpage = self._download_webpage(url, video_key)
@ -38,18 +53,11 @@ class PiaLiveIE(InfoExtractor):
program_code, program_code,
) )
player_data_url = self._search_regex(PIAULIZAPortalAPIIE.SCRIPT_TAG_REGEX_PATTERN, return self.handle_embed_player(
player_tag_list['data']['movie_one_tag'], 'player data url') player_tag_list['data']['movie_one_tag'],
video_id=program_code,
return { info_dict={
**self.url_result(
smuggle_url(
player_data_url,
{'video_id': program_code, 'referer': self.PLAYER_ROOT_URL, 'info_dict': {
'id': program_code, 'id': program_code,
'title': self._html_extract_title(webpage), 'title': self._html_extract_title(webpage),
}}, },
), )
ie=PIAULIZAPortalAPIIE.ie_key(),
),
}

View File

@ -4,7 +4,8 @@ from ..utils import ExtractorError, int_or_none, parse_qs, smuggle_url, time_sec
class PIAULIZAPortalAPIIE(InfoExtractor): class PIAULIZAPortalAPIIE(InfoExtractor):
IE_DESC = 'https://player-api.p.uliza.jp - PIA ULIZA m3u8' IE_DESC = 'https://player-api.p.uliza.jp - PIA ULIZA m3u8'
SCRIPT_TAG_REGEX_PATTERN = r'<script [^>]*\bsrc="(https://player-api\.p\.uliza\.jp/v1/players/[^"]+)"' BASE_URL = 'https://player-api.p.uliza.jp'
TAG_REGEX_PATTERN = r'<script [^>]*\bsrc="(https://player-api\.p\.uliza\.jp/v1/players/[^"]+)"'
_VALID_URL = r'https://player-api\.p\.uliza\.jp/v1/players/(?P<id>.*)' _VALID_URL = r'https://player-api\.p\.uliza\.jp/v1/players/(?P<id>.*)'
_TESTS = [ _TESTS = [
@ -112,7 +113,7 @@ class PIAULIZAPortalIE(InfoExtractor):
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
player_data_url = self._search_regex( player_data_url = self._search_regex(
PIAULIZAPortalAPIIE.SCRIPT_TAG_REGEX_PATTERN, PIAULIZAPortalAPIIE.TAG_REGEX_PATTERN,
webpage, 'player data url') webpage, 'player data url')
return self.url_result( return self.url_result(
smuggle_url( smuggle_url(