1 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..utils
import urljoin
8 class NhkBaseIE(InfoExtractor
):
9 _API_URL_TEMPLATE
= 'https://api.nhk.or.jp/nhkworld/%sod%slist/v7a/%s/%s/%s/all%s.json'
10 _BASE_URL_REGEX
= r
'https?://www3\.nhk\.or\.jp/nhkworld/(?P<lang>[a-z]{2})/ondemand'
11 _TYPE_REGEX
= r
'/(?P<type>video|audio)/'
13 def _call_api(self
, m_id
, lang
, is_video
, is_episode
, is_clip
):
14 return self
._download
_json
(
15 self
._API
_URL
_TEMPLATE
% (
16 'v' if is_video
else 'r',
17 'clip' if is_clip
else 'esd',
18 'episode' if is_episode
else 'program',
19 m_id
, lang
, '/all' if is_video
else ''),
20 m_id
, query
={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'}
)['data']['episodes'] or []
22 def _extract_episode_info(self
, url
, episode
=None):
23 fetch_episode
= episode
is None
24 lang
, m_type
, episode_id
= NhkVodIE
._match
_valid
_url
(url
).groups()
25 if episode_id
.isdigit():
26 episode_id
= episode_id
[:4] + '-' + episode_id
[4:]
28 is_video
= m_type
== 'video'
30 episode
= self
._call
_api
(
31 episode_id
, lang
, is_video
, True, episode_id
[:4] == '9999')[0]
32 title
= episode
.get('sub_title_clean') or episode
['sub_title']
34 def get_clean_field(key
):
35 return episode
.get(key
+ '_clean') or episode
.get(key
)
37 series
= get_clean_field('title')
40 for s
, w
, h
in [('', 640, 360), ('_l', 1280, 720)]:
41 img_path
= episode
.get('image' + s
)
48 'url': 'https://www3.nhk.or.jp' + img_path
,
52 'id': episode_id
+ '-' + lang
,
53 'title': '%s - %s' % (series
, title
) if series
and title
else title
,
54 'description': get_clean_field('description'),
55 'thumbnails': thumbnails
,
60 vod_id
= episode
['vod_id']
62 '_type': 'url_transparent',
64 'url': 'https://player.piksel.com/v/refid/nhkworld/prefid/' + vod_id
,
69 audio_path
= episode
['audio']['audio']
70 info
['formats'] = self
._extract
_m
3u8_formats
(
71 'https://nhkworld-vh.akamaihd.net/i%s/master.m3u8' % audio_path
,
72 episode_id
, 'm4a', entry_protocol
='m3u8_native',
73 m3u8_id
='hls', fatal
=False)
74 for f
in info
['formats']:
78 '_type': 'url_transparent',
79 'ie_key': NhkVodIE
.ie_key(),
85 class NhkVodIE(NhkBaseIE
):
86 _VALID_URL
= r
'%s%s(?P<id>\d{7}|[^/]+?-\d{8}-[0-9a-z]+)' % (NhkBaseIE
._BASE
_URL
_REGEX
, NhkBaseIE
._TYPE
_REGEX
)
87 # Content available only for a limited period of time. Visit
88 # https://www3.nhk.or.jp/nhkworld/en/ondemand/ for working samples.
91 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999011/',
92 'md5': '7a90abcfe610ec22a6bfe15bd46b30ca',
96 'title': "Dining with the Chef - Chef Saito's Family recipe: MENCHI-KATSU",
97 'description': 'md5:5aee4a9f9d81c26281862382103b0ea5',
98 'timestamp': 1565965194,
99 'upload_date': '20190816',
103 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/r_inventions-20201104-1/',
105 'id': 'r_inventions-20201104-1-en',
107 'title': "Japan's Top Inventions - Miniature Video Cameras",
108 'description': 'md5:07ea722bdbbb4936fdd360b6a480c25b',
112 'skip_download': True,
115 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
116 'only_matching': True,
118 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/',
119 'only_matching': True,
121 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/',
122 'only_matching': True,
124 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/j_art-20150903-1/',
125 'only_matching': True,
128 def _real_extract(self
, url
):
129 return self
._extract
_episode
_info
(url
)
132 class NhkVodProgramIE(NhkBaseIE
):
133 _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
)
135 # video program episodes
136 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/japanrailway',
138 'id': 'japanrailway',
139 'title': 'Japan Railway Journal',
141 'playlist_mincount': 1,
143 # video program clips
144 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/japanrailway/?type=clip',
146 'id': 'japanrailway',
147 'title': 'Japan Railway Journal',
149 'playlist_mincount': 5,
151 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/video/10yearshayaomiyazaki/',
152 'only_matching': True,
155 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/program/audio/listener/',
156 'only_matching': True,
159 def _real_extract(self
, url
):
160 lang
, m_type
, program_id
, episode_type
= self
._match
_valid
_url
(url
).groups()
162 episodes
= self
._call
_api
(
163 program_id
, lang
, m_type
== 'video', False, episode_type
== 'clip')
166 for episode
in episodes
:
167 episode_path
= episode
.get('url')
170 entries
.append(self
._extract
_episode
_info
(
171 urljoin(url
, episode_path
), episode
))
175 program_title
= entries
[0].get('series')
177 return self
.playlist_result(entries
, program_id
, program_title
)