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