]>
Commit | Line | Data |
---|---|---|
298a120a AN |
1 | from __future__ import unicode_literals |
2 | ||
061d1cd9 RA |
3 | import re |
4 | ||
298a120a AN |
5 | from .common import InfoExtractor |
6 | ||
7 | ||
8 | class NhkVodIE(InfoExtractor): | |
061d1cd9 RA |
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. | |
0eba178f | 12 | _TESTS = [{ |
0eba178f S |
13 | 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/', |
14 | 'only_matching': True, | |
061d1cd9 RA |
15 | }, { |
16 | 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/', | |
17 | 'only_matching': True, | |
18 | }, { | |
19 | 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/', | |
20 | 'only_matching': True, | |
0eba178f | 21 | }] |
061d1cd9 | 22 | _API_URL_TEMPLATE = 'https://api.nhk.or.jp/nhkworld/%sodesdlist/v7/episode/%s/%s/all%s.json' |
298a120a AN |
23 | |
24 | def _real_extract(self, url): | |
061d1cd9 RA |
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:] | |
f9b373af | 28 | |
061d1cd9 RA |
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'] | |
45396dd2 | 34 | |
061d1cd9 RA |
35 | def get_clean_field(key): |
36 | return episode.get(key + '_clean') or episode.get(key) | |
45396dd2 | 37 | |
061d1cd9 | 38 | series = get_clean_field('title') |
45396dd2 | 39 | |
061d1cd9 RA |
40 | thumbnails = [] |
41 | for s, w, h in [('', 640, 360), ('_l', 1280, 720)]: | |
42 | img_path = episode.get('image' + s) | |
43 | if not img_path: | |
44 | continue | |
45 | thumbnails.append({ | |
46 | 'id': '%dp' % h, | |
47 | 'height': h, | |
48 | 'width': w, | |
49 | 'url': 'https://www3.nhk.or.jp' + img_path, | |
50 | }) | |
298a120a | 51 | |
061d1cd9 RA |
52 | info = { |
53 | 'id': episode_id + '-' + lang, | |
f9b373af | 54 | 'title': '%s - %s' % (series, title) if series and title else title, |
061d1cd9 RA |
55 | 'description': get_clean_field('description'), |
56 | 'thumbnails': thumbnails, | |
f9b373af S |
57 | 'series': series, |
58 | 'episode': title, | |
59 | } | |
061d1cd9 RA |
60 | if is_video: |
61 | info.update({ | |
62 | '_type': 'url_transparent', | |
63 | 'ie_key': 'Ooyala', | |
64 | 'url': 'ooyala:' + episode['vod_id'], | |
65 | }) | |
66 | else: | |
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) | |
47cfa005 RA |
72 | for proto in ('rtmpt', 'rtmp'): |
73 | info['formats'].append({ | |
74 | 'ext': 'flv', | |
75 | 'format_id': proto, | |
76 | 'url': '%s://flv.nhk.or.jp/ondemand/mp4:flv%s' % (proto, audio_path), | |
77 | 'vcodec': 'none', | |
78 | }) | |
061d1cd9 RA |
79 | for f in info['formats']: |
80 | f['language'] = lang | |
81 | return info |