mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-14 03:11:24 +01:00
Compare commits
No commits in common. "a4cc7524401bc23a3acf54b699b6f71cb1857c04" and "8c9dee3f6093296c9ff5e85b7040bfc0169d0ab1" have entirely different histories.
a4cc752440
...
8c9dee3f60
|
@ -28,43 +28,30 @@ class NhkBaseIE(InfoExtractor):
|
||||||
m_id, lang, '/all' if is_video else ''),
|
m_id, lang, '/all' if is_video else ''),
|
||||||
m_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'] or []
|
m_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'] or []
|
||||||
|
|
||||||
def _get_api_info(self, refresh=True):
|
def _extract_vod_api(self):
|
||||||
if not refresh:
|
|
||||||
return self.cache.load('nhk', 'api_info')
|
|
||||||
|
|
||||||
self.cache.store('nhk', 'api_info', {})
|
|
||||||
movie_player_js = self._download_webpage(
|
movie_player_js = self._download_webpage(
|
||||||
'https://movie-a.nhk.or.jp/world/player/js/movie-player.js', None,
|
'https://movie-a.nhk.or.jp/world/player/js/movie-player.js', None,
|
||||||
note='Downloading stream API information')
|
note='Downloading stream API information')
|
||||||
api_info = {
|
api_url = self._search_regex(
|
||||||
'url': self._search_regex(
|
r'prod:[^;]+apiUrl:\s*[\'"]([^\'"]+)[\'"]', movie_player_js, None, 'stream API url')
|
||||||
r'prod:[^;]+\bapiUrl:\s*[\'"]([^\'"]+)[\'"]', movie_player_js, None, 'stream API url'),
|
api_token = self._search_regex(
|
||||||
'token': self._search_regex(
|
r'prod:[^;]+token:\s*[\'"]([^\'"]+)[\'"]', movie_player_js, None, 'stream API token')
|
||||||
r'prod:[^;]+\btoken:\s*[\'"]([^\'"]+)[\'"]', movie_player_js, None, 'stream API token'),
|
self.cache.store('nhkworld', 'vod_api', {'url': api_url, 'token': api_token})
|
||||||
}
|
return api_url, api_token
|
||||||
self.cache.store('nhk', 'api_info', api_info)
|
|
||||||
return api_info
|
|
||||||
|
|
||||||
def _extract_formats_and_subtitles(self, vod_id):
|
def _load_vod_api(self):
|
||||||
for refresh in (False, True):
|
cachedata = self.cache.load('nhkworld', 'vod_api')
|
||||||
api_info = self._get_api_info(refresh)
|
if cachedata is not None and url_or_none(cachedata.get('url')) is not None:
|
||||||
if not api_info:
|
return cachedata['url'], cachedata.get('token')
|
||||||
continue
|
return self._extract_vod_api()
|
||||||
|
|
||||||
api_url = api_info.pop('url')
|
def _extract_stream_info(self, api_url, api_token, vod_id):
|
||||||
stream_url = traverse_obj(
|
return self._download_json(api_url, vod_id, query={
|
||||||
self._download_json(
|
'token': api_token,
|
||||||
api_url, vod_id, 'Downloading stream url info', fatal=False, query={
|
'type': 'json',
|
||||||
**api_info,
|
'optional_id': vod_id,
|
||||||
'type': 'json',
|
'active_flg': 1,
|
||||||
'optional_id': vod_id,
|
}, note='Downloading stream information')
|
||||||
'active_flg': 1,
|
|
||||||
}),
|
|
||||||
('meta', 0, 'movie_url', ('mb_auto', 'auto_sp', 'auto_pc'), {url_or_none}), get_all=False)
|
|
||||||
if stream_url:
|
|
||||||
return self._extract_m3u8_formats_and_subtitles(stream_url, vod_id)
|
|
||||||
|
|
||||||
raise ExtractorError('Unable to extract stream url')
|
|
||||||
|
|
||||||
def _extract_episode_info(self, url, episode=None):
|
def _extract_episode_info(self, url, episode=None):
|
||||||
fetch_episode = episode is None
|
fetch_episode = episode is None
|
||||||
|
@ -105,7 +92,16 @@ class NhkBaseIE(InfoExtractor):
|
||||||
}
|
}
|
||||||
if is_video:
|
if is_video:
|
||||||
vod_id = episode['vod_id']
|
vod_id = episode['vod_id']
|
||||||
formats, subs = self._extract_formats_and_subtitles(vod_id)
|
api_url, api_token = self._load_vod_api()
|
||||||
|
streams_json = self._extract_stream_info(api_url, api_token, vod_id)
|
||||||
|
if streams_json.get('response_status') != '2000':
|
||||||
|
self.to_screen('Getting stream information failed, trying again with fresh API details')
|
||||||
|
api_url, api_token = self._extract_vod_api()
|
||||||
|
streams_json = self._extract_stream_info(api_url, api_token, vod_id)
|
||||||
|
|
||||||
|
stream_url = traverse_obj(streams_json, (
|
||||||
|
'meta', 0, 'movie_url', ('mb_auto', 'auto_sp', 'auto_pc'), {url_or_none}), get_all=False)
|
||||||
|
formats, subs = self._extract_m3u8_formats_and_subtitles(stream_url, vod_id)
|
||||||
|
|
||||||
info.update({
|
info.update({
|
||||||
'id': vod_id,
|
'id': vod_id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user