]>
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): | |
fcaf4d7a | 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+)' |
061d1cd9 RA |
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 = [{ |
21d3c21e S |
13 | # clip |
14 | 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999011/', | |
15 | 'md5': '256a1be14f48d960a7e61e2532d95ec3', | |
16 | 'info_dict': { | |
17 | 'id': 'a95j5iza', | |
18 | 'ext': 'mp4', | |
19 | 'title': "Dining with the Chef - Chef Saito's Family recipe: MENCHI-KATSU", | |
20 | 'description': 'md5:5aee4a9f9d81c26281862382103b0ea5', | |
21 | 'timestamp': 1565965194, | |
22 | 'upload_date': '20190816', | |
23 | }, | |
24 | }, { | |
0eba178f S |
25 | 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/', |
26 | 'only_matching': True, | |
061d1cd9 RA |
27 | }, { |
28 | 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/', | |
29 | 'only_matching': True, | |
30 | }, { | |
31 | 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/', | |
32 | 'only_matching': True, | |
fcaf4d7a S |
33 | }, { |
34 | 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/j_art-20150903-1/', | |
35 | 'only_matching': True, | |
0eba178f | 36 | }] |
0ec9d4e5 | 37 | _API_URL_TEMPLATE = 'https://api.nhk.or.jp/nhkworld/%sod%slist/v7a/episode/%s/%s/all%s.json' |
298a120a AN |
38 | |
39 | def _real_extract(self, url): | |
061d1cd9 RA |
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:] | |
f9b373af | 43 | |
061d1cd9 RA |
44 | is_video = m_type == 'video' |
45 | episode = self._download_json( | |
21d3c21e S |
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 ''), | |
061d1cd9 RA |
50 | episode_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'][0] |
51 | title = episode.get('sub_title_clean') or episode['sub_title'] | |
45396dd2 | 52 | |
061d1cd9 RA |
53 | def get_clean_field(key): |
54 | return episode.get(key + '_clean') or episode.get(key) | |
45396dd2 | 55 | |
061d1cd9 | 56 | series = get_clean_field('title') |
45396dd2 | 57 | |
061d1cd9 RA |
58 | thumbnails = [] |
59 | for s, w, h in [('', 640, 360), ('_l', 1280, 720)]: | |
60 | img_path = episode.get('image' + s) | |
61 | if not img_path: | |
62 | continue | |
63 | thumbnails.append({ | |
64 | 'id': '%dp' % h, | |
65 | 'height': h, | |
66 | 'width': w, | |
67 | 'url': 'https://www3.nhk.or.jp' + img_path, | |
68 | }) | |
298a120a | 69 | |
061d1cd9 RA |
70 | info = { |
71 | 'id': episode_id + '-' + lang, | |
f9b373af | 72 | 'title': '%s - %s' % (series, title) if series and title else title, |
061d1cd9 RA |
73 | 'description': get_clean_field('description'), |
74 | 'thumbnails': thumbnails, | |
f9b373af S |
75 | 'series': series, |
76 | 'episode': title, | |
77 | } | |
061d1cd9 RA |
78 | if is_video: |
79 | info.update({ | |
80 | '_type': 'url_transparent', | |
a373befa RA |
81 | 'ie_key': 'Piksel', |
82 | 'url': 'https://player.piksel.com/v/refid/nhkworld/prefid/' + episode['vod_id'], | |
061d1cd9 RA |
83 | }) |
84 | else: | |
85 | audio = episode['audio'] | |
86 | audio_path = audio['audio'] | |
87 | info['formats'] = self._extract_m3u8_formats( | |
541fe3ea S |
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) | |
061d1cd9 RA |
91 | for f in info['formats']: |
92 | f['language'] = lang | |
93 | return info |