1 from __future__ import unicode_literals
3 from .common import InfoExtractor
14 class NPOBaseIE(InfoExtractor):
15 def _get_token(self, video_id):
16 token_page = self._download_webpage(
17 'http://ida.omroep.nl/npoplayer/i.js',
18 video_id, note='Downloading token')
19 token = self._search_regex(
20 r'npoplayer\.token = "(.+?)"', token_page, 'token')
21 # Decryption algorithm extracted from http://npoplayer.omroep.nl/csjs/npoplayer-min.js
24 for i in range(5, len(token_l) - 4):
25 if token_l[i].isdigit():
30 if first is None or second is None:
34 token_l[first], token_l[second] = token_l[second], token_l[first]
36 return ''.join(token_l)
39 class NPOIE(NPOBaseIE):
41 _VALID_URL = r'https?://(?:www\.)?npo\.nl/(?!live|radio)[^/]+/[^/]+/(?P<id>[^/?]+)'
45 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
46 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
48 'id': 'VPWON_1220719',
51 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
52 'upload_date': '20140622',
56 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
57 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
59 'id': 'VARA_101191800',
61 'title': 'De Mega Mike & Mega Thomas show',
62 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
63 'upload_date': '20090227',
68 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
69 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
71 'id': 'VPWON_1169289',
73 'title': 'Tegenlicht',
74 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
75 'upload_date': '20130225',
80 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
82 'id': 'WO_VPRO_043706',
84 'title': 'De nieuwe mens - Deel 1',
85 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
89 # mplayer mms download
90 'skip_download': True,
95 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
96 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
98 'id': 'WO_NOS_762771',
100 'title': 'Hoe gaat Europa verder na Parijs?',
105 def _real_extract(self, url):
106 video_id = self._match_id(url)
107 return self._get_info(video_id)
109 def _get_info(self, video_id):
110 metadata = self._download_json(
111 'http://e.omroep.nl/metadata/%s' % video_id,
113 # We have to remove the javascript callback
114 transform_source=strip_jsonp,
117 token = self._get_token(video_id)
121 pubopties = metadata.get('pubopties')
123 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
124 for format_id in pubopties:
125 format_info = self._download_json(
126 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
127 % (video_id, format_id, token),
128 video_id, 'Downloading %s JSON' % format_id)
129 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
131 streams = format_info.get('streams')
133 video_info = self._download_json(
134 streams[0] + '&type=json',
135 video_id, 'Downloading %s stream JSON' % format_id)
137 video_info = format_info
138 video_url = video_info.get('url')
141 if format_id == 'adaptive':
142 formats.extend(self._extract_m3u8_formats(video_url, video_id))
146 'format_id': format_id,
147 'quality': quality(format_id),
150 streams = metadata.get('streams')
152 for i, stream in enumerate(streams):
153 stream_url = stream.get('url')
156 if '.asf' not in stream_url:
159 'quality': stream.get('kwaliteit'),
162 asx = self._download_xml(
163 stream_url, video_id,
164 'Downloading stream %d ASX playlist' % i,
165 transform_source=fix_xml_ampersands)
166 ref = asx.find('./ENTRY/Ref')
169 video_url = ref.get('href')
174 'ext': stream.get('formaat', 'asf'),
175 'quality': stream.get('kwaliteit'),
178 self._sort_formats(formats)
181 if metadata.get('tt888') == 'ja':
184 'url': 'http://e.omroep.nl/tt888/%s' % video_id,
189 'title': metadata['titel'],
190 'description': metadata['info'],
191 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
192 'upload_date': unified_strdate(metadata.get('gidsdatum')),
193 'duration': parse_duration(metadata.get('tijdsduur')),
195 'subtitles': subtitles,
199 class NPOLiveIE(NPOBaseIE):
200 IE_NAME = 'npo.nl:live'
201 _VALID_URL = r'https?://(?:www\.)?npo\.nl/live/(?P<id>.+)'
204 'url': 'http://www.npo.nl/live/npo-1',
206 'id': 'LI_NEDERLAND1_136692',
207 'display_id': 'npo-1',
209 'title': 're:^Nederland 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
210 'description': 'Livestream',
214 'skip_download': True,
218 def _real_extract(self, url):
219 display_id = self._match_id(url)
221 webpage = self._download_webpage(url, display_id)
223 live_id = self._search_regex(
224 r'data-prid="([^"]+)"', webpage, 'live id')
226 metadata = self._download_json(
227 'http://e.omroep.nl/metadata/%s' % live_id,
228 display_id, transform_source=strip_jsonp)
230 token = self._get_token(display_id)
234 streams = metadata.get('streams')
236 for stream in streams:
237 stream_type = stream.get('type').lower()
238 # smooth streaming is not supported
239 if stream_type in ['ss', 'ms']:
241 stream_info = self._download_json(
242 'http://ida.omroep.nl/aapi/?stream=%s&token=%s&type=jsonp'
243 % (stream.get('url'), token),
244 display_id, 'Downloading %s JSON' % stream_type)
245 if stream_info.get('error_code', 0) or stream_info.get('errorcode', 0):
247 stream_url = self._download_json(
248 stream_info['stream'], display_id,
249 'Downloading %s URL' % stream_type,
250 'Unable to download %s URL' % stream_type,
251 transform_source=strip_jsonp, fatal=False)
254 if stream_type == 'hds':
255 f4m_formats = self._extract_f4m_formats(stream_url, display_id)
256 # f4m downloader downloads only piece of live stream
257 for f4m_format in f4m_formats:
258 f4m_format['preference'] = -1
259 formats.extend(f4m_formats)
260 elif stream_type == 'hls':
261 formats.extend(self._extract_m3u8_formats(stream_url, display_id, 'mp4'))
268 self._sort_formats(formats)
272 'display_id': display_id,
273 'title': self._live_title(metadata['titel']),
274 'description': metadata['info'],
275 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
281 class NPORadioIE(InfoExtractor):
282 IE_NAME = 'npo.nl:radio'
283 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
286 'url': 'http://www.npo.nl/radio/radio-1',
290 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
294 'skip_download': True,
299 def _html_get_attribute_regex(attribute):
300 return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
302 def _real_extract(self, url):
303 video_id = self._match_id(url)
305 webpage = self._download_webpage(url, video_id)
307 title = self._html_search_regex(
308 self._html_get_attribute_regex('data-channel'), webpage, 'title')
310 stream = self._parse_json(
311 self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
314 codec = stream.get('codec')
318 'url': stream['url'],
319 'title': self._live_title(title),
326 class NPORadioFragmentIE(InfoExtractor):
327 IE_NAME = 'npo.nl:radio:fragment'
328 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
331 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
332 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
336 'title': 'Jubileumconcert Willeke Alberti',
340 def _real_extract(self, url):
341 audio_id = self._match_id(url)
343 webpage = self._download_webpage(url, audio_id)
345 title = self._html_search_regex(
346 r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
349 audio_url = self._search_regex(
350 r"data-streams='([^']+)'", webpage, 'audio url')
359 class TegenlichtVproIE(NPOIE):
360 IE_NAME = 'tegenlicht.vpro.nl'
361 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
365 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
366 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
368 'id': 'VPWON_1169289',
370 'title': 'Tegenlicht',
371 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
372 'upload_date': '20130225',
377 def _real_extract(self, url):
378 name = url_basename(url)
379 webpage = self._download_webpage(url, name)
380 urn = self._html_search_meta('mediaurn', webpage)
381 info_page = self._download_json(
382 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
383 return self._get_info(info_page['mid'])