From aa410c803b09832d2fc6a5367acd6fa70f2f3152 Mon Sep 17 00:00:00 2001 From: ChocoLZS <61224208+ChocoLZS@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:13:03 +0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: sepro --- yt_dlp/extractor/pialive.py | 11 ++--------- yt_dlp/extractor/piaulizaportal.py | 16 +++++----------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/yt_dlp/extractor/pialive.py b/yt_dlp/extractor/pialive.py index 9399135b91..4f2ee7d043 100644 --- a/yt_dlp/extractor/pialive.py +++ b/yt_dlp/extractor/pialive.py @@ -43,8 +43,8 @@ class PiaLiveIE(InfoExtractor): def _extract_vars(self, variable, html): return self._search_regex( - rf'(?:var|const)\s+{variable}\s*=\s*(["\'])(?P(?:(?!\1).)+)\1', - html, 'variable', group='value', default=None) + rf'(?:var|const|let)\s+{variable}\s*=\s*(["\'])(?P(?:(?!\1).)+)\1', + html, f'variable {variable}', group='value') def _real_extract(self, url): video_key = self._match_id(url) @@ -53,13 +53,6 @@ class PiaLiveIE(InfoExtractor): program_code = self._extract_vars('programCode', webpage) article_code = self._extract_vars('articleCode', webpage) - prod_configure = self._download_webpage( - self.PLAYER_ROOT_URL + self._search_regex( - r']+src=(["\'])(?P/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({ 'play_url': video_key, 'api_key': self._extract_vars('APIKEY', prod_configure)}) diff --git a/yt_dlp/extractor/piaulizaportal.py b/yt_dlp/extractor/piaulizaportal.py index e8f38f8fc1..7120636981 100644 --- a/yt_dlp/extractor/piaulizaportal.py +++ b/yt_dlp/extractor/piaulizaportal.py @@ -4,9 +4,7 @@ from ..utils.traversal import traverse_obj 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/(?P.*)' + _VALID_URL = r'https://player-api\.p\.uliza\.jp/v1/players/[^?#]+\?(?:[^#]*&)?name=(?P[^#&]+)' _TESTS = [ { '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', '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', @@ -47,15 +41,15 @@ class PIAULIZAPortalAPIIE(InfoExtractor): ] 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( url, tmp_video_id, headers={'Referer': 'https://player-api.p.uliza.jp/'}, note='Fetching player data', errnote='Unable to fetch player data', ) - m3u8_url = self._search_regex( - r'["\'](https://vms-api\.p\.uliza\.jp/v1/prog-index\.m3u8[^"\']+)', player_data, - 'm3u8 url', default=None) + player_data = self._search_json( + r'var\s+params\s*=', player_js, 'json', display_id, + 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)