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