1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
28 class NPOBaseIE(InfoExtractor
):
29 def _get_token(self
, video_id
):
30 return self
._download
_json
(
31 'http://ida.omroep.nl/app.php/auth', video_id
,
32 note
='Downloading token')['token']
35 class NPOIE(NPOBaseIE
):
37 IE_DESC
= 'npo.nl, ntr.nl, omroepwnl.nl, zapp.nl and npo3.nl'
45 (?:ntr|npostart)\.nl/(?:[^/]+/){2,}|
46 omroepwnl\.nl/video/fragment/[^/]+__|
47 (?:zapp|npo3)\.nl/(?:[^/]+/){2,}
54 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
55 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
57 'id': 'VPWON_1220719',
60 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
61 'upload_date': '20140622',
64 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
65 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
67 'id': 'VARA_101191800',
69 'title': 'De Mega Mike & Mega Thomas show: The best of.',
70 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
71 'upload_date': '20090227',
75 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
76 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
78 'id': 'VPWON_1169289',
80 'title': 'Tegenlicht: Zwart geld. De toekomst komt uit Afrika',
81 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
82 'upload_date': '20130225',
86 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
88 'id': 'WO_VPRO_043706',
90 'title': 'De nieuwe mens - Deel 1',
91 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
95 'skip_download': True,
99 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
101 'id': 'WO_NOS_762771',
103 'title': 'Hoe gaat Europa verder na Parijs?',
106 'skip_download': True,
109 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
111 'id': 'VPWON_1233944',
113 'title': 'Aap, poot, pies',
114 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
115 'upload_date': '20150508',
119 'skip_download': True,
122 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
124 'id': 'POW_00996502',
126 'title': '''"Dit is wel een 'landslide'..."''',
127 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
128 'upload_date': '20150508',
132 'skip_download': True,
136 'url': 'http://www.npo.nl/jouw-stad-rotterdam/29-01-2017/RBX_FUNX_6683215/RBX_FUNX_7601437',
138 'id': 'RBX_FUNX_6683215',
140 'title': 'Jouw Stad Rotterdam',
141 'description': 'md5:db251505244f097717ec59fabc372d9f',
144 'skip_download': True,
147 'url': 'http://www.zapp.nl/de-bzt-show/gemist/KN_1687547',
148 'only_matching': True,
150 'url': 'http://www.zapp.nl/de-bzt-show/filmpjes/POMS_KN_7315118',
151 'only_matching': True,
153 'url': 'http://www.zapp.nl/beste-vrienden-quiz/extra-video-s/WO_NTR_1067990',
154 'only_matching': True,
156 'url': 'https://www.npo3.nl/3onderzoekt/16-09-2015/VPWON_1239870',
157 'only_matching': True,
160 'url': 'npo:LI_NL1_4188102',
161 'only_matching': True,
163 'url': 'http://www.npo.nl/radio-gaga/13-06-2017/BNN_101383373',
164 'only_matching': True,
166 'url': 'https://www.zapp.nl/1803-skelterlab/instructie-video-s/740-instructievideo-s/POMS_AT_11736927',
167 'only_matching': True,
169 'url': 'https://www.npostart.nl/broodje-gezond-ei/28-05-2018/KN_1698996',
170 'only_matching': True,
172 'url': 'https://npo.nl/KN_1698996',
173 'only_matching': True,
177 def suitable(cls
, url
):
178 return (False if any(ie
.suitable(url
)
179 for ie
in (NPOLiveIE
, NPORadioIE
, NPORadioFragmentIE
))
180 else super(NPOIE
, cls
).suitable(url
))
182 def _real_extract(self
, url
):
183 video_id
= self
._match
_id
(url
)
184 return self
._get
_info
(url
, video_id
) or self
._get
_old
_info
(video_id
)
186 def _get_info(self
, url
, video_id
):
187 token
= self
._download
_json
(
188 'https://www.npostart.nl/api/token', video_id
,
189 'Downloading token', headers
={
191 'X-Requested-With': 'XMLHttpRequest',
194 player
= self
._download
_json
(
195 'https://www.npostart.nl/player/%s' % video_id
, video_id
,
196 'Downloading player JSON', data
=urlencode_postdata({
204 player_token
= player
['token']
209 for profile
in ('hls', 'dash-widevine', 'dash-playready', 'smooth'):
210 streams
= self
._download
_json
(
211 'https://start-player.npo.nl/video/%s/streams' % video_id
,
212 video_id
, 'Downloading %s profile JSON' % profile
, fatal
=False,
216 'tokenId': player_token
,
217 'streamType': 'broadcast',
221 stream
= streams
.get('stream')
222 if not isinstance(stream
, dict):
224 stream_url
= url_or_none(stream
.get('src'))
225 if not stream_url
or stream_url
in format_urls
:
227 format_urls
.add(stream_url
)
228 if stream
.get('protection') is not None or stream
.get('keySystemOptions') is not None:
231 stream_type
= stream
.get('type')
232 stream_ext
= determine_ext(stream_url
)
233 if stream_type
== 'application/dash+xml' or stream_ext
== 'mpd':
234 formats
.extend(self
._extract
_mpd
_formats
(
235 stream_url
, video_id
, mpd_id
='dash', fatal
=False))
236 elif stream_type
== 'application/vnd.apple.mpegurl' or stream_ext
== 'm3u8':
237 formats
.extend(self
._extract
_m
3u8_formats
(
238 stream_url
, video_id
, ext
='mp4',
239 entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False))
240 elif re
.search(r
'\.isml?/Manifest', stream_url
):
241 formats
.extend(self
._extract
_ism
_formats
(
242 stream_url
, video_id
, ism_id
='mss', fatal
=False))
249 if not self
.get_param('allow_unplayable_formats') and drm
:
250 self
.report_drm(video_id
)
252 self
._sort
_formats
(formats
)
260 embed_url
= url_or_none(player
.get('embedUrl'))
262 webpage
= self
._download
_webpage
(
263 embed_url
, video_id
, 'Downloading embed page', fatal
=False)
265 video
= self
._parse
_json
(
267 r
'\bvideo\s*=\s*({.+?})\s*;', webpage
, 'video',
268 default
='{}'), video_id
)
270 title
= video
.get('episodeTitle')
272 subtitles_list
= video
.get('subtitles')
273 if isinstance(subtitles_list
, list):
274 for cc
in subtitles_list
:
275 cc_url
= url_or_none(cc
.get('src'))
278 lang
= str_or_none(cc
.get('language')) or 'nl'
279 subtitles
.setdefault(lang
, []).append({
284 'description': video
.get('description'),
285 'thumbnail': url_or_none(
286 video
.get('still_image_url') or video
.get('orig_image_url')),
287 'duration': int_or_none(video
.get('duration')),
288 'timestamp': unified_timestamp(video
.get('broadcastDate')),
289 'creator': video
.get('channel'),
290 'series': video
.get('title'),
292 'episode_number': int_or_none(video
.get('episodeNumber')),
293 'subtitles': subtitles
,
298 def _get_old_info(self
, video_id
):
299 metadata
= self
._download
_json
(
300 'http://e.omroep.nl/metadata/%s' % video_id
,
302 # We have to remove the javascript callback
303 transform_source
=strip_jsonp
,
306 error
= metadata
.get('error')
308 raise ExtractorError(error
, expected
=True)
310 # For some videos actual video id (prid) is different (e.g. for
311 # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
312 # video id is POMS_WNL_853698 but prid is POW_00996502)
313 video_id
= metadata
.get('prid') or video_id
315 # titel is too generic in some cases so utilize aflevering_titel as well
316 # when available (e.g. http://tegenlicht.vpro.nl/afleveringen/2014-2015/access-to-africa.html)
317 title
= metadata
['titel']
318 sub_title
= metadata
.get('aflevering_titel')
319 if sub_title
and sub_title
!= title
:
320 title
+= ': %s' % sub_title
322 token
= self
._get
_token
(video_id
)
327 def is_legal_url(format_url
):
328 return format_url
and format_url
not in urls
and re
.match(
329 r
'^(?:https?:)?//', format_url
)
331 QUALITY_LABELS
= ('Laag', 'Normaal', 'Hoog')
332 QUALITY_FORMATS
= ('adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std')
334 quality_from_label
= qualities(QUALITY_LABELS
)
335 quality_from_format_id
= qualities(QUALITY_FORMATS
)
336 items
= self
._download
_json
(
337 'http://ida.omroep.nl/app.php/%s' % video_id
, video_id
,
338 'Downloading formats JSON', query
={
342 for num
, item
in enumerate(items
):
343 item_url
= item
.get('url')
344 if not is_legal_url(item_url
):
347 format_id
= self
._search
_regex
(
348 r
'video/ida/([^/]+)', item_url
, 'format id',
351 item_label
= item
.get('label')
353 def add_format_url(format_url
):
354 width
= int_or_none(self
._search
_regex
(
355 r
'(\d+)[xX]\d+', format_url
, 'width', default
=None))
356 height
= int_or_none(self
._search
_regex
(
357 r
'\d+[xX](\d+)', format_url
, 'height', default
=None))
358 if item_label
in QUALITY_LABELS
:
359 quality
= quality_from_label(item_label
)
361 elif item_label
in QUALITY_FORMATS
:
362 quality
= quality_from_format_id(format_id
)
365 quality
, f_id
= [None] * 2
374 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
375 if item
.get('contentType') in ('url', 'audio'):
376 add_format_url(item_url
)
380 stream_info
= self
._download
_json
(
381 item_url
+ '&type=json', video_id
,
382 'Downloading %s stream JSON'
383 % item_label
or item
.get('format') or format_id
or num
)
384 except ExtractorError
as ee
:
385 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 404:
386 error
= (self
._parse
_json
(
387 ee
.cause
.read().decode(), video_id
,
388 fatal
=False) or {}).get('errorstring')
390 raise ExtractorError(error
, expected
=True)
392 # Stream URL instead of JSON, example: npo:LI_NL1_4188102
393 if isinstance(stream_info
, compat_str
):
394 if not stream_info
.startswith('http'):
396 video_url
= stream_info
399 video_url
= stream_info
.get('url')
400 if not video_url
or 'vodnotavailable.' in video_url
or video_url
in urls
:
403 if determine_ext(video_url
) == 'm3u8':
404 formats
.extend(self
._extract
_m
3u8_formats
(
405 video_url
, video_id
, ext
='mp4',
406 entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False))
408 add_format_url(video_url
)
410 is_live
= metadata
.get('medium') == 'live'
413 for num
, stream
in enumerate(metadata
.get('streams', [])):
414 stream_url
= stream
.get('url')
415 if not is_legal_url(stream_url
):
418 # smooth streaming is not supported
419 stream_type
= stream
.get('type', '').lower()
420 if stream_type
in ['ss', 'ms']:
422 if stream_type
== 'hds':
423 f4m_formats
= self
._extract
_f
4m
_formats
(
424 stream_url
, video_id
, fatal
=False)
425 # f4m downloader downloads only piece of live stream
426 for f4m_format
in f4m_formats
:
427 f4m_format
['preference'] = -5
428 formats
.extend(f4m_formats
)
429 elif stream_type
== 'hls':
430 formats
.extend(self
._extract
_m
3u8_formats
(
431 stream_url
, video_id
, ext
='mp4', fatal
=False))
432 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
433 elif '.asf' in stream_url
:
434 asx
= self
._download
_xml
(
435 stream_url
, video_id
,
436 'Downloading stream %d ASX playlist' % num
,
437 transform_source
=fix_xml_ampersands
, fatal
=False)
440 ref
= asx
.find('./ENTRY/Ref')
443 video_url
= ref
.get('href')
444 if not video_url
or video_url
in urls
:
449 'ext': stream
.get('formaat', 'asf'),
450 'quality': stream
.get('kwaliteit'),
456 'quality': stream
.get('kwaliteit'),
459 self
._sort
_formats
(formats
)
462 if metadata
.get('tt888') == 'ja':
465 'url': 'http://tt888.omroep.nl/tt888/%s' % video_id
,
471 'description': metadata
.get('info'),
472 'thumbnail': metadata
.get('images', [{'url': None}
])[-1]['url'],
473 'upload_date': unified_strdate(metadata
.get('gidsdatum')),
474 'duration': parse_duration(metadata
.get('tijdsduur')),
476 'subtitles': subtitles
,
481 class NPOLiveIE(NPOBaseIE
):
482 IE_NAME
= 'npo.nl:live'
483 _VALID_URL
= r
'https?://(?:www\.)?npo(?:start)?\.nl/live(?:/(?P<id>[^/?#&]+))?'
486 'url': 'http://www.npo.nl/live/npo-1',
488 'id': 'LI_NL1_4188102',
489 'display_id': 'npo-1',
491 'title': 're:^NPO 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
495 'skip_download': True,
498 'url': 'http://www.npo.nl/live',
499 'only_matching': True,
501 'url': 'https://www.npostart.nl/live/npo-1',
502 'only_matching': True,
505 def _real_extract(self
, url
):
506 display_id
= self
._match
_id
(url
) or 'npo-1'
508 webpage
= self
._download
_webpage
(url
, display_id
)
510 live_id
= self
._search
_regex
(
511 [r
'media-id="([^"]+)"', r
'data-prid="([^"]+)"'], webpage
, 'live id')
514 '_type': 'url_transparent',
515 'url': 'npo:%s' % live_id
,
516 'ie_key': NPOIE
.ie_key(),
518 'display_id': display_id
,
522 class NPORadioIE(InfoExtractor
):
523 IE_NAME
= 'npo.nl:radio'
524 _VALID_URL
= r
'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)'
527 'url': 'http://www.npo.nl/radio/radio-1',
531 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
535 'skip_download': True,
540 def suitable(cls
, url
):
541 return False if NPORadioFragmentIE
.suitable(url
) else super(NPORadioIE
, cls
).suitable(url
)
544 def _html_get_attribute_regex(attribute
):
545 return r
'{0}\s*=\s*\'([^
\']+)\''.format(attribute)
547 def _real_extract(self, url):
548 video_id = self._match_id(url)
550 webpage = self._download_webpage(url, video_id)
552 title = self._html_search_regex(
553 self._html_get_attribute_regex('data
-channel
'), webpage, 'title
')
555 stream = self._parse_json(
556 self._html_search_regex(self._html_get_attribute_regex('data
-streams
'), webpage, 'data
-streams
'),
559 codec = stream.get('codec
')
563 'url
': stream['url
'],
571 class NPORadioFragmentIE(InfoExtractor):
572 IE_NAME = 'npo
.nl
:radio
:fragment
'
573 _VALID_URL = r'https?
://(?
:www\
.)?npo\
.nl
/radio
/[^
/]+/fragment
/(?P
<id>\d
+)'
576 'url
': 'http
://www
.npo
.nl
/radio
/radio
-5/fragment
/174356',
577 'md5
': 'dd8cc470dad764d0fdc70a9a1e2d18c2
',
581 'title
': 'Jubileumconcert Willeke Alberti
',
585 def _real_extract(self, url):
586 audio_id = self._match_id(url)
588 webpage = self._download_webpage(url, audio_id)
590 title = self._html_search_regex(
591 r'href
="/radio/[^/]+/fragment/%s" title
="([^"]+)"' % audio_id,
594 audio_url = self._search_regex(
595 r"data
-streams
='([^']+)'", webpage, 'audio url
')
604 class NPODataMidEmbedIE(InfoExtractor):
605 def _real_extract(self, url):
606 display_id = self._match_id(url)
607 webpage = self._download_webpage(url, display_id)
608 video_id = self._search_regex(
609 r'data
-mid
=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video_id', group='id')
611 '_type': 'url_transparent',
613 'url': 'npo:%s' % video_id,
614 'display_id': display_id
618 class SchoolTVIE(NPODataMidEmbedIE):
620 _VALID_URL = r'https?://(?:www\.)?schooltv\.nl/video/(?P<id>[^/?#&]+)'
623 'url': 'http://www.schooltv.nl/video/ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam/',
625 'id': 'WO_NTR_429477',
626 'display_id': 'ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam',
627 'title': 'Ademhaling: De hele dag haal je adem. Maar wat gebeurt er dan eigenlijk in je lichaam?',
629 'description': 'md5:abfa0ff690adb73fd0297fd033aaa631'
632 # Skip because of m3u8 download
633 'skip_download': True
638 class HetKlokhuisIE(NPODataMidEmbedIE):
639 IE_NAME = 'hetklokhuis'
640 _VALID_URL = r'https?://(?:www\.)?hetklokhuis\.nl/[^/]+/\d+/(?P<id>[^/?#&]+)'
643 'url': 'http://hetklokhuis.nl/tv-uitzending/3471/Zwaartekrachtsgolven',
645 'id': 'VPWON_1260528',
646 'display_id': 'Zwaartekrachtsgolven',
648 'title': 'Het Klokhuis: Zwaartekrachtsgolven',
649 'description': 'md5:c94f31fb930d76c2efa4a4a71651dd48',
650 'upload_date': '20170223',
653 'skip_download': True
658 class NPOPlaylistBaseIE(NPOIE):
659 def _real_extract(self, url):
660 playlist_id = self._match_id(url)
662 webpage = self._download_webpage(url, playlist_id)
665 self.url_result('npo:%s' % video_id if not video_id.startswith('http') else video_id)
666 for video_id in orderedSet(re.findall(self._PLAYLIST_ENTRY_RE, webpage))
669 playlist_title = self._html_search_regex(
670 self._PLAYLIST_TITLE_RE, webpage, 'playlist title',
671 default=None) or self._og_search_title(webpage)
673 return self.playlist_result(entries, playlist_id, playlist_title)
676 class VPROIE(NPOPlaylistBaseIE):
678 _VALID_URL = r'https?://(?:www\.)?(?:(?:tegenlicht\.)?vpro|2doc)\.nl/(?:[^/]+/)*(?P<id>[^/]+)\.html'
679 _PLAYLIST_TITLE_RE = (r'<h1[^>]+class=["\'].*?
\bmedia
-platform
-title
\b.*?
["\'][^>]*>([^<]+)',
680 r'<h5[^>]+class=["\'].*?
\bmedia
-platform
-subtitle
\b.*?
["\'][^>]*>([^<]+)')
681 _PLAYLIST_ENTRY_RE = r'data-media-id="([^
"]+)"'
685 'url
': 'http
://tegenlicht
.vpro
.nl
/afleveringen
/2012-2013/de
-toekomst
-komt
-uit
-afrika
.html
',
686 'md5
': 'f8065e4e5a7824068ed3c7e783178f2c
',
688 'id': 'VPWON_1169289
',
690 'title
': 'De toekomst komt uit Afrika
',
691 'description
': 'md5
:52cf4eefbc96fffcbdc06d024147abea
',
692 'upload_date
': '20130225',
694 'skip
': 'Video gone
',
697 'url
': 'http
://www
.vpro
.nl
/programmas
/2doc
/2015/sergio
-herman
.html
',
699 'id': 'sergio
-herman
',
700 'title
': 'sergio herman
: fucking perfect
',
705 # playlist with youtube embed
706 'url
': 'http
://www
.vpro
.nl
/programmas
/2doc
/2015/education
-education
.html
',
708 'id': 'education
-education
',
709 'title
': 'education education
',
714 'url
': 'http
://www
.2doc
.nl
/documentaires
/series
/2doc
/2015/oktober
/de
-tegenprestatie
.html
',
716 'id': 'de
-tegenprestatie
',
717 'title
': 'De Tegenprestatie
',
721 'url
': 'http
://www
.2doc
.nl
/speel~VARA_101375237~mh17
-het
-verdriet
-van
-nederland~
.html
',
723 'id': 'VARA_101375237
',
725 'title
': 'MH17
: Het verdriet van Nederland
',
726 'description
': 'md5
:09e1a37c1fdb144621e22479691a9f18
',
727 'upload_date
': '20150716',
730 # Skip because of m3u8 download
731 'skip_download
': True
737 class WNLIE(NPOPlaylistBaseIE):
739 _VALID_URL = r'https?
://(?
:www\
.)?omroepwnl\
.nl
/video
/detail
/(?P
<id>[^
/]+)__\d
+'
740 _PLAYLIST_TITLE_RE = r'(?s
)<h1
[^
>]+class="subject"[^
>]*>(.+?
)</h1
>'
741 _PLAYLIST_ENTRY_RE = r'<a
[^
>]+href
="([^"]+)"[^>]+class="js
-mid
"[^>]*>Deel \d+'
744 'url': 'http://www.omroepwnl.nl/video/detail/vandaag-de-dag-6-mei__060515',
746 'id': 'vandaag-de-dag-6-mei',
747 'title': 'Vandaag de Dag 6 mei',
753 class AndereTijdenIE(NPOPlaylistBaseIE):
754 IE_NAME = 'anderetijden'
755 _VALID_URL = r'https?://(?:www\.)?anderetijden\.nl/programma/(?:[^/]+/)+(?P<id>[^/?#&]+)'
756 _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class=["\'].*?
\bpage
-title
\b.*?
["\'][^>]*>(.+?)</h1>'
757 _PLAYLIST_ENTRY_RE = r'<figure[^>]+class=["\']episode
-container episode
-page
["\'][^>]+data-prid=["\'](.+?
)["\']'
760 'url': 'http://anderetijden.nl/programma/1/Andere-Tijden/aflevering/676/Duitse-soldaten-over-de-Slag-bij-Arnhem',
762 'id': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
763 'title': 'Duitse soldaten over de Slag bij Arnhem',