1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
20 class NPOBaseIE(InfoExtractor
):
21 def _get_token(self
, video_id
):
22 token_page
= self
._download
_webpage
(
23 'http://ida.omroep.nl/npoplayer/i.js',
24 video_id
, note
='Downloading token')
25 token
= self
._search
_regex
(
26 r
'npoplayer\.token = "(.+?)"', token_page
, 'token')
27 # Decryption algorithm extracted from http://npoplayer.omroep.nl/csjs/npoplayer-min.js
30 for i
in range(5, len(token_l
) - 4):
31 if token_l
[i
].isdigit():
36 if first
is None or second
is None:
40 token_l
[first
], token_l
[second
] = token_l
[second
], token_l
[first
]
42 return ''.join(token_l
)
45 class NPOIE(NPOBaseIE
):
47 IE_DESC
= 'npo.nl and ntr.nl'
54 npo\.nl/(?!live|radio)(?:[^/]+/){2}|
55 ntr\.nl/(?:[^/]+/){2,}|
56 omroepwnl\.nl/video/fragment/[^/]+__
64 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
65 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
67 'id': 'VPWON_1220719',
70 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
71 'upload_date': '20140622',
75 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
76 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
78 'id': 'VARA_101191800',
80 'title': 'De Mega Mike & Mega Thomas show',
81 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
82 'upload_date': '20090227',
87 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
88 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
90 'id': 'VPWON_1169289',
92 'title': 'Tegenlicht',
93 'description': 'md5:52cf4eefbc96fffcbdc06d024147abea',
94 'upload_date': '20130225',
99 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
101 'id': 'WO_VPRO_043706',
103 'title': 'De nieuwe mens - Deel 1',
104 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
108 # mplayer mms download
109 'skip_download': True,
114 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
115 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
117 'id': 'WO_NOS_762771',
119 'title': 'Hoe gaat Europa verder na Parijs?',
123 'url': 'http://www.ntr.nl/Aap-Poot-Pies/27/detail/Aap-poot-pies/VPWON_1233944#content',
124 'md5': '01c6a2841675995da1f0cf776f03a9c3',
126 'id': 'VPWON_1233944',
128 'title': 'Aap, poot, pies',
129 'description': 'md5:c9c8005d1869ae65b858e82c01a91fde',
130 'upload_date': '20150508',
135 'url': 'http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698',
136 'md5': 'd30cd8417b8b9bca1fdff27428860d08',
138 'id': 'POW_00996502',
140 'title': '''"Dit is wel een 'landslide'..."''',
141 'description': 'md5:f8d66d537dfb641380226e31ca57b8e8',
142 'upload_date': '20150508',
148 def _real_extract(self
, url
):
149 video_id
= self
._match
_id
(url
)
150 return self
._get
_info
(video_id
)
152 def _get_info(self
, video_id
):
153 metadata
= self
._download
_json
(
154 'http://e.omroep.nl/metadata/%s' % video_id
,
156 # We have to remove the javascript callback
157 transform_source
=strip_jsonp
,
160 # For some videos actual video id (prid) is different (e.g. for
161 # http://www.omroepwnl.nl/video/fragment/vandaag-de-dag-verkiezingen__POMS_WNL_853698
162 # video id is POMS_WNL_853698 but prid is POW_00996502)
163 video_id
= metadata
.get('prid') or video_id
165 token
= self
._get
_token
(video_id
)
169 pubopties
= metadata
.get('pubopties')
171 quality
= qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
172 for format_id
in pubopties
:
173 format_info
= self
._download
_json
(
174 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
175 % (video_id
, format_id
, token
),
176 video_id
, 'Downloading %s JSON' % format_id
)
177 if format_info
.get('error_code', 0) or format_info
.get('errorcode', 0):
179 streams
= format_info
.get('streams')
181 video_info
= self
._download
_json
(
182 streams
[0] + '&type=json',
183 video_id
, 'Downloading %s stream JSON' % format_id
)
185 video_info
= format_info
186 video_url
= video_info
.get('url')
189 if format_id
== 'adaptive':
190 formats
.extend(self
._extract
_m
3u8_formats
(video_url
, video_id
))
194 'format_id': format_id
,
195 'quality': quality(format_id
),
198 streams
= metadata
.get('streams')
200 for i
, stream
in enumerate(streams
):
201 stream_url
= stream
.get('url')
204 if '.asf' not in stream_url
:
207 'quality': stream
.get('kwaliteit'),
210 asx
= self
._download
_xml
(
211 stream_url
, video_id
,
212 'Downloading stream %d ASX playlist' % i
,
213 transform_source
=fix_xml_ampersands
)
214 ref
= asx
.find('./ENTRY/Ref')
217 video_url
= ref
.get('href')
222 'ext': stream
.get('formaat', 'asf'),
223 'quality': stream
.get('kwaliteit'),
226 self
._sort
_formats
(formats
)
229 if metadata
.get('tt888') == 'ja':
232 'url': 'http://e.omroep.nl/tt888/%s' % video_id
,
237 # prefer aflevering_titel if any since titel may be too generic, e.g.
238 # http://tegenlicht.vpro.nl/afleveringen/2014-2015/access-to-africa.html
239 'title': metadata
.get('aflevering_titel') or metadata
['titel'],
240 'description': metadata
['info'],
241 'thumbnail': metadata
.get('images', [{'url': None}
])[-1]['url'],
242 'upload_date': unified_strdate(metadata
.get('gidsdatum')),
243 'duration': parse_duration(metadata
.get('tijdsduur')),
245 'subtitles': subtitles
,
249 class NPOLiveIE(NPOBaseIE
):
250 IE_NAME
= 'npo.nl:live'
251 _VALID_URL
= r
'https?://(?:www\.)?npo\.nl/live/(?P<id>.+)'
254 'url': 'http://www.npo.nl/live/npo-1',
256 'id': 'LI_NEDERLAND1_136692',
257 'display_id': 'npo-1',
259 'title': 're:^Nederland 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
260 'description': 'Livestream',
264 'skip_download': True,
268 def _real_extract(self
, url
):
269 display_id
= self
._match
_id
(url
)
271 webpage
= self
._download
_webpage
(url
, display_id
)
273 live_id
= self
._search
_regex
(
274 r
'data-prid="([^"]+)"', webpage
, 'live id')
276 metadata
= self
._download
_json
(
277 'http://e.omroep.nl/metadata/%s' % live_id
,
278 display_id
, transform_source
=strip_jsonp
)
280 token
= self
._get
_token
(display_id
)
284 streams
= metadata
.get('streams')
286 for stream
in streams
:
287 stream_type
= stream
.get('type').lower()
288 # smooth streaming is not supported
289 if stream_type
in ['ss', 'ms']:
291 stream_info
= self
._download
_json
(
292 'http://ida.omroep.nl/aapi/?stream=%s&token=%s&type=jsonp'
293 % (stream
.get('url'), token
),
294 display_id
, 'Downloading %s JSON' % stream_type
)
295 if stream_info
.get('error_code', 0) or stream_info
.get('errorcode', 0):
297 stream_url
= self
._download
_json
(
298 stream_info
['stream'], display_id
,
299 'Downloading %s URL' % stream_type
,
300 'Unable to download %s URL' % stream_type
,
301 transform_source
=strip_jsonp
, fatal
=False)
304 if stream_type
== 'hds':
305 f4m_formats
= self
._extract
_f
4m
_formats
(stream_url
, display_id
)
306 # f4m downloader downloads only piece of live stream
307 for f4m_format
in f4m_formats
:
308 f4m_format
['preference'] = -1
309 formats
.extend(f4m_formats
)
310 elif stream_type
== 'hls':
311 formats
.extend(self
._extract
_m
3u8_formats
(stream_url
, display_id
, 'mp4'))
318 self
._sort
_formats
(formats
)
322 'display_id': display_id
,
323 'title': self
._live
_title
(metadata
['titel']),
324 'description': metadata
['info'],
325 'thumbnail': metadata
.get('images', [{'url': None}
])[-1]['url'],
331 class NPORadioIE(InfoExtractor
):
332 IE_NAME
= 'npo.nl:radio'
333 _VALID_URL
= r
'https?://(?:www\.)?npo\.nl/radio/(?P<id>[^/]+)/?$'
336 'url': 'http://www.npo.nl/radio/radio-1',
340 'title': 're:^NPO Radio 1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
344 'skip_download': True,
349 def _html_get_attribute_regex(attribute
):
350 return r
'{0}\s*=\s*\'([^
\']+)\''.format(attribute)
352 def _real_extract(self, url):
353 video_id = self._match_id(url)
355 webpage = self._download_webpage(url, video_id)
357 title = self._html_search_regex(
358 self._html_get_attribute_regex('data
-channel
'), webpage, 'title
')
360 stream = self._parse_json(
361 self._html_search_regex(self._html_get_attribute_regex('data
-streams
'), webpage, 'data
-streams
'),
364 codec = stream.get('codec
')
368 'url
': stream['url
'],
369 'title
': self._live_title(title),
376 class NPORadioFragmentIE(InfoExtractor):
377 IE_NAME = 'npo
.nl
:radio
:fragment
'
378 _VALID_URL = r'https?
://(?
:www\
.)?npo\
.nl
/radio
/[^
/]+/fragment
/(?P
<id>\d
+)'
381 'url
': 'http
://www
.npo
.nl
/radio
/radio
-5/fragment
/174356',
382 'md5
': 'dd8cc470dad764d0fdc70a9a1e2d18c2
',
386 'title
': 'Jubileumconcert Willeke Alberti
',
390 def _real_extract(self, url):
391 audio_id = self._match_id(url)
393 webpage = self._download_webpage(url, audio_id)
395 title = self._html_search_regex(
396 r'href
="/radio/[^/]+/fragment/%s" title
="([^"]+)"' % audio_id,
399 audio_url = self._search_regex(
400 r"data
-streams
='([^']+)'", webpage, 'audio url
')
410 _VALID_URL = r'https?
://(?
:www\
.)?
(?
:tegenlicht\
.)?vpro\
.nl
/(?
:[^
/]+/){2,}
(?P
<id>[^
/]+)\
.html
'
414 'url
': 'http
://tegenlicht
.vpro
.nl
/afleveringen
/2012-2013/de
-toekomst
-komt
-uit
-afrika
.html
',
415 'md5
': 'f8065e4e5a7824068ed3c7e783178f2c
',
417 'id': 'VPWON_1169289
',
419 'title
': 'De toekomst komt uit Afrika
',
420 'description
': 'md5
:52cf4eefbc96fffcbdc06d024147abea
',
421 'upload_date
': '20130225',
425 'url
': 'http
://www
.vpro
.nl
/programmas
/2doc
/2015/sergio
-herman
.html
',
427 'id': 'sergio
-herman
',
428 'title
': 'Sergio Herman
: Fucking perfect
',
434 def _real_extract(self, url):
435 playlist_id = self._match_id(url)
437 webpage = self._download_webpage(url, playlist_id)
440 self.url_result('npo
:%s' % video_id, 'NPO
')
441 for video_id in re.findall(r'data
-media
-id="([^"]+)"', webpage)
444 playlist_title = self._search_regex(
445 r'<title>\s*([^>]+?)\s*-\s*Teledoc\s*-\s*VPRO\s*</title>',
446 webpage, 'playlist title', default=None) or self._og_search_title(webpage)
448 return self.playlist_result(entries, playlist_id, playlist_title)
451 class WNLIE(InfoExtractor):
452 _VALID_URL = r'https?://(?:www\.)?omroepwnl\.nl/video/detail/(?P<id>[^/]+)__\d+'
455 'url': 'http://www.omroepwnl.nl/video/detail/vandaag-de-dag-6-mei__060515',
457 'id': 'vandaag-de-dag-6-mei',
458 'title': 'Vandaag de Dag 6 mei',
463 def _real_extract(self, url):
464 playlist_id = self._match_id(url)
466 webpage = self._download_webpage(url, playlist_id)
469 self.url_result('npo:%s' % video_id, 'NPO')
470 for video_id, part in re.findall(
471 r'<a[^>]+href="([^
"]+)"[^
>]+class="js-mid"[^
>]*>(Deel \d
+)', webpage)
474 playlist_title = self._html_search_regex(
475 r'(?s
)<h1
[^
>]+class="subject"[^
>]*>(.+?
)</h1
>',
476 webpage, 'playlist title
')
478 return self.playlist_result(entries, playlist_id, playlist_title)