1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..utils
import urljoin
9 class NhkBaseIE(InfoExtractor
):
10 _API_URL_TEMPLATE
= 'https://api.nhk.or.jp/nhkworld/%sod%slist/v7a/%s/%s/%s/all%s.json'
11 _BASE_URL_REGEX
= r
'https?://www3\.nhk\.or\.jp/nhkworld/(?P<lang>[a-z]{2})/ondemand'
12 _TYPE_REGEX
= r
'/(?P<type>video|audio)/'
14 def _call_api(self
, m_id
, lang
, is_video
, is_episode
, is_clip
):
15 return self
._download
_json
(
16 self
._API
_URL
_TEMPLATE
% (
17 'v' if is_video
else 'r',
18 'clip' if is_clip
else 'esd',
19 'episode' if is_episode
else 'program',
20 m_id
, lang
, '/all' if is_video
else ''),
21 m_id
, query
={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'}
)['data']['episodes'] or []
23 def _extract_episode_info(self
, url
, episode
=None):
24 fetch_episode
= episode
is None
25 lang
, m_type
, episode_id
= re
.match(NhkVodIE
._VALID
_URL
, url
).groups()
26 if episode_id
.isdigit():
27 episode_id
= episode_id
[:4] + '-' + episode_id
[4:]
29 is_video
= m_type
== 'video'
31 episode
= self
._call
_api
(
32 episode_id
, lang
, is_video
, True, episode_id
[:4] == '9999')[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
,
61 vod_id
= episode
['vod_id']
63 '_type': 'url_transparent',
65 'url': 'https://player.piksel.com/v/refid/nhkworld/prefid/' + vod_id
,
70 audio_path
= episode
['audio']['audio']
71 info
['formats'] = self
._extract
_m
3u8_formats
(
72 'https://nhkworld-vh.akamaihd.net/i%s/master.m3u8' % audio_path
,
73 episode_id
, 'm4a', entry_protocol
='m3u8_native',
74 m3u8_id
='hls', fatal
=False)
75 for f
in info
['formats']:
79 '_type': 'url_transparent',
80 'ie_key': NhkVodIE
.ie_key(),
86 class NhkVodIE(NhkBaseIE
):
87 _VALID_URL
= r
'%s%s(?P<id>\d{7}|[^/]+?-\d{8}-[0-9a-z]+)' % (NhkBaseIE
._BASE
_URL
_REGEX
, NhkBaseIE
._TYPE
_REGEX
)
88 # Content available only for a limited period of time. Visit
89 # https://www3.nhk.or.jp/nhkworld/en/ondemand/ for working samples.
92 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999011/',
93 'md5': '7a90abcfe610ec22a6bfe15bd46b30ca',
97 'title': "Dining with the Chef - Chef Saito's Family recipe: MENCHI-KATSU",
98 'description': 'md5:5aee4a9f9d81c26281862382103b0ea5',
99 'timestamp': 1565965194,
100 'upload_date': '20190816',
104 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/r_inventions-20201104-1/',
106 'id': 'r_inventions-20201104-1-en',
108 'title': "Japan's Top Inventions - Miniature Video Cameras",
109 'description': 'md5:07ea722bdbbb4936fdd360b6a480c25b',
113 'skip_download': True,
116 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
117 'only_matching': True,
119 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/',
120 'only_matching': True,
122 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/',
123 'only_matching': True,
125 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/j_art-20150903-1/',
126 'only_matching': True,
129 def _real_extract(self
, url
):
130 return self
._extract
_episode
_info
(url
)
133 class NhkVodProgramIE(NhkBaseIE
):
134 _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
)
136 # video program episodes
137 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/japanrailway',
139 'id': 'japanrailway',
140 'title': 'Japan Railway Journal',
142 'playlist_mincount': 1,
144 # video program clips
145 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/japanrailway/?type=clip',
147 'id': 'japanrailway',
148 'title': 'Japan Railway Journal',
150 'playlist_mincount': 5,
152 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/10yearshayaomiyazaki/',
153 'only_matching': True,
156 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/audio/listener/',
157 'only_matching': True,
160 def _real_extract(self
, url
):
161 lang
, m_type
, program_id
, episode_type
= re
.match(self
._VALID
_URL
, url
).groups()
163 episodes
= self
._call
_api
(
164 program_id
, lang
, m_type
== 'video', False, episode_type
== 'clip')
167 for episode
in episodes
:
168 episode_path
= episode
.get('url')
171 entries
.append(self
._extract
_episode
_info
(
172 urljoin(url
, episode_path
), episode
))
176 program_title
= entries
[0].get('series')
178 return self
.playlist_result(entries
, program_id
, program_title
)