From 7799e518956387bb3c1064c9beae26eab8d5044a Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Tue, 2 Jul 2024 22:22:52 +0000 Subject: [PATCH] [ie/zaiko] Support JWT video URLs (#10130) Closes #9798 Authored by: pzhlkj6612 --- yt_dlp/extractor/zaiko.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/yt_dlp/extractor/zaiko.py b/yt_dlp/extractor/zaiko.py index c8c4ec0b8..4563b7ba0 100644 --- a/yt_dlp/extractor/zaiko.py +++ b/yt_dlp/extractor/zaiko.py @@ -66,7 +66,9 @@ class ZaikoIE(ZaikoBaseIE): stream_meta['stream-access']['video_source'], video_id, 'Downloading player page', headers={'referer': 'https://zaiko.io/'}) player_meta = self._parse_vue_element_attr('player', player_page, video_id) - status = traverse_obj(player_meta, ('initial_event_info', 'status', {str})) + initial_event_info = traverse_obj(player_meta, ('initial_event_info', {dict})) or {} + + status = traverse_obj(initial_event_info, ('status', {str})) live_status, msg, expected = { 'vod': ('was_live', 'No VOD stream URL was found', False), 'archiving': ('post_live', 'Event VOD is still being processed', True), @@ -80,14 +82,20 @@ class ZaikoIE(ZaikoBaseIE): 'cancelled': ('not_live', 'Event has been cancelled', True), }.get(status) or ('not_live', f'Unknown event status "{status}"', False) - stream_url = traverse_obj(player_meta, ('initial_event_info', 'endpoint', {url_or_none})) + if traverse_obj(initial_event_info, ('is_jwt_protected', {bool})): + stream_url = self._download_json( + initial_event_info['jwt_token_url'], video_id, 'Downloading JWT-protected stream URL', + 'Failed to download JWT-protected stream URL')['playback_url'] + else: + stream_url = traverse_obj(initial_event_info, ('endpoint', {url_or_none})) + formats = self._extract_m3u8_formats( stream_url, video_id, live=True, fatal=False) if stream_url else [] if not formats: self.raise_no_formats(msg, expected=expected) thumbnail_urls = [ - traverse_obj(player_meta, ('initial_event_info', 'poster_url')), + traverse_obj(initial_event_info, ('poster_url', {url_or_none})), self._og_search_thumbnail(self._download_webpage( f'https://zaiko.io/event/{video_id}', video_id, 'Downloading event page', fatal=False) or ''), ] @@ -103,9 +111,7 @@ class ZaikoIE(ZaikoBaseIE): 'release_timestamp': ('stream', 'start', 'timestamp', {int_or_none}), 'categories': ('event', 'genres', ..., {lambda x: x or None}), }), - **traverse_obj(player_meta, ('initial_event_info', { - 'alt_title': ('title', {str}), - })), + 'alt_title': traverse_obj(initial_event_info, ('title', {str})), 'thumbnails': [{'url': url, 'id': url_basename(url)} for url in thumbnail_urls if url_or_none(url)], }