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}|[^/]+?-\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.
14 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999011/',
15 'md5': '256a1be14f48d960a7e61e2532d95ec3',
19 'title': "Dining with the Chef - Chef Saito's Family recipe: MENCHI-KATSU",
20 'description': 'md5:5aee4a9f9d81c26281862382103b0ea5',
21 'timestamp': 1565965194,
22 'upload_date': '20190816',
25 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
26 'only_matching': True,
28 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/',
29 'only_matching': True,
31 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/',
32 'only_matching': True,
34 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/j_art-20150903-1/',
35 'only_matching': True,
37 _API_URL_TEMPLATE = 'https://api.nhk.or.jp/nhkworld/%sod%slist/v7a/episode/%s/%s/all%s.json'
39 def _real_extract(self, url):
40 lang, m_type, episode_id = re.match(self._VALID_URL, url).groups()
41 if episode_id.isdigit():
42 episode_id = episode_id[:4] + '-' + episode_id[4:]
44 is_video = m_type == 'video'
45 episode = self._download_json(
46 self._API_URL_TEMPLATE % (
47 'v' if is_video else 'r',
48 'clip' if episode_id[:4] == '9999' else 'esd',
49 episode_id, lang, '/all' if is_video else ''),
50 episode_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'][0]
51 title = episode.get('sub_title_clean') or episode['sub_title']
53 def get_clean_field(key):
54 return episode.get(key + '_clean') or episode.get(key)
56 series = get_clean_field('title')
59 for s, w, h in [('', 640, 360), ('_l', 1280, 720)]:
60 img_path = episode.get('image' + s)
67 'url': 'https://www3.nhk.or.jp' + img_path,
71 'id': episode_id + '-' + lang,
72 'title': '%s - %s' % (series, title) if series and title else title,
73 'description': get_clean_field('description'),
74 'thumbnails': thumbnails,
80 '_type': 'url_transparent',
82 'url': 'https://player.piksel.com/v/refid/nhkworld/prefid/' + episode['vod_id'],
85 audio = episode['audio']
86 audio_path = audio['audio']
87 info['formats'] = self._extract_m3u8_formats(
88 'https://nhkworld-vh.akamaihd.net/i%s/master.m3u8' % audio_path,
89 episode_id, 'm4a', entry_protocol='m3u8_native',
90 m3u8_id='hls', fatal=False)
91 for f in info['formats']: