Apply suggestions from code review

Co-authored-by: sepro <sepro@sepr0.com>
This commit is contained in:
ChocoLZS 2024-09-09 21:13:03 +08:00 committed by GitHub
parent 83f4c5a98e
commit aa410c803b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 20 deletions

View File

@ -43,8 +43,8 @@ class PiaLiveIE(InfoExtractor):
def _extract_vars(self, variable, html): def _extract_vars(self, variable, html):
return self._search_regex( return self._search_regex(
rf'(?:var|const)\s+{variable}\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1', rf'(?:var|const|let)\s+{variable}\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
html, 'variable', group='value', default=None) html, f'variable {variable}', group='value')
def _real_extract(self, url): def _real_extract(self, url):
video_key = self._match_id(url) video_key = self._match_id(url)
@ -53,13 +53,6 @@ class PiaLiveIE(InfoExtractor):
program_code = self._extract_vars('programCode', webpage) program_code = self._extract_vars('programCode', webpage)
article_code = self._extract_vars('articleCode', webpage) article_code = self._extract_vars('articleCode', webpage)
prod_configure = self._download_webpage(
self.PLAYER_ROOT_URL + self._search_regex(
r'<script[^>]+src=(["\'])(?P<url>/statics/js/s_prod\?(?:(?!\1).)+)\1',
webpage, 'prod configure page url', group='url'),
program_code, headers={'Referer': self.PLAYER_ROOT_URL},
note='Fetching prod configure page', errnote='Unable to fetch prod configure page')
payload, content_type = multipart_encode({ payload, content_type = multipart_encode({
'play_url': video_key, 'play_url': video_key,
'api_key': self._extract_vars('APIKEY', prod_configure)}) 'api_key': self._extract_vars('APIKEY', prod_configure)})

View File

@ -4,9 +4,7 @@ from ..utils.traversal import traverse_obj
class PIAULIZAPortalAPIIE(InfoExtractor): class PIAULIZAPortalAPIIE(InfoExtractor):
IE_DESC = 'https://player-api.p.uliza.jp - PIA ULIZA m3u8' _VALID_URL = r'https://player-api\.p\.uliza\.jp/v1/players/[^?#]+\?(?:[^#]*&)?name=(?P<id>[^#&]+)'
_VALID_URL = r'https://player-api\.p\.uliza\.jp/v1/players/(?P<id>.*)'
_TESTS = [ _TESTS = [
{ {
'url': 'https://player-api.p.uliza.jp/v1/players/timeshift-disabled/pia/admin?type=normal&playerobjectname=ulizaPlayer&name=livestream01_dvr&repeatable=true', 'url': 'https://player-api.p.uliza.jp/v1/players/timeshift-disabled/pia/admin?type=normal&playerobjectname=ulizaPlayer&name=livestream01_dvr&repeatable=true',
@ -15,10 +13,6 @@ class PIAULIZAPortalAPIIE(InfoExtractor):
'title': '88f3109a-f503-4d0f-a9f7-9f39ac745d84', 'title': '88f3109a-f503-4d0f-a9f7-9f39ac745d84',
'live_status': 'was_live', 'live_status': 'was_live',
}, },
'params': {
'skip_download': True,
'ignore_no_formats_error': True,
},
}, },
{ {
'url': 'https://player-api.p.uliza.jp/v1/players/uliza_jp_gallery_normal/promotion/admin?type=presentation&name=cookings&targetid=player1', 'url': 'https://player-api.p.uliza.jp/v1/players/uliza_jp_gallery_normal/promotion/admin?type=presentation&name=cookings&targetid=player1',
@ -47,15 +41,15 @@ class PIAULIZAPortalAPIIE(InfoExtractor):
] ]
def _real_extract(self, url): def _real_extract(self, url):
tmp_video_id = self._search_regex(r'&name=([^&]+)', self._match_id(url), 'video id', default='unknown') display_id = self._match_id(url)
player_data = self._download_webpage( player_data = self._download_webpage(
url, tmp_video_id, headers={'Referer': 'https://player-api.p.uliza.jp/'}, url, tmp_video_id, headers={'Referer': 'https://player-api.p.uliza.jp/'},
note='Fetching player data', errnote='Unable to fetch player data', note='Fetching player data', errnote='Unable to fetch player data',
) )
m3u8_url = self._search_regex( player_data = self._search_json(
r'["\'](https://vms-api\.p\.uliza\.jp/v1/prog-index\.m3u8[^"\']+)', player_data, r'var\s+params\s*=', player_js, 'json', display_id,
'm3u8 url', default=None) transform_source=js_to_json)
video_id = self._search_regex(r'&?ss=([\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})&?', m3u8_url, 'video id', default=tmp_video_id) video_id = self._search_regex(r'&?ss=([\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})&?', m3u8_url, 'video id', default=tmp_video_id)