3 from .common
import InfoExtractor
26 class NPOBaseIE(InfoExtractor
):
27 def _get_token(self
, video_id
):
28 return self
._download
_json
(
29 'http://ida.omroep.nl/app.php/auth', video_id
,
30 note
='Downloading token')['token']
33 class NPOIE(NPOBaseIE
):
35 IE_DESC
= 'npo.nl, ntr.nl, omroepwnl.nl, zapp.nl and npo3.nl'
43 (?:ntr|npostart)\.nl/(?:[^/]+/){2,}|
44 omroepwnl\.nl/video/fragment/[^/]+__|
45 (?:zapp|npo3)\.nl/(?:[^/]+/){2,}
52 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
53 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
55 'id': 'VPWON_1220719',
58 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
59 'upload_date': '20140622',
62 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
63 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
65 'id': 'VARA_101191800',
67 'title': 'De Mega Mike & Mega Thomas show: The best of.',
68 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
69 'upload_date': '20090227',
73 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
74 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
76 'id': 'VPWON_1169289',
78 'title': 'Tegenlicht: Zwart geld. De toekomst komt uit Afrika',
79 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
80 'upload_date': '20130225',
84 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
86 'id': 'WO_VPRO_043706',
88 'title': 'De nieuwe mens - Deel 1',
89 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
93 'skip_download': True,
97 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
99 'id': 'WO_NOS_762771',
101 'title': 'Hoe gaat Europa verder na Parijs?',
104 'skip_download': True,
107 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
109 'id': 'VPWON_1233944',
111 'title': 'Aap, poot, pies',
112 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
113 'upload_date': '20150508',
117 'skip_download': True,
120 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
122 'id': 'POW_00996502',
124 'title': '''"Dit is wel een 'landslide'..."''',
125 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
126 'upload_date': '20150508',
130 'skip_download': True,
134 'url': 'http://www.npo.nl/jouw-stad-rotterdam/29-01-2017/RBX_FUNX_6683215/RBX_FUNX_7601437',
136 'id': 'RBX_FUNX_6683215',
138 'title': 'Jouw Stad Rotterdam',
139 'description': 'md5:db251505244f097717ec59fabc372d9f',
142 'skip_download': True,
145 'url': 'http://www.zapp.nl/de-bzt-show/gemist/KN_1687547',
146 'only_matching': True,
148 'url': 'http://www.zapp.nl/de-bzt-show/filmpjes/POMS_KN_7315118',
149 'only_matching': True,
151 'url': 'http://www.zapp.nl/beste-vrienden-quiz/extra-video-s/WO_NTR_1067990',
152 'only_matching': True,
154 'url': 'https://www.npo3.nl/3onderzoekt/16-09-2015/VPWON_1239870',
155 'only_matching': True,
158 'url': 'npo:LI_NL1_4188102',
159 'only_matching': True,
161 'url': 'http://www.npo.nl/radio-gaga/13-06-2017/BNN_101383373',
162 'only_matching': True,
164 'url': 'https://www.zapp.nl/1803-skelterlab/instructie-video-s/740-instructievideo-s/POMS_AT_11736927',
165 'only_matching': True,
167 'url': 'https://www.npostart.nl/broodje-gezond-ei/28-05-2018/KN_1698996',
168 'only_matching': True,
170 'url': 'https://npo.nl/KN_1698996',
171 'only_matching': True,
175 def suitable(cls
, url
):
176 return (False if any(ie
.suitable(url
)
177 for ie
in (NPOLiveIE
, NPORadioIE
, NPORadioFragmentIE
))
178 else super(NPOIE
, cls
).suitable(url
))
180 def _real_extract(self
, url
):
181 video_id
= self
._match
_id
(url
)
182 return self
._get
_info
(url
, video_id
) or self
._get
_old
_info
(video_id
)
184 def _get_info(self
, url
, video_id
):
185 token
= self
._download
_json
(
186 'https://www.npostart.nl/api/token', video_id
,
187 'Downloading token', headers
={
189 'X-Requested-With': 'XMLHttpRequest',
192 player
= self
._download
_json
(
193 'https://www.npostart.nl/player/%s' % video_id
, video_id
,
194 'Downloading player JSON', data
=urlencode_postdata({
202 player_token
= player
['token']
207 for profile
in ('hls', 'dash-widevine', 'dash-playready', 'smooth'):
208 streams
= self
._download
_json
(
209 'https://start-player.npo.nl/video/%s/streams' % video_id
,
210 video_id
, 'Downloading %s profile JSON' % profile
, fatal
=False,
214 'tokenId': player_token
,
215 'streamType': 'broadcast',
219 stream
= streams
.get('stream')
220 if not isinstance(stream
, dict):
222 stream_url
= url_or_none(stream
.get('src'))
223 if not stream_url
or stream_url
in format_urls
:
225 format_urls
.add(stream_url
)
226 if stream
.get('protection') is not None or stream
.get('keySystemOptions') is not None:
229 stream_type
= stream
.get('type')
230 stream_ext
= determine_ext(stream_url
)
231 if stream_type
== 'application/dash+xml' or stream_ext
== 'mpd':
232 formats
.extend(self
._extract
_mpd
_formats
(
233 stream_url
, video_id
, mpd_id
='dash', fatal
=False))
234 elif stream_type
== 'application/vnd.apple.mpegurl' or stream_ext
== 'm3u8':
235 formats
.extend(self
._extract
_m
3u8_formats
(
236 stream_url
, video_id
, ext
='mp4',
237 entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False))
238 elif re
.search(r
'\.isml?/Manifest', stream_url
):
239 formats
.extend(self
._extract
_ism
_formats
(
240 stream_url
, video_id
, ism_id
='mss', fatal
=False))
247 if not self
.get_param('allow_unplayable_formats') and drm
:
248 self
.report_drm(video_id
)
250 self
._sort
_formats
(formats
)
258 embed_url
= url_or_none(player
.get('embedUrl'))
260 webpage
= self
._download
_webpage
(
261 embed_url
, video_id
, 'Downloading embed page', fatal
=False)
263 video
= self
._parse
_json
(
265 r
'\bvideo\s*=\s*({.+?})\s*;', webpage
, 'video',
266 default
='{}'), video_id
)
268 title
= video
.get('episodeTitle')
270 subtitles_list
= video
.get('subtitles')
271 if isinstance(subtitles_list
, list):
272 for cc
in subtitles_list
:
273 cc_url
= url_or_none(cc
.get('src'))
276 lang
= str_or_none(cc
.get('language')) or 'nl'
277 subtitles
.setdefault(lang
, []).append({
282 'description': video
.get('description'),
283 'thumbnail': url_or_none(
284 video
.get('still_image_url') or video
.get('orig_image_url')),
285 'duration': int_or_none(video
.get('duration')),
286 'timestamp': unified_timestamp(video
.get('broadcastDate')),
287 'creator': video
.get('channel'),
288 'series': video
.get('title'),
290 'episode_number': int_or_none(video
.get('episodeNumber')),
291 'subtitles': subtitles
,
296 def _get_old_info(self
, video_id
):
297 metadata
= self
._download
_json
(
298 'http://e.omroep.nl/metadata/%s' % video_id
,
300 # We have to remove the javascript callback
301 transform_source
=strip_jsonp
,
304 error
= metadata
.get('error')
306 raise ExtractorError(error
, expected
=True)
308 # For some videos actual video id (prid) is different (e.g. for
309 # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
310 # video id is POMS_WNL_853698 but prid is POW_00996502)
311 video_id
= metadata
.get('prid') or video_id
313 # titel is too generic in some cases so utilize aflevering_titel as well
314 # when available (e.g. http://tegenlicht.vpro.nl/afleveringen/2014-2015/access-to-africa.html)
315 title
= metadata
['titel']
316 sub_title
= metadata
.get('aflevering_titel')
317 if sub_title
and sub_title
!= title
:
318 title
+= ': %s' % sub_title
320 token
= self
._get
_token
(video_id
)
325 def is_legal_url(format_url
):
326 return format_url
and format_url
not in urls
and re
.match(
327 r
'^(?:https?:)?//', format_url
)
329 QUALITY_LABELS
= ('Laag', 'Normaal', 'Hoog')
330 QUALITY_FORMATS
= ('adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std')
332 quality_from_label
= qualities(QUALITY_LABELS
)
333 quality_from_format_id
= qualities(QUALITY_FORMATS
)
334 items
= self
._download
_json
(
335 'http://ida.omroep.nl/app.php/%s' % video_id
, video_id
,
336 'Downloading formats JSON', query
={
340 for num
, item
in enumerate(items
):
341 item_url
= item
.get('url')
342 if not is_legal_url(item_url
):
345 format_id
= self
._search
_regex
(
346 r
'video/ida/([^/]+)', item_url
, 'format id',
349 item_label
= item
.get('label')
351 def add_format_url(format_url
):
352 width
= int_or_none(self
._search
_regex
(
353 r
'(\d+)[xX]\d+', format_url
, 'width', default
=None))
354 height
= int_or_none(self
._search
_regex
(
355 r
'\d+[xX](\d+)', format_url
, 'height', default
=None))
356 if item_label
in QUALITY_LABELS
:
357 quality
= quality_from_label(item_label
)
359 elif item_label
in QUALITY_FORMATS
:
360 quality
= quality_from_format_id(format_id
)
363 quality
, f_id
= [None] * 2
372 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
373 if item
.get('contentType') in ('url', 'audio'):
374 add_format_url(item_url
)
378 stream_info
= self
._download
_json
(
379 item_url
+ '&type=json', video_id
,
380 'Downloading %s stream JSON'
381 % item_label
or item
.get('format') or format_id
or num
)
382 except ExtractorError
as ee
:
383 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 404:
384 error
= (self
._parse
_json
(
385 ee
.cause
.read().decode(), video_id
,
386 fatal
=False) or {}).get('errorstring')
388 raise ExtractorError(error
, expected
=True)
390 # Stream URL instead of JSON, example: npo:LI_NL1_4188102
391 if isinstance(stream_info
, compat_str
):
392 if not stream_info
.startswith('http'):
394 video_url
= stream_info
397 video_url
= stream_info
.get('url')
398 if not video_url
or 'vodnotavailable.' in video_url
or video_url
in urls
:
401 if determine_ext(video_url
) == 'm3u8':
402 formats
.extend(self
._extract
_m
3u8_formats
(
403 video_url
, video_id
, ext
='mp4',
404 entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False))
406 add_format_url(video_url
)
408 is_live
= metadata
.get('medium') == 'live'
411 for num
, stream
in enumerate(metadata
.get('streams', [])):
412 stream_url
= stream
.get('url')
413 if not is_legal_url(stream_url
):
416 # smooth streaming is not supported
417 stream_type
= stream
.get('type', '').lower()
418 if stream_type
in ['ss', 'ms']:
420 if stream_type
== 'hds':
421 f4m_formats
= self
._extract
_f
4m
_formats
(
422 stream_url
, video_id
, fatal
=False)
423 # f4m downloader downloads only piece of live stream
424 for f4m_format
in f4m_formats
:
425 f4m_format
['preference'] = -5
426 formats
.extend(f4m_formats
)
427 elif stream_type
== 'hls':
428 formats
.extend(self
._extract
_m
3u8_formats
(
429 stream_url
, video_id
, ext
='mp4', fatal
=False))
430 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
431 elif '.asf' in stream_url
:
432 asx
= self
._download
_xml
(
433 stream_url
, video_id
,
434 'Downloading stream %d ASX playlist' % num
,
435 transform_source
=fix_xml_ampersands
, fatal
=False)
438 ref
= asx
.find('./ENTRY/Ref')
441 video_url
= ref
.get('href')
442 if not video_url
or video_url
in urls
:
447 'ext': stream
.get('formaat', 'asf'),
448 'quality': stream
.get('kwaliteit'),
454 'quality': stream
.get('kwaliteit'),
457 self
._sort
_formats
(formats
)
460 if metadata
.get('tt888') == 'ja':
463 'url': 'http://tt888.omroep.nl/tt888/%s' % video_id
,
469 'description': metadata
.get('info'),
470 'thumbnail': metadata
.get('images', [{'url': None}
])[-1]['url'],
471 'upload_date': unified_strdate(metadata
.get('gidsdatum')),
472 'duration': parse_duration(metadata
.get('tijdsduur')),
474 'subtitles': subtitles
,
479 class NPOLiveIE(NPOBaseIE
):
480 IE_NAME
= 'npo.nl:live'
481 _VALID_URL
= r
'https?://(?:www\.)?npo(?:start)?\.nl/live(?:/(?P<id>[^/?#&]+))?'
484 'url': 'http://www.npo.nl/live/npo-1',
486 'id': 'LI_NL1_4188102',
487 'display_id': 'npo-1',
489 'title': 're:^NPO 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
493 'skip_download': True,
496 'url': 'http://www.npo.nl/live',
497 'only_matching': True,
499 'url': 'https://www.npostart.nl/live/npo-1',
500 'only_matching': True,
503 def _real_extract(self
, url
):
504 display_id
= self
._match
_id
(url
) or 'npo-1'
506 webpage
= self
._download
_webpage
(url
, display_id
)
508 live_id
= self
._search
_regex
(
509 [r
'media-id="([^"]+)"', r
'data-prid="([^"]+)"'], webpage
, 'live id')
512 '_type': 'url_transparent',
513 'url': 'npo:%s' % live_id
,
514 'ie_key': NPOIE
.ie_key(),
516 'display_id': display_id
,
520 class NPORadioIE(InfoExtractor
):
521 IE_NAME
= 'npo.nl:radio'
522 _VALID_URL
= r
'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)'
525 'url': 'http://www.npo.nl/radio/radio-1',
529 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
533 'skip_download': True,
538 def suitable(cls
, url
):
539 return False if NPORadioFragmentIE
.suitable(url
) else super(NPORadioIE
, cls
).suitable(url
)
542 def _html_get_attribute_regex(attribute
):
543 return r
'{0}\s*=\s*\'([^
\']+)\''.format(attribute)
545 def _real_extract(self, url):
546 video_id = self._match_id(url)
548 webpage = self._download_webpage(url, video_id)
550 title = self._html_search_regex(
551 self._html_get_attribute_regex('data
-channel
'), webpage, 'title
')
553 stream = self._parse_json(
554 self._html_search_regex(self._html_get_attribute_regex('data
-streams
'), webpage, 'data
-streams
'),
557 codec = stream.get('codec
')
561 'url
': stream['url
'],
569 class NPORadioFragmentIE(InfoExtractor):
570 IE_NAME = 'npo
.nl
:radio
:fragment
'
571 _VALID_URL = r'https?
://(?
:www\
.)?npo\
.nl
/radio
/[^
/]+/fragment
/(?P
<id>\d
+)'
574 'url
': 'http
://www
.npo
.nl
/radio
/radio
-5/fragment
/174356',
575 'md5
': 'dd8cc470dad764d0fdc70a9a1e2d18c2
',
579 'title
': 'Jubileumconcert Willeke Alberti
',
583 def _real_extract(self, url):
584 audio_id = self._match_id(url)
586 webpage = self._download_webpage(url, audio_id)
588 title = self._html_search_regex(
589 r'href
="/radio/[^/]+/fragment/%s" title
="([^"]+)"' % audio_id,
592 audio_url = self._search_regex(
593 r"data
-streams
='([^']+)'", webpage, 'audio url
')
602 class NPODataMidEmbedIE(InfoExtractor):
603 def _real_extract(self, url):
604 display_id = self._match_id(url)
605 webpage = self._download_webpage(url, display_id)
606 video_id = self._search_regex(
607 r'data
-mid
=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video_id', group='id')
609 '_type': 'url_transparent',
611 'url': 'npo:%s' % video_id,
612 'display_id': display_id
616 class SchoolTVIE(NPODataMidEmbedIE):
618 _VALID_URL = r'https?://(?:www\.)?schooltv\.nl/video/(?P<id>[^/?#&]+)'
621 'url': 'http://www.schooltv.nl/video/ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam/',
623 'id': 'WO_NTR_429477',
624 'display_id': 'ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam',
625 'title': 'Ademhaling: De hele dag haal je adem. Maar wat gebeurt er dan eigenlijk in je lichaam?',
627 'description': 'md5:abfa0ff690adb73fd0297fd033aaa631'
630 # Skip because of m3u8 download
631 'skip_download': True
636 class HetKlokhuisIE(NPODataMidEmbedIE):
637 IE_NAME = 'hetklokhuis'
638 _VALID_URL = r'https?://(?:www\.)?hetklokhuis\.nl/[^/]+/\d+/(?P<id>[^/?#&]+)'
641 'url': 'http://hetklokhuis.nl/tv-uitzending/3471/Zwaartekrachtsgolven',
643 'id': 'VPWON_1260528',
644 'display_id': 'Zwaartekrachtsgolven',
646 'title': 'Het Klokhuis: Zwaartekrachtsgolven',
647 'description': 'md5:c94f31fb930d76c2efa4a4a71651dd48',
648 'upload_date': '20170223',
651 'skip_download': True
656 class NPOPlaylistBaseIE(NPOIE):
657 def _real_extract(self, url):
658 playlist_id = self._match_id(url)
660 webpage = self._download_webpage(url, playlist_id)
663 self.url_result('npo:%s' % video_id if not video_id.startswith('http') else video_id)
664 for video_id in orderedSet(re.findall(self._PLAYLIST_ENTRY_RE, webpage))
667 playlist_title = self._html_search_regex(
668 self._PLAYLIST_TITLE_RE, webpage, 'playlist title',
669 default=None) or self._og_search_title(webpage)
671 return self.playlist_result(entries, playlist_id, playlist_title)
674 class VPROIE(NPOPlaylistBaseIE):
676 _VALID_URL = r'https?://(?:www\.)?(?:(?:tegenlicht\.)?vpro|2doc)\.nl/(?:[^/]+/)*(?P<id>[^/]+)\.html'
677 _PLAYLIST_TITLE_RE = (r'<h1[^>]+class=["\'].*?
\bmedia
-platform
-title
\b.*?
["\'][^>]*>([^<]+)',
678 r'<h5[^>]+class=["\'].*?
\bmedia
-platform
-subtitle
\b.*?
["\'][^>]*>([^<]+)')
679 _PLAYLIST_ENTRY_RE = r'data-media-id="([^
"]+)"'
683 'url
': 'http
://tegenlicht
.vpro
.nl
/afleveringen
/2012-2013/de
-toekomst
-komt
-uit
-afrika
.html
',
684 'md5
': 'f8065e4e5a7824068ed3c7e783178f2c
',
686 'id': 'VPWON_1169289
',
688 'title
': 'De toekomst komt uit Afrika
',
689 'description
': 'md5
:52cf4eefbc96fffcbdc06d024147abea
',
690 'upload_date
': '20130225',
692 'skip
': 'Video gone
',
695 'url
': 'http
://www
.vpro
.nl
/programmas
/2doc
/2015/sergio
-herman
.html
',
697 'id': 'sergio
-herman
',
698 'title
': 'sergio herman
: fucking perfect
',
703 # playlist with youtube embed
704 'url
': 'http
://www
.vpro
.nl
/programmas
/2doc
/2015/education
-education
.html
',
706 'id': 'education
-education
',
707 'title
': 'education education
',
712 'url
': 'http
://www
.2doc
.nl
/documentaires
/series
/2doc
/2015/oktober
/de
-tegenprestatie
.html
',
714 'id': 'de
-tegenprestatie
',
715 'title
': 'De Tegenprestatie
',
719 'url
': 'http
://www
.2doc
.nl
/speel~VARA_101375237~mh17
-het
-verdriet
-van
-nederland~
.html
',
721 'id': 'VARA_101375237
',
723 'title
': 'MH17
: Het verdriet van Nederland
',
724 'description
': 'md5
:09e1a37c1fdb144621e22479691a9f18
',
725 'upload_date
': '20150716',
728 # Skip because of m3u8 download
729 'skip_download
': True
735 class WNLIE(NPOPlaylistBaseIE):
737 _VALID_URL = r'https?
://(?
:www\
.)?omroepwnl\
.nl
/video
/detail
/(?P
<id>[^
/]+)__\d
+'
738 _PLAYLIST_TITLE_RE = r'(?s
)<h1
[^
>]+class="subject"[^
>]*>(.+?
)</h1
>'
739 _PLAYLIST_ENTRY_RE = r'<a
[^
>]+href
="([^"]+)"[^>]+class="js
-mid
"[^>]*>Deel \d+'
742 'url': 'http://www.omroepwnl.nl/video/detail/vandaag-de-dag-6-mei__060515',
744 'id': 'vandaag-de-dag-6-mei',
745 'title': 'Vandaag de Dag 6 mei',
751 class AndereTijdenIE(NPOPlaylistBaseIE):
752 IE_NAME = 'anderetijden'
753 _VALID_URL = r'https?://(?:www\.)?anderetijden\.nl/programma/(?:[^/]+/)+(?P<id>[^/?#&]+)'
754 _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class=["\'].*?
\bpage
-title
\b.*?
["\'][^>]*>(.+?)</h1>'
755 _PLAYLIST_ENTRY_RE = r'<figure[^>]+class=["\']episode
-container episode
-page
["\'][^>]+data-prid=["\'](.+?
)["\']'
758 'url': 'http://anderetijden.nl/programma/1/Andere-Tijden/aflevering/676/Duitse-soldaten-over-de-Slag-bij-Arnhem',
760 'id': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
761 'title': 'Duitse soldaten over de Slag bij Arnhem',