1 from __future__ import unicode_literals
5 from .common import InfoExtractor
20 class NPOBaseIE(InfoExtractor):
21 def _get_token(self, video_id):
22 token_page = self._download_webpage(
23 'http://ida.omroep.nl/npoplayer/i.js',
24 video_id, note='Downloading token')
25 token = self._search_regex(
26 r'npoplayer\.token = "(.+?)"', token_page, 'token')
27 # Decryption algorithm extracted from http://npoplayer.omroep.nl/csjs/npoplayer-min.js
30 for i in range(5, len(token_l) - 4):
31 if token_l[i].isdigit():
36 if first is None or second is None:
40 token_l[first], token_l[second] = token_l[second], token_l[first]
42 return ''.join(token_l)
45 class NPOIE(NPOBaseIE):
47 IE_DESC = 'npo.nl and ntr.nl'
52 npo\.nl/(?!live|radio)(?:[^/]+/){2}|
53 ntr\.nl/(?:[^/]+/){2,}|
54 omroepwnl\.nl/video/fragment/[^/]+__
61 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
62 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
64 'id': 'VPWON_1220719',
67 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
68 'upload_date': '20140622',
72 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
73 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
75 'id': 'VARA_101191800',
77 'title': 'De Mega Mike & Mega Thomas show',
78 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
79 'upload_date': '20090227',
84 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
85 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
87 'id': 'VPWON_1169289',
89 'title': 'Tegenlicht',
90 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
91 'upload_date': '20130225',
96 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
98 'id': 'WO_VPRO_043706',
100 'title': 'De nieuwe mens - Deel 1',
101 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
105 # mplayer mms download
106 'skip_download': True,
111 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
112 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
114 'id': 'WO_NOS_762771',
116 'title': 'Hoe gaat Europa verder na Parijs?',
120 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
121 'md5': '01c6a2841675995da1f0cf776f03a9c3',
123 'id': 'VPWON_1233944',
125 'title': 'Aap, poot, pies',
126 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
127 'upload_date': '20150508',
132 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
133 'md5': 'd30cd8417b8b9bca1fdff27428860d08',
135 'id': 'POW_00996502',
137 'title': '''"Dit is wel een 'landslide'..."''',
138 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
139 'upload_date': '20150508',
145 def _real_extract(self, url):
146 video_id = self._match_id(url)
147 return self._get_info(video_id)
149 def _get_info(self, video_id):
150 metadata = self._download_json(
151 'http://e.omroep.nl/metadata/%s' % video_id,
153 # We have to remove the javascript callback
154 transform_source=strip_jsonp,
157 # For some videos actual video id (prid) is different (e.g. for
158 # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
159 # video id is POMS_WNL_853698 but prid is POW_00996502)
160 video_id = metadata.get('prid') or video_id
162 token = self._get_token(video_id)
166 pubopties = metadata.get('pubopties')
168 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
169 for format_id in pubopties:
170 format_info = self._download_json(
171 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
172 % (video_id, format_id, token),
173 video_id, 'Downloading %s JSON' % format_id)
174 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
176 streams = format_info.get('streams')
178 video_info = self._download_json(
179 streams[0] + '&type=json',
180 video_id, 'Downloading %s stream JSON' % format_id)
182 video_info = format_info
183 video_url = video_info.get('url')
186 if format_id == 'adaptive':
187 formats.extend(self._extract_m3u8_formats(video_url, video_id))
191 'format_id': format_id,
192 'quality': quality(format_id),
195 streams = metadata.get('streams')
197 for i, stream in enumerate(streams):
198 stream_url = stream.get('url')
201 if '.asf' not in stream_url:
204 'quality': stream.get('kwaliteit'),
207 asx = self._download_xml(
208 stream_url, video_id,
209 'Downloading stream %d ASX playlist' % i,
210 transform_source=fix_xml_ampersands)
211 ref = asx.find('./ENTRY/Ref')
214 video_url = ref.get('href')
219 'ext': stream.get('formaat', 'asf'),
220 'quality': stream.get('kwaliteit'),
223 self._sort_formats(formats)
226 if metadata.get('tt888') == 'ja':
229 'url': 'http://e.omroep.nl/tt888/%s' % video_id,
234 'title': metadata['titel'],
235 'description': metadata['info'],
236 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
237 'upload_date': unified_strdate(metadata.get('gidsdatum')),
238 'duration': parse_duration(metadata.get('tijdsduur')),
240 'subtitles': subtitles,
244 class NPOLiveIE(NPOBaseIE):
245 IE_NAME = 'npo.nl:live'
246 _VALID_URL = r'https?://(?:www\.)?npo\.nl/live/(?P<id>.+)'
249 'url': 'http://www.npo.nl/live/npo-1',
251 'id': 'LI_NEDERLAND1_136692',
252 'display_id': 'npo-1',
254 'title': 're:^Nederland 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
255 'description': 'Livestream',
259 'skip_download': True,
263 def _real_extract(self, url):
264 display_id = self._match_id(url)
266 webpage = self._download_webpage(url, display_id)
268 live_id = self._search_regex(
269 r'data-prid="([^"]+)"', webpage, 'live id')
271 metadata = self._download_json(
272 'http://e.omroep.nl/metadata/%s' % live_id,
273 display_id, transform_source=strip_jsonp)
275 token = self._get_token(display_id)
279 streams = metadata.get('streams')
281 for stream in streams:
282 stream_type = stream.get('type').lower()
283 # smooth streaming is not supported
284 if stream_type in ['ss', 'ms']:
286 stream_info = self._download_json(
287 'http://ida.omroep.nl/aapi/?stream=%s&token=%s&type=jsonp'
288 % (stream.get('url'), token),
289 display_id, 'Downloading %s JSON' % stream_type)
290 if stream_info.get('error_code', 0) or stream_info.get('errorcode', 0):
292 stream_url = self._download_json(
293 stream_info['stream'], display_id,
294 'Downloading %s URL' % stream_type,
295 'Unable to download %s URL' % stream_type,
296 transform_source=strip_jsonp, fatal=False)
299 if stream_type == 'hds':
300 f4m_formats = self._extract_f4m_formats(stream_url, display_id)
301 # f4m downloader downloads only piece of live stream
302 for f4m_format in f4m_formats:
303 f4m_format['preference'] = -1
304 formats.extend(f4m_formats)
305 elif stream_type == 'hls':
306 formats.extend(self._extract_m3u8_formats(stream_url, display_id, 'mp4'))
313 self._sort_formats(formats)
317 'display_id': display_id,
318 'title': self._live_title(metadata['titel']),
319 'description': metadata['info'],
320 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
326 class NPORadioIE(InfoExtractor):
327 IE_NAME = 'npo.nl:radio'
328 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
331 'url': 'http://www.npo.nl/radio/radio-1',
335 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
339 'skip_download': True,
344 def _html_get_attribute_regex(attribute):
345 return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
347 def _real_extract(self, url):
348 video_id = self._match_id(url)
350 webpage = self._download_webpage(url, video_id)
352 title = self._html_search_regex(
353 self._html_get_attribute_regex('data-channel'), webpage, 'title')
355 stream = self._parse_json(
356 self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
359 codec = stream.get('codec')
363 'url': stream['url'],
364 'title': self._live_title(title),
371 class NPORadioFragmentIE(InfoExtractor):
372 IE_NAME = 'npo.nl:radio:fragment'
373 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
376 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
377 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
381 'title': 'Jubileumconcert Willeke Alberti',
385 def _real_extract(self, url):
386 audio_id = self._match_id(url)
388 webpage = self._download_webpage(url, audio_id)
390 title = self._html_search_regex(
391 r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
394 audio_url = self._search_regex(
395 r"data-streams='([^']+)'", webpage, 'audio url')
404 class TegenlichtVproIE(NPOIE):
405 IE_NAME = 'tegenlicht.vpro.nl'
406 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
410 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
411 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
413 'id': 'VPWON_1169289',
415 'title': 'Tegenlicht',
416 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
417 'upload_date': '20130225',
422 def _real_extract(self, url):
423 name = url_basename(url)
424 webpage = self._download_webpage(url, name)
425 urn = self._html_search_meta('mediaurn', webpage)
426 info_page = self._download_json(
427 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
428 return self._get_info(info_page['mid'])