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