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')
23 for i in range(5, len(token_l) - 4):
24 if token_l[i].isdigit():
29 if first is None or second is None:
33 token_l[first], token_l[second] = token_l[second], token_l[first]
35 return ''.join(token_l)
38 class NPOIE(NPOBaseIE):
40 _VALID_URL = r'https?://(?:www\.)?npo\.nl/(?!live|radio)[^/]+/[^/]+/(?P<id>[^/?]+)'
44 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
45 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
47 'id': 'VPWON_1220719',
50 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
51 'upload_date': '20140622',
55 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
56 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
58 'id': 'VARA_101191800',
60 'title': 'De Mega Mike & Mega Thomas show',
61 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
62 'upload_date': '20090227',
67 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
68 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
70 'id': 'VPWON_1169289',
72 'title': 'Tegenlicht',
73 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
74 'upload_date': '20130225',
79 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
81 'id': 'WO_VPRO_043706',
83 'title': 'De nieuwe mens - Deel 1',
84 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
88 # mplayer mms download
89 'skip_download': True,
94 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
95 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
97 'id': 'WO_NOS_762771',
99 'title': 'Hoe gaat Europa verder na Parijs?',
104 def _real_extract(self, url):
105 video_id = self._match_id(url)
106 return self._get_info(video_id)
108 def _get_info(self, video_id):
109 metadata = self._download_json(
110 'http://e.omroep.nl/metadata/%s' % video_id,
112 # We have to remove the javascript callback
113 transform_source=strip_jsonp,
116 token = self._get_token(video_id)
120 pubopties = metadata.get('pubopties')
122 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
123 for format_id in pubopties:
124 format_info = self._download_json(
125 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
126 % (video_id, format_id, token),
127 video_id, 'Downloading %s JSON' % format_id)
128 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
130 streams = format_info.get('streams')
132 video_info = self._download_json(
133 streams[0] + '&type=json',
134 video_id, 'Downloading %s stream JSON' % format_id)
136 video_info = format_info
137 video_url = video_info.get('url')
140 if format_id == 'adaptive':
141 formats.extend(self._extract_m3u8_formats(video_url, video_id))
145 'format_id': format_id,
146 'quality': quality(format_id),
149 streams = metadata.get('streams')
151 for i, stream in enumerate(streams):
152 stream_url = stream.get('url')
155 if '.asf' not in stream_url:
158 'quality': stream.get('kwaliteit'),
161 asx = self._download_xml(
162 stream_url, video_id,
163 'Downloading stream %d ASX playlist' % i,
164 transform_source=fix_xml_ampersands)
165 ref = asx.find('./ENTRY/Ref')
168 video_url = ref.get('href')
173 'ext': stream.get('formaat', 'asf'),
174 'quality': stream.get('kwaliteit'),
177 self._sort_formats(formats)
180 if metadata.get('tt888') == 'ja':
183 'url': 'http://e.omroep.nl/tt888/%s' % video_id,
188 'title': metadata['titel'],
189 'description': metadata['info'],
190 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
191 'upload_date': unified_strdate(metadata.get('gidsdatum')),
192 'duration': parse_duration(metadata.get('tijdsduur')),
194 'subtitles': subtitles,
198 class NPOLiveIE(NPOBaseIE):
199 IE_NAME = 'npo.nl:live'
200 _VALID_URL = r'https?://(?:www\.)?npo\.nl/live/(?P<id>.+)'
203 'url': 'http://www.npo.nl/live/npo-1',
205 'id': 'LI_NEDERLAND1_136692',
206 'display_id': 'npo-1',
208 'title': 're:^Nederland 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
209 'description': 'Livestream',
213 'skip_download': True,
217 def _real_extract(self, url):
218 display_id = self._match_id(url)
220 webpage = self._download_webpage(url, display_id)
222 live_id = self._search_regex(
223 r'data-prid="([^"]+)"', webpage, 'live id')
225 metadata = self._download_json(
226 'http://e.omroep.nl/metadata/%s' % live_id,
227 display_id, transform_source=strip_jsonp)
229 token = self._get_token(display_id)
233 streams = metadata.get('streams')
235 for stream in streams:
236 stream_type = stream.get('type').lower()
237 # smooth streaming is not supported
238 if stream_type in ['ss', 'ms']:
240 stream_info = self._download_json(
241 'http://ida.omroep.nl/aapi/?stream=%s&token=%s&type=jsonp'
242 % (stream.get('url'), token),
243 display_id, 'Downloading %s JSON' % stream_type)
244 if stream_info.get('error_code', 0) or stream_info.get('errorcode', 0):
246 stream_url = self._download_json(
247 stream_info['stream'], display_id,
248 'Downloading %s URL' % stream_type,
249 'Unable to download %s URL' % stream_type,
250 transform_source=strip_jsonp, fatal=False)
253 if stream_type == 'hds':
254 f4m_formats = self._extract_f4m_formats(stream_url, display_id)
255 # f4m downloader downloads only piece of live stream
256 for f4m_format in f4m_formats:
257 f4m_format['preference'] = -1
258 formats.extend(f4m_formats)
259 elif stream_type == 'hls':
260 formats.extend(self._extract_m3u8_formats(stream_url, display_id, 'mp4'))
267 self._sort_formats(formats)
271 'display_id': display_id,
272 'title': self._live_title(metadata['titel']),
273 'description': metadata['info'],
274 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
280 class NPORadioIE(InfoExtractor):
281 IE_NAME = 'npo.nl:radio'
282 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
285 'url': 'http://www.npo.nl/radio/radio-1',
289 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
293 'skip_download': True,
298 def _html_get_attribute_regex(attribute):
299 return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
301 def _real_extract(self, url):
302 video_id = self._match_id(url)
304 webpage = self._download_webpage(url, video_id)
306 title = self._html_search_regex(
307 self._html_get_attribute_regex('data-channel'), webpage, 'title')
309 stream = self._parse_json(
310 self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
313 codec = stream.get('codec')
317 'url': stream['url'],
318 'title': self._live_title(title),
325 class NPORadioFragmentIE(InfoExtractor):
326 IE_NAME = 'npo.nl:radio:fragment'
327 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
330 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
331 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
335 'title': 'Jubileumconcert Willeke Alberti',
339 def _real_extract(self, url):
340 audio_id = self._match_id(url)
342 webpage = self._download_webpage(url, audio_id)
344 title = self._html_search_regex(
345 r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
348 audio_url = self._search_regex(
349 r"data-streams='([^']+)'", webpage, 'audio url')
358 class TegenlichtVproIE(NPOIE):
359 IE_NAME = 'tegenlicht.vpro.nl'
360 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
364 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
365 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
367 'id': 'VPWON_1169289',
369 'title': 'Tegenlicht',
370 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
371 'upload_date': '20130225',
376 def _real_extract(self, url):
377 name = url_basename(url)
378 webpage = self._download_webpage(url, name)
379 urn = self._html_search_meta('mediaurn', webpage)
380 info_page = self._download_json(
381 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
382 return self._get_info(info_page['mid'])