1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
22 class NPOBaseIE(InfoExtractor
):
23 def _get_token(self
, video_id
):
24 return self
._download
_json
(
25 'http://ida.omroep.nl/app.php/auth', video_id
,
26 note
='Downloading token')['token']
29 class NPOIE(NPOBaseIE
):
31 IE_DESC
= 'npo.nl and ntr.nl'
38 npo\.nl/(?!live|radio)(?:[^/]+/){2}|
39 ntr\.nl/(?:[^/]+/){2,}|
40 omroepwnl\.nl/video/fragment/[^/]+__|
48 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
49 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
51 'id': 'VPWON_1220719',
54 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
55 'upload_date': '20140622',
58 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
59 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
61 'id': 'VARA_101191800',
63 'title': 'De Mega Mike & Mega Thomas show: The best of.',
64 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
65 '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: Zwart geld. De toekomst komt uit Afrika',
75 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
76 'upload_date': '20130225',
80 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
82 'id': 'WO_VPRO_043706',
84 'title': 'De nieuwe mens - Deel 1',
85 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
89 'skip_download': True,
93 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
95 'id': 'WO_NOS_762771',
97 'title': 'Hoe gaat Europa verder na Parijs?',
100 'skip_download': True,
103 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
105 'id': 'VPWON_1233944',
107 'title': 'Aap, poot, pies',
108 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
109 'upload_date': '20150508',
113 'skip_download': True,
116 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
118 'id': 'POW_00996502',
120 'title': '''"Dit is wel een 'landslide'..."''',
121 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
122 'upload_date': '20150508',
126 'skip_download': True,
130 'url': 'http://www.npo.nl/jouw-stad-rotterdam/29-01-2017/RBX_FUNX_6683215/RBX_FUNX_7601437',
132 'id': 'RBX_FUNX_6683215',
134 'title': 'Jouw Stad Rotterdam',
135 'description': 'md5:db251505244f097717ec59fabc372d9f',
138 'skip_download': True,
141 'url': 'http://www.zapp.nl/de-bzt-show/gemist/KN_1687547',
142 'only_matching': True,
144 'url': 'http://www.zapp.nl/de-bzt-show/filmpjes/POMS_KN_7315118',
145 'only_matching': True,
147 'url': 'http://www.zapp.nl/beste-vrienden-quiz/extra-video-s/WO_NTR_1067990',
148 'only_matching': True,
151 'url': 'npo:LI_NL1_4188102',
152 'only_matching': True,
155 def _real_extract(self
, url
):
156 video_id
= self
._match
_id
(url
)
157 return self
._get
_info
(video_id
)
159 def _get_info(self
, video_id
):
160 metadata
= self
._download
_json
(
161 'http://e.omroep.nl/metadata/%s' % video_id
,
163 # We have to remove the javascript callback
164 transform_source
=strip_jsonp
,
167 # For some videos actual video id (prid) is different (e.g. for
168 # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
169 # video id is POMS_WNL_853698 but prid is POW_00996502)
170 video_id
= metadata
.get('prid') or video_id
172 # titel is too generic in some cases so utilize aflevering_titel as well
173 # when available (e.g. http://tegenlicht.vpro.nl/afleveringen/2014-2015/access-to-africa.html)
174 title
= metadata
['titel']
175 sub_title
= metadata
.get('aflevering_titel')
176 if sub_title
and sub_title
!= title
:
177 title
+= ': %s' % sub_title
179 token
= self
._get
_token
(video_id
)
184 quality
= qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
185 items
= self
._download
_json
(
186 'http://ida.omroep.nl/app.php/%s' % video_id
, video_id
,
187 'Downloading formats JSON', query
={
191 for num
, item
in enumerate(items
):
192 item_url
= item
.get('url')
193 if not item_url
or item_url
in urls
:
196 format_id
= self
._search
_regex
(
197 r
'video/ida/([^/]+)', item_url
, 'format id',
200 def add_format_url(format_url
):
203 'format_id': format_id
,
204 'quality': quality(format_id
),
207 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
208 if item
.get('contentType') in ('url', 'audio'):
209 add_format_url(item_url
)
213 stream_info
= self
._download
_json
(
214 item_url
+ '&type=json', video_id
,
215 'Downloading %s stream JSON'
216 % item
.get('label') or item
.get('format') or format_id
or num
)
217 except ExtractorError
as ee
:
218 if isinstance(ee
.cause
, compat_HTTPError
) and ee
.cause
.code
== 404:
219 error
= (self
._parse
_json
(
220 ee
.cause
.read().decode(), video_id
,
221 fatal
=False) or {}).get('errorstring')
223 raise ExtractorError(error
, expected
=True)
225 # Stream URL instead of JSON, example: npo:LI_NL1_4188102
226 if isinstance(stream_info
, compat_str
):
227 if not stream_info
.startswith('http'):
229 video_url
= stream_info
232 video_url
= stream_info
.get('url')
233 if not video_url
or video_url
in urls
:
236 if determine_ext(video_url
) == 'm3u8':
237 formats
.extend(self
._extract
_m
3u8_formats
(
238 video_url
, video_id
, ext
='mp4',
239 entry_protocol
='m3u8_native', m3u8_id
='hls', fatal
=False))
241 add_format_url(video_url
)
243 is_live
= metadata
.get('medium') == 'live'
246 for num
, stream
in enumerate(metadata
.get('streams', [])):
247 stream_url
= stream
.get('url')
248 if not stream_url
or stream_url
in urls
:
251 # smooth streaming is not supported
252 stream_type
= stream
.get('type', '').lower()
253 if stream_type
in ['ss', 'ms']:
255 if stream_type
== 'hds':
256 f4m_formats
= self
._extract
_f
4m
_formats
(
257 stream_url
, video_id
, fatal
=False)
258 # f4m downloader downloads only piece of live stream
259 for f4m_format
in f4m_formats
:
260 f4m_format
['preference'] = -1
261 formats
.extend(f4m_formats
)
262 elif stream_type
== 'hls':
263 formats
.extend(self
._extract
_m
3u8_formats
(
264 stream_url
, video_id
, ext
='mp4', fatal
=False))
265 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
266 elif '.asf' in stream_url
:
267 asx
= self
._download
_xml
(
268 stream_url
, video_id
,
269 'Downloading stream %d ASX playlist' % num
,
270 transform_source
=fix_xml_ampersands
, fatal
=False)
273 ref
= asx
.find('./ENTRY/Ref')
276 video_url
= ref
.get('href')
277 if not video_url
or video_url
in urls
:
282 'ext': stream
.get('formaat', 'asf'),
283 'quality': stream
.get('kwaliteit'),
289 'quality': stream
.get('kwaliteit'),
292 self
._sort
_formats
(formats
)
295 if metadata
.get('tt888') == 'ja':
298 'url': 'http://tt888.omroep.nl/tt888/%s' % video_id
,
303 'title': self
._live
_title
(title
) if is_live
else title
,
304 'description': metadata
.get('info'),
305 'thumbnail': metadata
.get('images', [{'url': None}])[-1]['url'],
306 'upload_date': unified_strdate(metadata
.get('gidsdatum')),
307 'duration': parse_duration(metadata
.get('tijdsduur')),
309 'subtitles': subtitles
,
314 class NPOLiveIE(NPOBaseIE
):
315 IE_NAME
= 'npo.nl:live'
316 _VALID_URL
= r
'https?://(?:www\.)?npo\.nl/live(?:/(?P<id>[^/?#&]+))?'
319 'url': 'http://www.npo.nl/live/npo-1',
321 'id': 'LI_NL1_4188102',
322 'display_id': 'npo-1',
324 'title': 're:^NPO 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
328 'skip_download': True,
331 'url': 'http://www.npo.nl/live',
332 'only_matching': True,
335 def _real_extract(self
, url
):
336 display_id
= self
._match
_id
(url
) or 'npo-1'
338 webpage
= self
._download
_webpage
(url
, display_id
)
340 live_id
= self
._search
_regex
(
341 r
'data-prid="([^"]+)"', webpage
, 'live id')
344 '_type': 'url_transparent',
345 'url': 'npo:%s' % live_id
,
346 'ie_key': NPOIE
.ie_key(),
348 'display_id': display_id
,
352 class NPORadioIE(InfoExtractor
):
353 IE_NAME
= 'npo.nl:radio'
354 _VALID_URL
= r
'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
357 'url': 'http://www.npo.nl/radio/radio-1',
361 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
365 'skip_download': True,
370 def _html_get_attribute_regex(attribute
):
371 return r
'{0}\s*=\s*\'([^
\']+)\''.format(attribute)
373 def _real_extract(self, url):
374 video_id = self._match_id(url)
376 webpage = self._download_webpage(url, video_id)
378 title = self._html_search_regex(
379 self._html_get_attribute_regex('data
-channel
'), webpage, 'title
')
381 stream = self._parse_json(
382 self._html_search_regex(self._html_get_attribute_regex('data
-streams
'), webpage, 'data
-streams
'),
385 codec = stream.get('codec
')
389 'url
': stream['url
'],
390 'title
': self._live_title(title),
397 class NPORadioFragmentIE(InfoExtractor):
398 IE_NAME = 'npo
.nl
:radio
:fragment
'
399 _VALID_URL = r'https?
://(?
:www\
.)?npo\
.nl
/radio
/[^
/]+/fragment
/(?P
<id>\d
+)'
402 'url
': 'http
://www
.npo
.nl
/radio
/radio
-5/fragment
/174356',
403 'md5
': 'dd8cc470dad764d0fdc70a9a1e2d18c2
',
407 'title
': 'Jubileumconcert Willeke Alberti
',
411 def _real_extract(self, url):
412 audio_id = self._match_id(url)
414 webpage = self._download_webpage(url, audio_id)
416 title = self._html_search_regex(
417 r'href
="/radio/[^/]+/fragment/%s" title
="([^"]+)"' % audio_id,
420 audio_url = self._search_regex(
421 r"data
-streams
='([^']+)'", webpage, 'audio url
')
430 class NPODataMidEmbedIE(InfoExtractor):
431 def _real_extract(self, url):
432 display_id = self._match_id(url)
433 webpage = self._download_webpage(url, display_id)
434 video_id = self._search_regex(
435 r'data
-mid
=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video_id', group='id')
437 '_type': 'url_transparent',
439 'url': 'npo:%s' % video_id,
440 'display_id': display_id
444 class SchoolTVIE(NPODataMidEmbedIE):
446 _VALID_URL = r'https?://(?:www\.)?schooltv\.nl/video/(?P<id>[^/?#&]+)'
449 'url': 'http://www.schooltv.nl/video/ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam/',
451 'id': 'WO_NTR_429477',
452 'display_id': 'ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam',
453 'title': 'Ademhaling: De hele dag haal je adem. Maar wat gebeurt er dan eigenlijk in je lichaam?',
455 'description': 'md5:abfa0ff690adb73fd0297fd033aaa631'
458 # Skip because of m3u8 download
459 'skip_download': True
464 class HetKlokhuisIE(NPODataMidEmbedIE):
465 IE_NAME = 'hetklokhuis'
466 _VALID_URL = r'https?://(?:www\.)?hetklokhuis.nl/[^/]+/\d+/(?P<id>[^/?#&]+)'
469 'url': 'http://hetklokhuis.nl/tv-uitzending/3471/Zwaartekrachtsgolven',
471 'id': 'VPWON_1260528',
472 'display_id': 'Zwaartekrachtsgolven',
474 'title': 'Het Klokhuis: Zwaartekrachtsgolven',
475 'description': 'md5:c94f31fb930d76c2efa4a4a71651dd48',
476 'upload_date': '20170223',
479 'skip_download': True
484 class NPOPlaylistBaseIE(NPOIE):
485 def _real_extract(self, url):
486 playlist_id = self._match_id(url)
488 webpage = self._download_webpage(url, playlist_id)
491 self.url_result('npo:%s' % video_id if not video_id.startswith('http') else video_id)
492 for video_id in orderedSet(re.findall(self._PLAYLIST_ENTRY_RE, webpage))
495 playlist_title = self._html_search_regex(
496 self._PLAYLIST_TITLE_RE, webpage, 'playlist title',
497 default=None) or self._og_search_title(webpage)
499 return self.playlist_result(entries, playlist_id, playlist_title)
502 class VPROIE(NPOPlaylistBaseIE):
504 _VALID_URL = r'https?://(?:www\.)?(?:(?:tegenlicht\.)?vpro|2doc)\.nl/(?:[^/]+/)*(?P<id>[^/]+)\.html'
505 _PLAYLIST_TITLE_RE = (r'<h1[^>]+class=["\'].*?
\bmedia
-platform
-title
\b.*?
["\'][^>]*>([^<]+)',
506 r'<h5[^>]+class=["\'].*?
\bmedia
-platform
-subtitle
\b.*?
["\'][^>]*>([^<]+)')
507 _PLAYLIST_ENTRY_RE = r'data-media-id="([^
"]+)"'
511 'url
': 'http
://tegenlicht
.vpro
.nl
/afleveringen
/2012-2013/de
-toekomst
-komt
-uit
-afrika
.html
',
512 'md5
': 'f8065e4e5a7824068ed3c7e783178f2c
',
514 'id': 'VPWON_1169289
',
516 'title
': 'De toekomst komt uit Afrika
',
517 'description
': 'md5
:52cf4eefbc96fffcbdc06d024147abea
',
518 'upload_date
': '20130225',
520 'skip
': 'Video gone
',
523 'url
': 'http
://www
.vpro
.nl
/programmas
/2doc
/2015/sergio
-herman
.html
',
525 'id': 'sergio
-herman
',
526 'title
': 'sergio herman
: fucking perfect
',
531 # playlist with youtube embed
532 'url
': 'http
://www
.vpro
.nl
/programmas
/2doc
/2015/education
-education
.html
',
534 'id': 'education
-education
',
535 'title
': 'education education
',
540 'url
': 'http
://www
.2doc
.nl
/documentaires
/series
/2doc
/2015/oktober
/de
-tegenprestatie
.html
',
542 'id': 'de
-tegenprestatie
',
543 'title
': 'De Tegenprestatie
',
547 'url
': 'http
://www
.2doc
.nl
/speel~VARA_101375237~mh17
-het
-verdriet
-van
-nederland~
.html
',
549 'id': 'VARA_101375237
',
551 'title
': 'MH17
: Het verdriet van Nederland
',
552 'description
': 'md5
:09e1a37c1fdb144621e22479691a9f18
',
553 'upload_date
': '20150716',
556 # Skip because of m3u8 download
557 'skip_download
': True
563 class WNLIE(NPOPlaylistBaseIE):
565 _VALID_URL = r'https?
://(?
:www\
.)?omroepwnl\
.nl
/video
/detail
/(?P
<id>[^
/]+)__\d
+'
566 _PLAYLIST_TITLE_RE = r'(?s
)<h1
[^
>]+class="subject"[^
>]*>(.+?
)</h1
>'
567 _PLAYLIST_ENTRY_RE = r'<a
[^
>]+href
="([^"]+)"[^>]+class="js
-mid
"[^>]*>Deel \d+'
570 'url': 'http://www.omroepwnl.nl/video/detail/vandaag-de-dag-6-mei__060515',
572 'id': 'vandaag-de-dag-6-mei',
573 'title': 'Vandaag de Dag 6 mei',
579 class AndereTijdenIE(NPOPlaylistBaseIE):
580 IE_NAME = 'anderetijden'
581 _VALID_URL = r'https?://(?:www\.)?anderetijden\.nl/programma/(?:[^/]+/)+(?P<id>[^/?#&]+)'
582 _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class=["\'].*?
\bpage
-title
\b.*?
["\'][^>]*>(.+?)</h1>'
583 _PLAYLIST_ENTRY_RE = r'<figure[^>]+class=["\']episode
-container episode
-page
["\'][^>]+data-prid=["\'](.+?
)["\']'
586 'url': 'http://anderetijden.nl/programma/1/Andere-Tijden/aflevering/676/Duitse-soldaten-over-de-Slag-bij-Arnhem',
588 'id': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
589 'title': 'Duitse soldaten over de Slag bij Arnhem',