Compare commits

...

2 Commits

Author SHA1 Message Date
Snack
4957d59098 [ie/asobichannel] Add better error handling on upcoming live 2023-12-31 18:34:37 +09:00
Snack
e155f88759 [ie/asobichannel] Apply fixes from code review 2023-12-31 18:17:02 +09:00

View File

@ -59,23 +59,23 @@ class AsobiChannelIE(AsobiChannelBaseIE):
}, },
}] }]
def _get_survapi_header(self, video_id): _survapi_header = None
request_token = self._download_json(
'https://asobichannel-api.asobistore.jp/api/v1/vspf/token', video_id, def _real_initialize(self):
token = self._download_json(
'https://asobichannel-api.asobistore.jp/api/v1/vspf/token', None,
note='Retrieving API token') note='Retrieving API token')
return {'Authorization': f'Bearer {request_token}'} self._survapi_header = {'Authorization': f'Bearer {token}'}
def _process_vod(self, video_id, metadata): def _process_vod(self, video_id, metadata):
content_id = metadata['contents']['video_id'] content_id = metadata['contents']['video_id']
vod_data = self._download_json( vod_data = self._download_json(
f'https://survapi.channel.or.jp/proxy/v1/contents/{content_id}/get_by_cuid', video_id, f'https://survapi.channel.or.jp/proxy/v1/contents/{content_id}/get_by_cuid', video_id,
headers=self._get_survapi_header(video_id), note='Downloading vod data') headers=self._survapi_header, note='Downloading vod data')
m3u8_url = vod_data['ex_content']['streaming_url']
return { return {
'formats': self._extract_m3u8_formats(m3u8_url, video_id), 'formats': self._extract_m3u8_formats(vod_data['ex_content']['streaming_url'], video_id),
} }
def _process_live(self, video_id, metadata): def _process_live(self, video_id, metadata):
@ -87,19 +87,20 @@ class AsobiChannelIE(AsobiChannelBaseIE):
if live_start is None: if live_start is None:
live_status = None live_status = None
elif now_ts < live_start: elif now_ts < live_start:
live_status = 'is_upcoming' # live_status should be 'is_upcoming', but stream is not available at this point
self.raise_no_formats(f'Live stream will be available at {live_start}', expected=True)
else: else:
live_status = 'is_live' live_status = 'is_live'
event_data = self._download_json( event_data = self._download_json(
f'https://survapi.channel.or.jp/ex/events/{content_id}?embed=channel', video_id, f'https://survapi.channel.or.jp/ex/events/{content_id}?embed=channel', video_id,
headers=self._get_survapi_header(video_id), note='Downloading event data') headers=self._survapi_header, note='Downloading event data')
live_url = event_data['data']['Channel']['Custom_live_url'] live_url = event_data['data']['Channel']['Custom_live_url']
return { return {
'live_status': live_status, 'live_status': live_status,
'formats': self._extract_m3u8_formats(live_url, video_id), 'formats': self._extract_m3u8_formats(live_url, video_id, live=True),
} }
def _real_extract(self, url): def _real_extract(self, url):
@ -145,7 +146,7 @@ class AsobiChannelTagURLIE(AsobiChannelBaseIE):
tag_id = self._match_id(url) tag_id = self._match_id(url)
webpage = self._download_webpage(url, tag_id) webpage = self._download_webpage(url, tag_id)
webpage_data = self._search_nextjs_data(webpage, tag_id)['props']['pageProps'] title = traverse_obj(self._search_nextjs_data(webpage, tag_id, fatal=False), ('props', 'pageProps', 'data', 'name'))
media_list = self._download_json( media_list = self._download_json(
f'https://channel.microcms.io/api/v1/media?limit=999&filters=(tag[contains]{tag_id})', tag_id, f'https://channel.microcms.io/api/v1/media?limit=999&filters=(tag[contains]{tag_id})', tag_id,
@ -153,8 +154,8 @@ class AsobiChannelTagURLIE(AsobiChannelBaseIE):
entries = [{ entries = [{
'_type': 'url', '_type': 'url',
'url': f'https://asobichannel.asobistore.jp/watch/{metadata['id']}', 'url': f'https://asobichannel.asobistore.jp/watch/{metadata["id"]}',
**self._extract_info(metadata), **self._extract_info(metadata),
} for metadata in media_list.get('contents', [])] } for metadata in media_list.get('contents', [])]
return self.playlist_result(entries, tag_id, traverse_obj(webpage_data, ('data', 'name'))) return self.playlist_result(entries, tag_id, title)