1 from __future__ import unicode_literals
3 from .common import InfoExtractor
14 class NPOBaseIE(InfoExtractor):
15 def _get_token(self, video_id):
16 token_page = self._download_webpage(
17 'http://ida.omroep.nl/npoplayer/i.js',
18 video_id, note='Downloading token')
19 token = self._search_regex(
20 r'npoplayer\.token = "(.+?)"', token_page, 'token')
21 # Decryption algorithm extracted from http://npoplayer.omroep.nl/csjs/npoplayer-min.js
24 for i in range(5, len(token_l) - 4):
25 if token_l[i].isdigit():
30 if first is None or second is None:
34 token_l[first], token_l[second] = token_l[second], token_l[first]
36 return ''.join(token_l)
39 class NPOIE(NPOBaseIE):
41 IE_DESC = 'npo.nl and ntr.nl'
42 _VALID_URL = r'https?://(?:www\.)?(?:npo|ntr)\.nl/(?!live|radio)(?:[^/]+/){2,}(?P<id>[^/?#]+)'
46 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
47 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
49 'id': 'VPWON_1220719',
52 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
53 'upload_date': '20140622',
57 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
58 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
60 'id': 'VARA_101191800',
62 'title': 'De Mega Mike & Mega Thomas show',
63 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
64 'upload_date': '20090227',
69 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
70 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
72 'id': 'VPWON_1169289',
74 'title': 'Tegenlicht',
75 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
76 'upload_date': '20130225',
81 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
83 'id': 'WO_VPRO_043706',
85 'title': 'De nieuwe mens - Deel 1',
86 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
90 # mplayer mms download
91 'skip_download': True,
96 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
97 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
99 'id': 'WO_NOS_762771',
101 'title': 'Hoe gaat Europa verder na Parijs?',
105 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
106 'md5': '01c6a2841675995da1f0cf776f03a9c3',
108 'id': 'VPWON_1233944',
110 'title': 'Aap, poot, pies',
111 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
112 'upload_date': '20150508',
118 def _real_extract(self, url):
119 video_id = self._match_id(url)
120 return self._get_info(video_id)
122 def _get_info(self, video_id):
123 metadata = self._download_json(
124 'http://e.omroep.nl/metadata/%s' % video_id,
126 # We have to remove the javascript callback
127 transform_source=strip_jsonp,
130 token = self._get_token(video_id)
134 pubopties = metadata.get('pubopties')
136 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
137 for format_id in pubopties:
138 format_info = self._download_json(
139 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
140 % (video_id, format_id, token),
141 video_id, 'Downloading %s JSON' % format_id)
142 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
144 streams = format_info.get('streams')
146 video_info = self._download_json(
147 streams[0] + '&type=json',
148 video_id, 'Downloading %s stream JSON' % format_id)
150 video_info = format_info
151 video_url = video_info.get('url')
154 if format_id == 'adaptive':
155 formats.extend(self._extract_m3u8_formats(video_url, video_id))
159 'format_id': format_id,
160 'quality': quality(format_id),
163 streams = metadata.get('streams')
165 for i, stream in enumerate(streams):
166 stream_url = stream.get('url')
169 if '.asf' not in stream_url:
172 'quality': stream.get('kwaliteit'),
175 asx = self._download_xml(
176 stream_url, video_id,
177 'Downloading stream %d ASX playlist' % i,
178 transform_source=fix_xml_ampersands)
179 ref = asx.find('./ENTRY/Ref')
182 video_url = ref.get('href')
187 'ext': stream.get('formaat', 'asf'),
188 'quality': stream.get('kwaliteit'),
191 self._sort_formats(formats)
194 if metadata.get('tt888') == 'ja':
197 'url': 'http://e.omroep.nl/tt888/%s' % video_id,
202 'title': metadata['titel'],
203 'description': metadata['info'],
204 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
205 'upload_date': unified_strdate(metadata.get('gidsdatum')),
206 'duration': parse_duration(metadata.get('tijdsduur')),
208 'subtitles': subtitles,
212 class NPOLiveIE(NPOBaseIE):
213 IE_NAME = 'npo.nl:live'
214 _VALID_URL = r'https?://(?:www\.)?npo\.nl/live/(?P<id>.+)'
217 'url': 'http://www.npo.nl/live/npo-1',
219 'id': 'LI_NEDERLAND1_136692',
220 'display_id': 'npo-1',
222 'title': 're:^Nederland 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
223 'description': 'Livestream',
227 'skip_download': True,
231 def _real_extract(self, url):
232 display_id = self._match_id(url)
234 webpage = self._download_webpage(url, display_id)
236 live_id = self._search_regex(
237 r'data-prid="([^"]+)"', webpage, 'live id')
239 metadata = self._download_json(
240 'http://e.omroep.nl/metadata/%s' % live_id,
241 display_id, transform_source=strip_jsonp)
243 token = self._get_token(display_id)
247 streams = metadata.get('streams')
249 for stream in streams:
250 stream_type = stream.get('type').lower()
251 # smooth streaming is not supported
252 if stream_type in ['ss', 'ms']:
254 stream_info = self._download_json(
255 'http://ida.omroep.nl/aapi/?stream=%s&token=%s&type=jsonp'
256 % (stream.get('url'), token),
257 display_id, 'Downloading %s JSON' % stream_type)
258 if stream_info.get('error_code', 0) or stream_info.get('errorcode', 0):
260 stream_url = self._download_json(
261 stream_info['stream'], display_id,
262 'Downloading %s URL' % stream_type,
263 'Unable to download %s URL' % stream_type,
264 transform_source=strip_jsonp, fatal=False)
267 if stream_type == 'hds':
268 f4m_formats = self._extract_f4m_formats(stream_url, display_id)
269 # f4m downloader downloads only piece of live stream
270 for f4m_format in f4m_formats:
271 f4m_format['preference'] = -1
272 formats.extend(f4m_formats)
273 elif stream_type == 'hls':
274 formats.extend(self._extract_m3u8_formats(stream_url, display_id, 'mp4'))
281 self._sort_formats(formats)
285 'display_id': display_id,
286 'title': self._live_title(metadata['titel']),
287 'description': metadata['info'],
288 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
294 class NPORadioIE(InfoExtractor):
295 IE_NAME = 'npo.nl:radio'
296 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
299 'url': 'http://www.npo.nl/radio/radio-1',
303 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
307 'skip_download': True,
312 def _html_get_attribute_regex(attribute):
313 return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
315 def _real_extract(self, url):
316 video_id = self._match_id(url)
318 webpage = self._download_webpage(url, video_id)
320 title = self._html_search_regex(
321 self._html_get_attribute_regex('data-channel'), webpage, 'title')
323 stream = self._parse_json(
324 self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
327 codec = stream.get('codec')
331 'url': stream['url'],
332 'title': self._live_title(title),
339 class NPORadioFragmentIE(InfoExtractor):
340 IE_NAME = 'npo.nl:radio:fragment'
341 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
344 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
345 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
349 'title': 'Jubileumconcert Willeke Alberti',
353 def _real_extract(self, url):
354 audio_id = self._match_id(url)
356 webpage = self._download_webpage(url, audio_id)
358 title = self._html_search_regex(
359 r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
362 audio_url = self._search_regex(
363 r"data-streams='([^']+)'", webpage, 'audio url')
372 class TegenlichtVproIE(NPOIE):
373 IE_NAME = 'tegenlicht.vpro.nl'
374 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
378 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
379 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
381 'id': 'VPWON_1169289',
383 'title': 'Tegenlicht',
384 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
385 'upload_date': '20130225',
390 def _real_extract(self, url):
391 name = url_basename(url)
392 webpage = self._download_webpage(url, name)
393 urn = self._html_search_meta('mediaurn', webpage)
394 info_page = self._download_json(
395 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
396 return self._get_info(info_page['mid'])