]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/npo.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / npo.py
CommitLineData
525daedd
S
1import re
2
171ca612 3from .common import InfoExtractor
83e8fce6
S
4from ..compat import (
5 compat_HTTPError,
6 compat_str,
7)
331ae266 8from ..utils import (
83e8fce6
S
9 determine_ext,
10 ExtractorError,
5c4a81d9 11 fix_xml_ampersands,
ee706f10 12 int_or_none,
ff60ec8f 13 merge_dicts,
5742c18b 14 orderedSet,
944a3de2 15 parse_duration,
c9ea760e 16 qualities,
ff60ec8f 17 str_or_none,
609a61e3 18 strip_jsonp,
5c4a81d9 19 unified_strdate,
ff60ec8f
S
20 unified_timestamp,
21 url_or_none,
22 urlencode_postdata,
331ae266
JMF
23)
24
25
b9b42f2e 26class NPOBaseIE(InfoExtractor):
04e0bac2 27 def _get_token(self, video_id):
aa9cc2ec
S
28 return self._download_json(
29 'http://ida.omroep.nl/app.php/auth', video_id,
30 note='Downloading token')['token']
04e0bac2
S
31
32
33class NPOIE(NPOBaseIE):
e118031e 34 IE_NAME = 'npo'
359aa2fd 35 IE_DESC = 'npo.nl, ntr.nl, omroepwnl.nl, zapp.nl and npo3.nl'
525daedd 36 _VALID_URL = r'''(?x)
03f32a7e
S
37 (?:
38 npo:|
39 https?://
40 (?:www\.)?
41 (?:
9d581efe
S
42 npo\.nl/(?:[^/]+/)*|
43 (?:ntr|npostart)\.nl/(?:[^/]+/){2,}|
f264c623 44 omroepwnl\.nl/video/fragment/[^/]+__|
c4e74964 45 (?:zapp|npo3)\.nl/(?:[^/]+/){2,}
03f32a7e 46 )
525daedd
S
47 )
48 (?P<id>[^/?#]+)
49 '''
331ae266 50
83e8fce6
S
51 _TESTS = [{
52 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
53 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
54 'info_dict': {
55 'id': 'VPWON_1220719',
56 'ext': 'm4v',
57 'title': 'Nieuwsuur',
58 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
59 'upload_date': '20140622',
331ae266 60 },
83e8fce6
S
61 }, {
62 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
63 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
64 'info_dict': {
65 'id': 'VARA_101191800',
66 'ext': 'm4v',
67 'title': 'De Mega Mike & Mega Thomas show: The best of.',
68 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
69 'upload_date': '20090227',
70 'duration': 2400,
944a3de2 71 },
83e8fce6
S
72 }, {
73 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
74 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
75 'info_dict': {
76 'id': 'VPWON_1169289',
77 'ext': 'm4v',
78 'title': 'Tegenlicht: Zwart geld. De toekomst komt uit Afrika',
79 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
80 'upload_date': '20130225',
81 'duration': 3000,
1ff30d7b 82 },
83e8fce6
S
83 }, {
84 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
85 'info_dict': {
86 'id': 'WO_VPRO_043706',
87 'ext': 'm4v',
88 'title': 'De nieuwe mens - Deel 1',
89 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
90 'duration': 4680,
1ff30d7b 91 },
83e8fce6
S
92 'params': {
93 'skip_download': True,
94 }
95 }, {
c85f3683 96 # non asf in streams
83e8fce6
S
97 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
98 'info_dict': {
99 'id': 'WO_NOS_762771',
100 'ext': 'mp4',
101 'title': 'Hoe gaat Europa verder na Parijs?',
f264c623 102 },
83e8fce6
S
103 'params': {
104 'skip_download': True,
105 }
106 }, {
107 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
108 'info_dict': {
109 'id': 'VPWON_1233944',
110 'ext': 'm4v',
111 'title': 'Aap, poot, pies',
112 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
113 'upload_date': '20150508',
114 'duration': 599,
f264c623 115 },
83e8fce6
S
116 'params': {
117 'skip_download': True,
118 }
119 }, {
120 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
121 'info_dict': {
122 'id': 'POW_00996502',
123 'ext': 'm4v',
124 'title': '''"Dit is wel een 'landslide'..."''',
125 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
126 'upload_date': '20150508',
127 'duration': 462,
18abb743 128 },
83e8fce6
S
129 'params': {
130 'skip_download': True,
e118031e 131 }
4b8a984c
S
132 }, {
133 # audio
134 'url': 'http://www.npo.nl/jouw-stad-rotterdam/29-01-2017/RBX_FUNX_6683215/RBX_FUNX_7601437',
135 'info_dict': {
136 'id': 'RBX_FUNX_6683215',
137 'ext': 'mp3',
138 'title': 'Jouw Stad Rotterdam',
139 'description': 'md5:db251505244f097717ec59fabc372d9f',
140 },
141 'params': {
142 'skip_download': True,
143 }
83e8fce6
S
144 }, {
145 'url': 'http://www.zapp.nl/de-bzt-show/gemist/KN_1687547',
146 'only_matching': True,
147 }, {
148 'url': 'http://www.zapp.nl/de-bzt-show/filmpjes/POMS_KN_7315118',
149 'only_matching': True,
150 }, {
151 'url': 'http://www.zapp.nl/beste-vrienden-quiz/extra-video-s/WO_NTR_1067990',
152 'only_matching': True,
359aa2fd 153 }, {
154 'url': 'https://www.npo3.nl/3onderzoekt/16-09-2015/VPWON_1239870',
155 'only_matching': True,
83e8fce6
S
156 }, {
157 # live stream
158 'url': 'npo:LI_NL1_4188102',
159 'only_matching': True,
7dd5415c
S
160 }, {
161 'url': 'http://www.npo.nl/radio-gaga/13-06-2017/BNN_101383373',
162 'only_matching': True,
c4e74964
S
163 }, {
164 'url': 'https://www.zapp.nl/1803-skelterlab/instructie-video-s/740-instructievideo-s/POMS_AT_11736927',
165 'only_matching': True,
9d581efe
S
166 }, {
167 'url': 'https://www.npostart.nl/broodje-gezond-ei/28-05-2018/KN_1698996',
168 'only_matching': True,
169 }, {
170 'url': 'https://npo.nl/KN_1698996',
171 'only_matching': True,
83e8fce6 172 }]
331ae266 173
9d581efe
S
174 @classmethod
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))
179
331ae266 180 def _real_extract(self, url):
04e0bac2 181 video_id = self._match_id(url)
8cb10807 182 return self._get_info(url, video_id) or self._get_old_info(video_id)
331ae266 183
ff60ec8f
S
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={
188 'Referer': url,
189 'X-Requested-With': 'XMLHttpRequest',
190 })['token']
191
192 player = self._download_json(
193 'https://www.npostart.nl/player/%s' % video_id, video_id,
194 'Downloading player JSON', data=urlencode_postdata({
195 'autoplay': 0,
196 'share': 1,
197 'pageUrl': url,
198 'hasAdConsent': 0,
199 '_token': token,
200 }))
201
202 player_token = player['token']
203
8cb10807 204 drm = False
ff60ec8f
S
205 format_urls = set()
206 formats = []
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,
211 query={
212 'profile': profile,
213 'quality': 'npo',
214 'tokenId': player_token,
215 'streamType': 'broadcast',
216 })
217 if not streams:
218 continue
219 stream = streams.get('stream')
220 if not isinstance(stream, dict):
221 continue
222 stream_url = url_or_none(stream.get('src'))
223 if not stream_url or stream_url in format_urls:
224 continue
225 format_urls.add(stream_url)
8cb10807
S
226 if stream.get('protection') is not None or stream.get('keySystemOptions') is not None:
227 drm = True
ff60ec8f
S
228 continue
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_m3u8_formats(
236 stream_url, video_id, ext='mp4',
237 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
bb6f112d 238 elif re.search(r'\.isml?/Manifest', stream_url):
ff60ec8f
S
239 formats.extend(self._extract_ism_formats(
240 stream_url, video_id, ism_id='mss', fatal=False))
241 else:
242 formats.append({
243 'url': stream_url,
244 })
245
8cb10807 246 if not formats:
a06916d9 247 if not self.get_param('allow_unplayable_formats') and drm:
88acdbc2 248 self.report_drm(video_id)
8cb10807 249
ff60ec8f
S
250 info = {
251 'id': video_id,
252 'title': video_id,
253 'formats': formats,
254 }
255
256 embed_url = url_or_none(player.get('embedUrl'))
257 if embed_url:
258 webpage = self._download_webpage(
259 embed_url, video_id, 'Downloading embed page', fatal=False)
260 if webpage:
261 video = self._parse_json(
262 self._search_regex(
263 r'\bvideo\s*=\s*({.+?})\s*;', webpage, 'video',
264 default='{}'), video_id)
265 if video:
266 title = video.get('episodeTitle')
267 subtitles = {}
268 subtitles_list = video.get('subtitles')
269 if isinstance(subtitles_list, list):
270 for cc in subtitles_list:
271 cc_url = url_or_none(cc.get('src'))
272 if not cc_url:
273 continue
274 lang = str_or_none(cc.get('language')) or 'nl'
275 subtitles.setdefault(lang, []).append({
276 'url': cc_url,
277 })
278 return merge_dicts({
279 'title': title,
280 'description': video.get('description'),
281 'thumbnail': url_or_none(
282 video.get('still_image_url') or video.get('orig_image_url')),
283 'duration': int_or_none(video.get('duration')),
284 'timestamp': unified_timestamp(video.get('broadcastDate')),
285 'creator': video.get('channel'),
286 'series': video.get('title'),
287 'episode': title,
288 'episode_number': int_or_none(video.get('episodeNumber')),
289 'subtitles': subtitles,
290 }, info)
291
292 return info
293
294 def _get_old_info(self, video_id):
331ae266 295 metadata = self._download_json(
8d06a624 296 'http://e.omroep.nl/metadata/%s' % video_id,
331ae266
JMF
297 video_id,
298 # We have to remove the javascript callback
609a61e3 299 transform_source=strip_jsonp,
331ae266 300 )
04e0bac2 301
b8adcec4
S
302 error = metadata.get('error')
303 if error:
304 raise ExtractorError(error, expected=True)
305
525daedd
S
306 # For some videos actual video id (prid) is different (e.g. for
307 # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
308 # video id is POMS_WNL_853698 but prid is POW_00996502)
309 video_id = metadata.get('prid') or video_id
310
23fc384f
S
311 # titel is too generic in some cases so utilize aflevering_titel as well
312 # when available (e.g. http://tegenlicht.vpro.nl/afleveringen/2014-2015/access-to-africa.html)
313 title = metadata['titel']
314 sub_title = metadata.get('aflevering_titel')
315 if sub_title and sub_title != title:
316 title += ': %s' % sub_title
317
04e0bac2 318 token = self._get_token(video_id)
331ae266 319
c9ea760e 320 formats = []
83e8fce6
S
321 urls = set()
322
d1b61870
S
323 def is_legal_url(format_url):
324 return format_url and format_url not in urls and re.match(
325 r'^(?:https?:)?//', format_url)
326
ee706f10
S
327 QUALITY_LABELS = ('Laag', 'Normaal', 'Hoog')
328 QUALITY_FORMATS = ('adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std')
329
330 quality_from_label = qualities(QUALITY_LABELS)
331 quality_from_format_id = qualities(QUALITY_FORMATS)
83e8fce6
S
332 items = self._download_json(
333 'http://ida.omroep.nl/app.php/%s' % video_id, video_id,
334 'Downloading formats JSON', query={
335 'adaptive': 'yes',
336 'token': token,
337 })['items'][0]
338 for num, item in enumerate(items):
339 item_url = item.get('url')
d1b61870 340 if not is_legal_url(item_url):
83e8fce6
S
341 continue
342 urls.add(item_url)
343 format_id = self._search_regex(
344 r'video/ida/([^/]+)', item_url, 'format id',
345 default=None)
346
ee706f10
S
347 item_label = item.get('label')
348
83e8fce6 349 def add_format_url(format_url):
ee706f10
S
350 width = int_or_none(self._search_regex(
351 r'(\d+)[xX]\d+', format_url, 'width', default=None))
352 height = int_or_none(self._search_regex(
353 r'\d+[xX](\d+)', format_url, 'height', default=None))
354 if item_label in QUALITY_LABELS:
355 quality = quality_from_label(item_label)
356 f_id = item_label
357 elif item_label in QUALITY_FORMATS:
358 quality = quality_from_format_id(format_id)
359 f_id = format_id
360 else:
5616caf8 361 quality, f_id = [None] * 2
83e8fce6
S
362 formats.append({
363 'url': format_url,
ee706f10
S
364 'format_id': f_id,
365 'width': width,
366 'height': height,
367 'quality': quality,
83e8fce6 368 })
1ff30d7b 369
83e8fce6 370 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
4b8a984c 371 if item.get('contentType') in ('url', 'audio'):
83e8fce6
S
372 add_format_url(item_url)
373 continue
374
375 try:
376 stream_info = self._download_json(
377 item_url + '&type=json', video_id,
378 'Downloading %s stream JSON'
ee706f10 379 % item_label or item.get('format') or format_id or num)
83e8fce6
S
380 except ExtractorError as ee:
381 if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 404:
382 error = (self._parse_json(
383 ee.cause.read().decode(), video_id,
384 fatal=False) or {}).get('errorstring')
385 if error:
386 raise ExtractorError(error, expected=True)
387 raise
388 # Stream URL instead of JSON, example: npo:LI_NL1_4188102
389 if isinstance(stream_info, compat_str):
390 if not stream_info.startswith('http'):
aa9cc2ec 391 continue
83e8fce6
S
392 video_url = stream_info
393 # JSON
394 else:
aa9cc2ec 395 video_url = stream_info.get('url')
ff60ec8f 396 if not video_url or 'vodnotavailable.' in video_url or video_url in urls:
83e8fce6 397 continue
2160768a 398 urls.add(video_url)
83e8fce6
S
399 if determine_ext(video_url) == 'm3u8':
400 formats.extend(self._extract_m3u8_formats(
401 video_url, video_id, ext='mp4',
402 entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
403 else:
404 add_format_url(video_url)
405
406 is_live = metadata.get('medium') == 'live'
407
408 if not is_live:
409 for num, stream in enumerate(metadata.get('streams', [])):
410 stream_url = stream.get('url')
d1b61870 411 if not is_legal_url(stream_url):
1ff30d7b 412 continue
83e8fce6
S
413 urls.add(stream_url)
414 # smooth streaming is not supported
415 stream_type = stream.get('type', '').lower()
416 if stream_type in ['ss', 'ms']:
417 continue
418 if stream_type == 'hds':
419 f4m_formats = self._extract_f4m_formats(
420 stream_url, video_id, fatal=False)
421 # f4m downloader downloads only piece of live stream
422 for f4m_format in f4m_formats:
f983b875 423 f4m_format['preference'] = -5
83e8fce6
S
424 formats.extend(f4m_formats)
425 elif stream_type == 'hls':
aa9cc2ec 426 formats.extend(self._extract_m3u8_formats(
83e8fce6
S
427 stream_url, video_id, ext='mp4', fatal=False))
428 # Example: http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706
429 elif '.asf' in stream_url:
430 asx = self._download_xml(
431 stream_url, video_id,
432 'Downloading stream %d ASX playlist' % num,
433 transform_source=fix_xml_ampersands, fatal=False)
434 if not asx:
435 continue
436 ref = asx.find('./ENTRY/Ref')
437 if ref is None:
438 continue
439 video_url = ref.get('href')
440 if not video_url or video_url in urls:
441 continue
442 urls.add(video_url)
1ff30d7b
S
443 formats.append({
444 'url': video_url,
83e8fce6
S
445 'ext': stream.get('formaat', 'asf'),
446 'quality': stream.get('kwaliteit'),
447 'preference': -10,
1ff30d7b 448 })
83e8fce6 449 else:
a0977064
S
450 formats.append({
451 'url': stream_url,
452 'quality': stream.get('kwaliteit'),
453 })
1ff30d7b 454
9e91449c
S
455 subtitles = {}
456 if metadata.get('tt888') == 'ja':
b9b42f2e
JMF
457 subtitles['nl'] = [{
458 'ext': 'vtt',
56fc078d 459 'url': 'http://tt888.omroep.nl/tt888/%s' % video_id,
b9b42f2e 460 }]
331ae266
JMF
461
462 return {
463 'id': video_id,
39ca3b5c 464 'title': title,
536b0700 465 'description': metadata.get('info'),
944a3de2
S
466 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
467 'upload_date': unified_strdate(metadata.get('gidsdatum')),
468 'duration': parse_duration(metadata.get('tijdsduur')),
c9ea760e 469 'formats': formats,
25e5ebf3 470 'subtitles': subtitles,
83e8fce6 471 'is_live': is_live,
331ae266 472 }
d0df9292
JMF
473
474
04e0bac2
S
475class NPOLiveIE(NPOBaseIE):
476 IE_NAME = 'npo.nl:live'
4e1ddc8d 477 _VALID_URL = r'https?://(?:www\.)?npo(?:start)?\.nl/live(?:/(?P<id>[^/?#&]+))?'
04e0bac2 478
1591ba25 479 _TESTS = [{
04e0bac2
S
480 'url': 'http://www.npo.nl/live/npo-1',
481 'info_dict': {
83e8fce6 482 'id': 'LI_NL1_4188102',
04e0bac2
S
483 'display_id': 'npo-1',
484 'ext': 'mp4',
83e8fce6 485 'title': 're:^NPO 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
04e0bac2
S
486 'is_live': True,
487 },
488 'params': {
489 'skip_download': True,
490 }
1591ba25
AG
491 }, {
492 'url': 'http://www.npo.nl/live',
04e431cf 493 'only_matching': True,
4e1ddc8d
S
494 }, {
495 'url': 'https://www.npostart.nl/live/npo-1',
496 'only_matching': True,
1591ba25 497 }]
04e0bac2
S
498
499 def _real_extract(self, url):
1591ba25 500 display_id = self._match_id(url) or 'npo-1'
04e0bac2
S
501
502 webpage = self._download_webpage(url, display_id)
503
504 live_id = self._search_regex(
7a577309 505 [r'media-id="([^"]+)"', r'data-prid="([^"]+)"'], webpage, 'live id')
04e0bac2 506
04e0bac2 507 return {
83e8fce6
S
508 '_type': 'url_transparent',
509 'url': 'npo:%s' % live_id,
510 'ie_key': NPOIE.ie_key(),
04e0bac2
S
511 'id': live_id,
512 'display_id': display_id,
04e0bac2
S
513 }
514
515
171ca612
S
516class NPORadioIE(InfoExtractor):
517 IE_NAME = 'npo.nl:radio'
9d581efe 518 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)'
171ca612
S
519
520 _TEST = {
521 'url': 'http://www.npo.nl/radio/radio-1',
522 'info_dict': {
523 'id': 'radio-1',
524 'ext': 'mp3',
525 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
526 'is_live': True,
527 },
528 'params': {
529 'skip_download': True,
530 }
531 }
532
9d581efe
S
533 @classmethod
534 def suitable(cls, url):
535 return False if NPORadioFragmentIE.suitable(url) else super(NPORadioIE, cls).suitable(url)
536
171ca612
S
537 @staticmethod
538 def _html_get_attribute_regex(attribute):
539 return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
540
541 def _real_extract(self, url):
542 video_id = self._match_id(url)
543
544 webpage = self._download_webpage(url, video_id)
545
546 title = self._html_search_regex(
547 self._html_get_attribute_regex('data-channel'), webpage, 'title')
548
549 stream = self._parse_json(
550 self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
551 video_id)
552
553 codec = stream.get('codec')
554
555 return {
556 'id': video_id,
557 'url': stream['url'],
39ca3b5c 558 'title': title,
171ca612
S
559 'acodec': codec,
560 'ext': codec,
561 'is_live': True,
562 }
563
564
565class NPORadioFragmentIE(InfoExtractor):
566 IE_NAME = 'npo.nl:radio:fragment'
567 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
568
569 _TEST = {
570 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
571 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
572 'info_dict': {
573 'id': '174356',
574 'ext': 'mp3',
575 'title': 'Jubileumconcert Willeke Alberti',
576 },
577 }
578
579 def _real_extract(self, url):
580 audio_id = self._match_id(url)
581
582 webpage = self._download_webpage(url, audio_id)
583
584 title = self._html_search_regex(
585 r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
586 webpage, 'title')
587
588 audio_url = self._search_regex(
589 r"data-streams='([^']+)'", webpage, 'audio url')
590
591 return {
592 'id': audio_id,
593 'url': audio_url,
594 'title': title,
595 }
596
597
6368e2e6 598class NPODataMidEmbedIE(InfoExtractor): # XXX: Conventionally, base classes should end with BaseIE/InfoExtractor
0dc5a86a
S
599 def _real_extract(self, url):
600 display_id = self._match_id(url)
601 webpage = self._download_webpage(url, display_id)
602 video_id = self._search_regex(
603 r'data-mid=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video_id', group='id')
604 return {
605 '_type': 'url_transparent',
606 'ie_key': 'NPO',
607 'url': 'npo:%s' % video_id,
608 'display_id': display_id
609 }
610
611
612class SchoolTVIE(NPODataMidEmbedIE):
89f26028 613 IE_NAME = 'schooltv'
614 _VALID_URL = r'https?://(?:www\.)?schooltv\.nl/video/(?P<id>[^/?#&]+)'
615
616 _TEST = {
617 'url': 'http://www.schooltv.nl/video/ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam/',
618 'info_dict': {
619 'id': 'WO_NTR_429477',
620 'display_id': 'ademhaling-de-hele-dag-haal-je-adem-maar-wat-gebeurt-er-dan-eigenlijk-in-je-lichaam',
621 'title': 'Ademhaling: De hele dag haal je adem. Maar wat gebeurt er dan eigenlijk in je lichaam?',
622 'ext': 'mp4',
623 'description': 'md5:abfa0ff690adb73fd0297fd033aaa631'
624 },
625 'params': {
626 # Skip because of m3u8 download
627 'skip_download': True
628 }
629 }
630
0dc5a86a
S
631
632class HetKlokhuisIE(NPODataMidEmbedIE):
dbc01fdb 633 IE_NAME = 'hetklokhuis'
197224b7 634 _VALID_URL = r'https?://(?:www\.)?hetklokhuis\.nl/[^/]+/\d+/(?P<id>[^/?#&]+)'
0dc5a86a
S
635
636 _TEST = {
637 'url': 'http://hetklokhuis.nl/tv-uitzending/3471/Zwaartekrachtsgolven',
638 'info_dict': {
639 'id': 'VPWON_1260528',
640 'display_id': 'Zwaartekrachtsgolven',
641 'ext': 'm4v',
642 'title': 'Het Klokhuis: Zwaartekrachtsgolven',
643 'description': 'md5:c94f31fb930d76c2efa4a4a71651dd48',
644 'upload_date': '20170223',
645 },
646 'params': {
647 'skip_download': True
89f26028 648 }
0dc5a86a 649 }
89f26028 650
651
6368e2e6 652class NPOPlaylistBaseIE(NPOIE): # XXX: Do not subclass from concrete IE
a3d8b381
S
653 def _real_extract(self, url):
654 playlist_id = self._match_id(url)
655
656 webpage = self._download_webpage(url, playlist_id)
657
658 entries = [
659 self.url_result('npo:%s' % video_id if not video_id.startswith('http') else video_id)
5742c18b 660 for video_id in orderedSet(re.findall(self._PLAYLIST_ENTRY_RE, webpage))
a3d8b381
S
661 ]
662
663 playlist_title = self._html_search_regex(
664 self._PLAYLIST_TITLE_RE, webpage, 'playlist title',
665 default=None) or self._og_search_title(webpage)
666
667 return self.playlist_result(entries, playlist_id, playlist_title)
668
669
670class VPROIE(NPOPlaylistBaseIE):
464e7924 671 IE_NAME = 'vpro'
b1d79888
S
672 _VALID_URL = r'https?://(?:www\.)?(?:(?:tegenlicht\.)?vpro|2doc)\.nl/(?:[^/]+/)*(?P<id>[^/]+)\.html'
673 _PLAYLIST_TITLE_RE = (r'<h1[^>]+class=["\'].*?\bmedia-platform-title\b.*?["\'][^>]*>([^<]+)',
674 r'<h5[^>]+class=["\'].*?\bmedia-platform-subtitle\b.*?["\'][^>]*>([^<]+)')
a3d8b381 675 _PLAYLIST_ENTRY_RE = r'data-media-id="([^"]+)"'
d0df9292
JMF
676
677 _TESTS = [
678 {
679 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
680 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
681 'info_dict': {
682 'id': 'VPWON_1169289',
683 'ext': 'm4v',
5ba761eb 684 'title': 'De toekomst komt uit Afrika',
611ac379 685 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
d0df9292
JMF
686 'upload_date': '20130225',
687 },
ddb19772 688 'skip': 'Video gone',
d0df9292 689 },
611ac379
S
690 {
691 'url': 'http://www.vpro.nl/programmas/2doc/2015/sergio-herman.html',
692 'info_dict': {
693 'id': 'sergio-herman',
ddb19772 694 'title': 'sergio herman: fucking perfect',
611ac379
S
695 },
696 'playlist_count': 2,
574f42d7
S
697 },
698 {
699 # playlist with youtube embed
700 'url': 'http://www.vpro.nl/programmas/2doc/2015/education-education.html',
701 'info_dict': {
702 'id': 'education-education',
ddb19772 703 'title': 'education education',
574f42d7
S
704 },
705 'playlist_count': 2,
b1d79888
S
706 },
707 {
708 'url': 'http://www.2doc.nl/documentaires/series/2doc/2015/oktober/de-tegenprestatie.html',
709 'info_dict': {
710 'id': 'de-tegenprestatie',
711 'title': 'De Tegenprestatie',
712 },
713 'playlist_count': 2,
714 }, {
715 'url': 'http://www.2doc.nl/speel~VARA_101375237~mh17-het-verdriet-van-nederland~.html',
716 'info_dict': {
717 'id': 'VARA_101375237',
718 'ext': 'm4v',
719 'title': 'MH17: Het verdriet van Nederland',
720 'description': 'md5:09e1a37c1fdb144621e22479691a9f18',
721 'upload_date': '20150716',
722 },
723 'params': {
724 # Skip because of m3u8 download
725 'skip_download': True
726 },
611ac379 727 }
d0df9292
JMF
728 ]
729
03f32a7e 730
a3d8b381 731class WNLIE(NPOPlaylistBaseIE):
f9dd86a1 732 IE_NAME = 'wnl'
03f32a7e 733 _VALID_URL = r'https?://(?:www\.)?omroepwnl\.nl/video/detail/(?P<id>[^/]+)__\d+'
a3d8b381
S
734 _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class="subject"[^>]*>(.+?)</h1>'
735 _PLAYLIST_ENTRY_RE = r'<a[^>]+href="([^"]+)"[^>]+class="js-mid"[^>]*>Deel \d+'
03f32a7e 736
a3d8b381 737 _TESTS = [{
03f32a7e
S
738 'url': 'http://www.omroepwnl.nl/video/detail/vandaag-de-dag-6-mei__060515',
739 'info_dict': {
740 'id': 'vandaag-de-dag-6-mei',
741 'title': 'Vandaag de Dag 6 mei',
742 },
743 'playlist_count': 4,
a3d8b381 744 }]
5742c18b
S
745
746
747class AndereTijdenIE(NPOPlaylistBaseIE):
f9dd86a1 748 IE_NAME = 'anderetijden'
5742c18b
S
749 _VALID_URL = r'https?://(?:www\.)?anderetijden\.nl/programma/(?:[^/]+/)+(?P<id>[^/?#&]+)'
750 _PLAYLIST_TITLE_RE = r'(?s)<h1[^>]+class=["\'].*?\bpage-title\b.*?["\'][^>]*>(.+?)</h1>'
751 _PLAYLIST_ENTRY_RE = r'<figure[^>]+class=["\']episode-container episode-page["\'][^>]+data-prid=["\'](.+?)["\']'
752
753 _TESTS = [{
754 'url': 'http://anderetijden.nl/programma/1/Andere-Tijden/aflevering/676/Duitse-soldaten-over-de-Slag-bij-Arnhem',
755 'info_dict': {
756 'id': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
757 'title': 'Duitse soldaten over de Slag bij Arnhem',
758 },
759 'playlist_count': 3,
760 }]