2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..utils import urljoin
10 class NhkBaseIE(InfoExtractor):
11 _API_URL_TEMPLATE = 'https://nwapi.nhk.jp/nhkworld/%sod%slist/v7b/%s/%s/%s/all%s.json'
12 _BASE_URL_REGEX = r'https?://www3\.nhk\.or\.jp/nhkworld/(?P<lang>[a-z]{2})/ondemand'
13 _TYPE_REGEX = r'/(?P<type>video|audio)/'
15 def _call_api(self, m_id, lang, is_video, is_episode, is_clip):
16 return self._download_json(
17 self._API_URL_TEMPLATE % (
18 'v' if is_video else 'r',
19 'clip' if is_clip else 'esd',
20 'episode' if is_episode else 'program',
21 m_id, lang, '/all' if is_video else ''),
22 m_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'] or []
24 def _extract_episode_info(self, url, episode=None):
25 fetch_episode = episode is None
26 lang, m_type, episode_id = re.match(NhkVodIE._VALID_URL, url).groups()
27 if len(episode_id) == 7:
28 episode_id = episode_id[:4] + '-' + episode_id[4:]
30 is_video = m_type == 'video'
32 episode = self._call_api(
33 episode_id, lang, is_video, True, episode_id[:4] == '9999')[0]
34 title = episode.get('sub_title_clean') or episode['sub_title']
36 def get_clean_field(key):
37 return episode.get(key + '_clean') or episode.get(key)
39 series = get_clean_field('title')
42 for s, w, h in [('', 640, 360), ('_l', 1280, 720)]:
43 img_path = episode.get('image' + s)
50 'url': 'https://www3.nhk.or.jp' + img_path,
54 'id': episode_id + '-' + lang,
55 'title': '%s - %s' % (series, title) if series and title else title,
56 'description': get_clean_field('description'),
57 'thumbnails': thumbnails,
62 vod_id = episode['vod_id']
64 '_type': 'url_transparent',
66 'url': 'https://player.piksel.com/v/refid/nhkworld/prefid/' + vod_id,
71 audio_path = episode['audio']['audio']
72 info['formats'] = self._extract_m3u8_formats(
73 'https://nhkworld-vh.akamaihd.net/i%s/master.m3u8' % audio_path,
74 episode_id, 'm4a', entry_protocol='m3u8_native',
75 m3u8_id='hls', fatal=False)
76 for f in info['formats']:
80 '_type': 'url_transparent',
81 'ie_key': NhkVodIE.ie_key(),
87 class NhkVodIE(NhkBaseIE):
88 # the 7-character IDs can have alphabetic chars too: assume [a-z] rather than just [a-f], eg
89 _VALID_URL = r'%s%s(?P<id>[0-9a-z]{7}|[^/]+?-\d{8}-[0-9a-z]+)' % (NhkBaseIE._BASE_URL_REGEX, NhkBaseIE._TYPE_REGEX)
90 # Content available only for a limited period of time. Visit
91 # https://www3.nhk.or.jp/nhkworld/en/ondemand/ for working samples.
94 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999011/',
95 'md5': '7a90abcfe610ec22a6bfe15bd46b30ca',
99 'title': "Dining with the Chef - Chef Saito's Family recipe: MENCHI-KATSU",
100 'description': 'md5:5aee4a9f9d81c26281862382103b0ea5',
101 'timestamp': 1565965194,
102 'upload_date': '20190816',
106 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/r_inventions-20201104-1/',
108 'id': 'r_inventions-20201104-1-en',
110 'title': "Japan's Top Inventions - Miniature Video Cameras",
111 'description': 'md5:07ea722bdbbb4936fdd360b6a480c25b',
115 'skip_download': True,
118 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
119 'only_matching': True,
121 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/',
122 'only_matching': True,
124 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/',
125 'only_matching': True,
127 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/j_art-20150903-1/',
128 'only_matching': True,
130 # video, alphabetic character in ID #29670
131 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999a34/',
132 'only_matching': True,
136 'title': 'DESIGN TALKS plus - Fishermen’s Finery',
137 'description': 'md5:8a8f958aaafb0d7cb59d38de53f1e448',
138 'thumbnail': r're:^https?:/(/[a-z0-9.-]+)+\.jpg\?w=1920&h=1080$',
139 'upload_date': '20210615',
140 'timestamp': 1623722008,
144 def _real_extract(self, url):
145 return self._extract_episode_info(url)
148 class NhkVodProgramIE(NhkBaseIE):
149 _VALID_URL = r'%s/program%s(?P<id>[0-9a-z]+)(?:.+?\btype=(?P<episode_type>clip|(?:radio|tv)Episode))?' % (NhkBaseIE._BASE_URL_REGEX, NhkBaseIE._TYPE_REGEX)
151 # video program episodes
152 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/japanrailway',
154 'id': 'japanrailway',
155 'title': 'Japan Railway Journal',
157 'playlist_mincount': 1,
159 # video program clips
160 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/japanrailway/?type=clip',
162 'id': 'japanrailway',
163 'title': 'Japan Railway Journal',
165 'playlist_mincount': 5,
167 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/10yearshayaomiyazaki/',
168 'only_matching': True,
171 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/audio/listener/',
172 'only_matching': True,
175 def _real_extract(self, url):
176 lang, m_type, program_id, episode_type = re.match(self._VALID_URL, url).groups()
178 episodes = self._call_api(
179 program_id, lang, m_type == 'video', False, episode_type == 'clip')
182 for episode in episodes:
183 episode_path = episode.get('url')
186 entries.append(self._extract_episode_info(
187 urljoin(url, episode_path), episode))
191 program_title = entries[0].get('series')
193 return self.playlist_result(entries, program_id, program_title)