1 from __future__ import unicode_literals
5 from .common import InfoExtractor
8 class NhkVodIE(InfoExtractor):
9 _VALID_URL = r'https?://www3\.nhk\.or\.jp/nhkworld/(?P<lang>[a-z]{2})/ondemand/(?P<type>video|audio)/(?P<id>\d{7}|[a-z]+-\d{8}-\d+)'
10 # Content available only for a limited period of time. Visit
11 # https://www3.nhk.or.jp/nhkworld/en/ondemand/ for working samples.
13 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
14 'only_matching': True,
16 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/',
17 'only_matching': True,
19 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/',
20 'only_matching': True,
22 _API_URL_TEMPLATE = 'https://api.nhk.or.jp/nhkworld/%sodesdlist/v7/episode/%s/%s/all%s.json'
24 def _real_extract(self, url):
25 lang, m_type, episode_id = re.match(self._VALID_URL, url).groups()
26 if episode_id.isdigit():
27 episode_id = episode_id[:4] + '-' + episode_id[4:]
29 is_video = m_type == 'video'
30 episode = self._download_json(
31 self._API_URL_TEMPLATE % ('v' if is_video else 'r', episode_id, lang, '/all' if is_video else ''),
32 episode_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'][0]
33 title = episode.get('sub_title_clean') or episode['sub_title']
35 def get_clean_field(key):
36 return episode.get(key + '_clean') or episode.get(key)
38 series = get_clean_field('title')
41 for s, w, h in [('', 640, 360), ('_l', 1280, 720)]:
42 img_path = episode.get('image' + s)
49 'url': 'https://www3.nhk.or.jp' + img_path,
53 'id': episode_id + '-' + lang,
54 'title': '%s - %s' % (series, title) if series and title else title,
55 'description': get_clean_field('description'),
56 'thumbnails': thumbnails,
62 '_type': 'url_transparent',
64 'url': 'ooyala:' + episode['vod_id'],
67 audio = episode['audio']
68 audio_path = audio['audio']
69 info['formats'] = self._extract_m3u8_formats(
70 'https://nhks-vh.akamaihd.net/i%s/master.m3u8' % audio_path,
71 episode_id, 'm4a', m3u8_id='hls', fatal=False)
72 for proto in ('rtmpt', 'rtmp'):
73 info['formats'].append({
76 'url': '%s://flv.nhk.or.jp/ondemand/mp4:flv%s' % (proto, audio_path),
79 for f in info['formats']: