1 from __future__ import unicode_literals
3 from .subtitles import SubtitlesInfoExtractor
4 from .common import InfoExtractor
15 class NPOBaseIE(SubtitlesInfoExtractor):
16 def _get_token(self, video_id):
17 token_page = self._download_webpage(
18 'http://ida.omroep.nl/npoplayer/i.js',
19 video_id, note='Downloading token')
20 return self._search_regex(
21 r'npoplayer\.token = "(.+?)"', token_page, 'token')
24 class NPOIE(NPOBaseIE):
26 _VALID_URL = r'https?://(?:www\.)?npo\.nl/(?!live|radio)[^/]+/[^/]+/(?P<id>[^/?]+)'
30 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
31 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
33 'id': 'VPWON_1220719',
36 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
37 'upload_date': '20140622',
41 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
42 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
44 'id': 'VARA_101191800',
46 'title': 'De Mega Mike & Mega Thomas show',
47 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
48 'upload_date': '20090227',
53 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
54 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
56 'id': 'VPWON_1169289',
58 'title': 'Tegenlicht',
59 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
60 'upload_date': '20130225',
65 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
67 'id': 'WO_VPRO_043706',
69 'title': 'De nieuwe mens - Deel 1',
70 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
74 # mplayer mms download
75 'skip_download': True,
80 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
81 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
83 'id': 'WO_NOS_762771',
85 'title': 'Hoe gaat Europa verder na Parijs?',
90 def _real_extract(self, url):
91 video_id = self._match_id(url)
92 return self._get_info(video_id)
94 def _get_info(self, video_id):
95 metadata = self._download_json(
96 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
98 # We have to remove the javascript callback
99 transform_source=strip_jsonp,
102 token = self._get_token(video_id)
106 pubopties = metadata.get('pubopties')
108 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
109 for format_id in pubopties:
110 format_info = self._download_json(
111 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
112 % (video_id, format_id, token),
113 video_id, 'Downloading %s JSON' % format_id)
114 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
116 streams = format_info.get('streams')
118 video_info = self._download_json(
119 streams[0] + '&type=json',
120 video_id, 'Downloading %s stream JSON' % format_id)
122 video_info = format_info
123 video_url = video_info.get('url')
126 if format_id == 'adaptive':
127 formats.extend(self._extract_m3u8_formats(video_url, video_id))
131 'format_id': format_id,
132 'quality': quality(format_id),
135 streams = metadata.get('streams')
137 for i, stream in enumerate(streams):
138 stream_url = stream.get('url')
141 if '.asf' not in stream_url:
144 'quality': stream.get('kwaliteit'),
147 asx = self._download_xml(
148 stream_url, video_id,
149 'Downloading stream %d ASX playlist' % i,
150 transform_source=fix_xml_ampersands)
151 ref = asx.find('./ENTRY/Ref')
154 video_url = ref.get('href')
159 'ext': stream.get('formaat', 'asf'),
160 'quality': stream.get('kwaliteit'),
163 self._sort_formats(formats)
166 if metadata.get('tt888') == 'ja':
167 subtitles['nl'] = 'http://e.omroep.nl/tt888/%s' % video_id
169 if self._downloader.params.get('listsubtitles', False):
170 self._list_available_subtitles(video_id, subtitles)
173 subtitles = self.extract_subtitles(video_id, subtitles)
177 'title': metadata['titel'],
178 'description': metadata['info'],
179 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
180 'upload_date': unified_strdate(metadata.get('gidsdatum')),
181 'duration': parse_duration(metadata.get('tijdsduur')),
183 'subtitles': subtitles,
187 class NPOLiveIE(NPOBaseIE):
188 IE_NAME = 'npo.nl:live'
189 _VALID_URL = r'https?://(?:www\.)?npo\.nl/live/(?P<id>.+)'
192 'url': 'http://www.npo.nl/live/npo-1',
194 'id': 'LI_NEDERLAND1_136692',
195 'display_id': 'npo-1',
197 'title': 're:^Nederland 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
198 'description': 'Livestream',
202 'skip_download': True,
206 def _real_extract(self, url):
207 display_id = self._match_id(url)
209 webpage = self._download_webpage(url, display_id)
211 live_id = self._search_regex(
212 r'data-prid="([^"]+)"', webpage, 'live id')
214 metadata = self._download_json(
215 'http://e.omroep.nl/metadata/%s' % live_id,
216 display_id, transform_source=strip_jsonp)
218 token = self._get_token(display_id)
222 streams = metadata.get('streams')
224 for stream in streams:
225 stream_type = stream.get('type').lower()
226 if stream_type == 'ss':
228 stream_info = self._download_json(
229 'http://ida.omroep.nl/aapi/?stream=%s&token=%s&type=jsonp'
230 % (stream.get('url'), token),
231 display_id, 'Downloading %s JSON' % stream_type)
232 if stream_info.get('error_code', 0) or stream_info.get('errorcode', 0):
234 stream_url = self._download_json(
235 stream_info['stream'], display_id,
236 'Downloading %s URL' % stream_type,
237 transform_source=strip_jsonp)
238 if stream_type == 'hds':
239 f4m_formats = self._extract_f4m_formats(stream_url, display_id)
240 # f4m downloader downloads only piece of live stream
241 for f4m_format in f4m_formats:
242 f4m_format['preference'] = -1
243 formats.extend(f4m_formats)
244 elif stream_type == 'hls':
245 formats.extend(self._extract_m3u8_formats(stream_url, display_id, 'mp4'))
251 self._sort_formats(formats)
255 'display_id': display_id,
256 'title': self._live_title(metadata['titel']),
257 'description': metadata['info'],
258 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
264 class NPORadioIE(InfoExtractor):
265 IE_NAME = 'npo.nl:radio'
266 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
269 'url': 'http://www.npo.nl/radio/radio-1',
273 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
277 'skip_download': True,
282 def _html_get_attribute_regex(attribute):
283 return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)
285 def _real_extract(self, url):
286 video_id = self._match_id(url)
288 webpage = self._download_webpage(url, video_id)
290 title = self._html_search_regex(
291 self._html_get_attribute_regex('data-channel'), webpage, 'title')
293 stream = self._parse_json(
294 self._html_search_regex(self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'),
297 codec = stream.get('codec')
301 'url': stream['url'],
302 'title': self._live_title(title),
309 class NPORadioFragmentIE(InfoExtractor):
310 IE_NAME = 'npo.nl:radio:fragment'
311 _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/[^/]+/fragment/(?P<id>\d+)'
314 'url': 'http://www.npo.nl/radio/radio-5/fragment/174356',
315 'md5': 'dd8cc470dad764d0fdc70a9a1e2d18c2',
319 'title': 'Jubileumconcert Willeke Alberti',
323 def _real_extract(self, url):
324 audio_id = self._match_id(url)
326 webpage = self._download_webpage(url, audio_id)
328 title = self._html_search_regex(
329 r'href="/radio/[^/]+/fragment/%s" title="([^"]+)"' % audio_id,
332 audio_url = self._search_regex(
333 r"data-streams='([^']+)'", webpage, 'audio url')
342 class TegenlichtVproIE(NPOIE):
343 IE_NAME = 'tegenlicht.vpro.nl'
344 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
348 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
349 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
351 'id': 'VPWON_1169289',
353 'title': 'Tegenlicht',
354 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
355 'upload_date': '20130225',
360 def _real_extract(self, url):
361 name = url_basename(url)
362 webpage = self._download_webpage(url, name)
363 urn = self._html_search_meta('mediaurn', webpage)
364 info_page = self._download_json(
365 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
366 return self._get_info(info_page['mid'])