1 from __future__ import unicode_literals
5 from .common import InfoExtractor
16 class NPOBaseIE(InfoExtractor):
17 def _get_token(self, video_id):
18 token_page = self._download_webpage(
19 'http://ida.omroep.nl/npoplayer/i.js',
20 video_id, note='Downloading token')
21 token = self._search_regex(
22 r'npoplayer\.token = "(.+?)"', token_page, 'token')
23 # Decryption algorithm extracted from http://npoplayer.omroep.nl/csjs/npoplayer-min.js
26 for i in range(5, len(token_l) - 4):
27 if token_l[i].isdigit():
32 if first is None or second is None:
36 token_l[first], token_l[second] = token_l[second], token_l[first]
38 return ''.join(token_l)
41 class NPOIE(NPOBaseIE):
43 IE_DESC = 'npo.nl and ntr.nl'
50 npo\.nl/(?!live|radio)(?:[^/]+/){2}|
51 ntr\.nl/(?:[^/]+/){2,}|
52 omroepwnl\.nl/video/fragment/[^/]+__
60 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
61 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
63 'id': 'VPWON_1220719',
66 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
67 'upload_date': '20140622',
71 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
72 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
74 'id': 'VARA_101191800',
76 'title': 'De Mega Mike & Mega Thomas show: The best of.',
77 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
78 'upload_date': '20090227',
83 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
84 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
86 'id': 'VPWON_1169289',
88 'title': 'Tegenlicht: De toekomst komt uit Afrika',
89 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
90 'upload_date': '20130225',
95 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
97 'id': 'WO_VPRO_043706',
99 'title': 'De nieuwe mens - Deel 1',
100 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
104 # mplayer mms download
105 'skip_download': True,
110 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
111 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
113 'id': 'WO_NOS_762771',
115 'title': 'Hoe gaat Europa verder na Parijs?',
119 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
120 'md5': '01c6a2841675995da1f0cf776f03a9c3',
122 'id': 'VPWON_1233944',
124 'title': 'Aap, poot, pies',
125 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
126 'upload_date': '20150508',
131 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
132 'md5': 'd30cd8417b8b9bca1fdff27428860d08',
134 'id': 'POW_00996502',
136 'title': '''"Dit is wel een 'landslide'..."''',
137 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
138 'upload_date': '20150508',
144 def _real_extract(self, url):
145 video_id = self._match_id(url)
146 return self._get_info(video_id)
148 def _get_info(self, video_id):
149 metadata = self._download_json(
150 'http://e.omroep.nl/metadata/%s' % video_id,
152 # We have to remove the javascript callback
153 transform_source=strip_jsonp,
156 # For some videos actual video id (prid) is different (e.g. for
157 # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
158 # video id is POMS_WNL_853698 but prid is POW_00996502)
159 video_id = metadata.get('prid') or video_id
161 # titel is too generic in some cases so utilize aflevering_titel as well
162 # when available (e.g. http://tegenlicht.vpro.nl/afleveringen/2014-2015/access-to-africa.html)
163 title = metadata['titel']
164 sub_title = metadata.get('aflevering_titel')
165 if sub_title and sub_title != title:
166 title += ': %s' % sub_title
168 token = self._get_token(video_id)
172 pubopties = metadata.get('pubopties')
174 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
175 for format_id in pubopties:
176 format_info = self._download_json(
177 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
178 % (video_id, format_id, token),
179 video_id, 'Downloading %s JSON' % format_id)
180 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
182 streams = format_info.get('streams')
184 video_info = self._download_json(
185 streams[0] + '&type=json',
186 video_id, 'Downloading %s stream JSON' % format_id)
188 video_info = format_info
189 video_url = video_info.get('url')
192 if format_id == 'adaptive':
193 formats.extend(self._extract_m3u8_formats(video_url, video_id, 'mp4'))
197 'format_id': format_id,
198 'quality': quality(format_id),
201 streams = metadata.get('streams')
203 for i, stream in enumerate(streams):
204 stream_url = stream.get('url')
207 if '.asf' not in stream_url:
210 'quality': stream.get('kwaliteit'),
213 asx = self._download_xml(
214 stream_url, video_id,
215 'Downloading stream %d ASX playlist' % i,
216 transform_source=fix_xml_ampersands)
217 ref = asx.find('./ENTRY/Ref')
220 video_url = ref.get('href')
225 'ext': stream.get('formaat', 'asf'),
226 'quality': stream.get('kwaliteit'),
229 self._sort_formats(formats)
232 if metadata.get('tt888') == 'ja':
235 'url': 'http://e.omroep.nl/tt888/%s' % video_id,
241 'description': metadata.get('info'),
242 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
243 'upload_date': unified_strdate(metadata.get('gidsdatum')),
244 'duration': parse_duration(metadata.get('tijdsduur')),
246 'subtitles': subtitles,
250 class NPOLiveIE(NPOBaseIE):
251 IE_NAME = 'npo.nl:live'
252 _VALID_URL = r'https?://(?:www\.)?npo\.nl/live/(?P<id>.+)'
255 'url': 'http://www.npo.nl/live/npo-1',
257 'id': 'LI_NEDERLAND1_136692',
258 'display_id': 'npo-1',
260 'title': 're:^Nederland 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
261 'description': 'Livestream',
265 'skip_download': True,
269 def _real_extract(self, url):
270 display_id = self._match_id(url)
272 webpage = self._download_webpage(url, display_id)
274 live_id = self._search_regex(
275 r'data-prid="([^"]+)"', webpage, 'live id')
277 metadata = self._download_json(
278 'http://e.omroep.nl/metadata/%s' % live_id,
279 display_id, transform_source=strip_jsonp)
281 token = self._get_token(display_id)
285 streams = metadata.get('streams')
287 for stream in streams:
288 stream_type = stream.get('type').lower()
289 # smooth streaming is not supported
290 if stream_type in ['ss', 'ms']:
292 stream_info = self._download_json(
293 'http://ida.omroep.nl/aapi/?stream=%s&token=%s&type=jsonp'
294 % (stream.get('url'), token),
295 display_id, 'Downloading %s JSON' % stream_type)
296 if stream_info.get('error_code', 0) or stream_info.get('errorcode', 0):
298 stream_url = self._download_json(
299 stream_info['stream'], display_id,
300 'Downloading %s URL' % stream_type,
301 'Unable to download %s URL' % stream_type,
302 transform_source=strip_jsonp, fatal=False)
305 if stream_type == 'hds':
306 f4m_formats = self._extract_f4m_formats(stream_url, display_id)
307 # f4m downloader downloads only piece of live stream
308 for f4m_format in f4m_formats:
309 f4m_format['preference'] = -1
310 formats.extend(f4m_formats)
311 elif stream_type == 'hls':
312 formats.extend(self._extract_m3u8_formats(stream_url, display_id, 'mp4'))
319 self._sort_formats(formats)
323 'display_id': display_id,
324 'title': self._live_title(metadata['titel']),
325 'description': metadata['info'],
326 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
332 class NPORadioIE(InfoExtractor):
333 IE_NAME = 'npo.nl:radio'
334 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
337 'url': 'http://www.npo.nl/radio/radio-1',
341 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
345 'skip_download': True,
350 def _html_get_attribute_regex(attribute):
351 return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
353 def _real_extract(self, url):
354 video_id = self._match_id(url)
356 webpage = self._download_webpage(url, video_id)
358 title = self._html_search_regex(
359 self._html_get_attribute_regex('data-channel'), webpage, 'title')
361 stream = self._parse_json(
362 self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
365 codec = stream.get('codec')
369 'url': stream['url'],
370 'title': self._live_title(title),
377 class NPORadioFragmentIE(InfoExtractor):
378 IE_NAME = 'npo.nl:radio:fragment'
379 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
382 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
383 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
387 'title': 'Jubileumconcert Willeke Alberti',
391 def _real_extract(self, url):
392 audio_id = self._match_id(url)
394 webpage = self._download_webpage(url, audio_id)
396 title = self._html_search_regex(
397 r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
400 audio_url = self._search_regex(
401 r"data-streams='([^']+)'", webpage, 'audio url')
410 class SchoolTVIE(InfoExtractor):
412 _VALID_URL = r'https?://(?:www\.)?schooltv\.nl/video/(?P<id>[^/?#&]+)'
415 'url': 'http://www.schooltv.nl/video/ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam/',
417 'id': 'WO_NTR_429477',
418 'display_id': 'ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam',
419 'title': 'Ademhaling: De hele dag haal je adem. Maar wat gebeurt er dan eigenlijk in je lichaam?',
421 'description': 'md5:abfa0ff690adb73fd0297fd033aaa631'
424 # Skip because of m3u8 download
425 'skip_download': True
429 def _real_extract(self, url):
430 display_id = self._match_id(url)
431 webpage = self._download_webpage(url, display_id)
432 video_id = self._search_regex(
433 r'data-mid=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video_id', group='id')
435 '_type': 'url_transparent',
437 'url': 'npo:%s' % video_id,
438 'display_id': display_id
442 class NPOPlaylistBaseIE(NPOIE):
443 def _real_extract(self, url):
444 playlist_id = self._match_id(url)
446 webpage = self._download_webpage(url, playlist_id)
449 self.url_result('npo:%s' % video_id if not video_id.startswith('http') else video_id)
450 for video_id in orderedSet(re.findall(self._PLAYLIST_ENTRY_RE, webpage))
453 playlist_title = self._html_search_regex(
454 self._PLAYLIST_TITLE_RE, webpage, 'playlist title',
455 default=None) or self._og_search_title(webpage)
457 return self.playlist_result(entries, playlist_id, playlist_title)
460 class VPROIE(NPOPlaylistBaseIE):
462 _VALID_URL = r'https?://(?:www\.)?(?:tegenlicht\.)?vpro\.nl/(?:[^/]+/){2,}(?P<id>[^/]+)\.html'
463 _PLAYLIST_TITLE_RE = r'<h1[^>]+class=["\'].*?\bmedia-platform-title\b.*?["\'][^>]*>([^<]+)'
464 _PLAYLIST_ENTRY_RE = r'data-media-id="([^"]+)"'
468 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
469 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
471 'id': 'VPWON_1169289',
473 'title': 'De toekomst komt uit Afrika',
474 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
475 'upload_date': '20130225',
477 'skip': 'Video gone',
480 'url': 'http://www.vpro.nl/programmas/2doc/2015/sergio-herman.html',
482 'id': 'sergio-herman',
483 'title': 'sergio herman: fucking perfect',
488 # playlist with youtube embed
489 'url': 'http://www.vpro.nl/programmas/2doc/2015/education-education.html',
491 'id': 'education-education',
492 'title': 'education education',
499 class WNLIE(NPOPlaylistBaseIE):
501 _VALID_URL = r'https?://(?:www\.)?omroepwnl\.nl/video/detail/(?P<id>[^/]+)__\d+'
502 _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class="subject"[^>]*>(.+?)</h1>'
503 _PLAYLIST_ENTRY_RE = r'<a[^>]+href="([^"]+)"[^>]+class="js-mid"[^>]*>Deel \d+'
506 'url': 'http://www.omroepwnl.nl/video/detail/vandaag-de-dag-6-mei__060515',
508 'id': 'vandaag-de-dag-6-mei',
509 'title': 'Vandaag de Dag 6 mei',
515 class AndereTijdenIE(NPOPlaylistBaseIE):
516 IE_NAME = 'anderetijden'
517 _VALID_URL = r'https?://(?:www\.)?anderetijden\.nl/programma/(?:[^/]+/)+(?P<id>[^/?#&]+)'
518 _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class=["\'].*?\bpage-title\b.*?["\'][^>]*>(.+?)</h1>'
519 _PLAYLIST_ENTRY_RE = r'<figure[^>]+class=["\']episode-container episode-page["\'][^>]+data-prid=["\'](.+?)["\']'
522 'url': 'http://anderetijden.nl/programma/1/Andere-Tijden/aflevering/676/Duitse-soldaten-over-de-Slag-bij-Arnhem',
524 'id': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
525 'title': 'Duitse soldaten over de Slag bij Arnhem',