1 from __future__ import unicode_literals
5 from .common import InfoExtractor
17 class NPOIE(InfoExtractor):
19 _VALID_URL = r'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)'
23 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
24 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
26 'id': 'VPWON_1220719',
29 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
30 'upload_date': '20140622',
34 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
35 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
37 'id': 'VARA_101191800',
39 'title': 'De Mega Mike & Mega Thomas show',
40 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
41 'upload_date': '20090227',
46 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
47 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
49 'id': 'VPWON_1169289',
51 'title': 'Tegenlicht',
52 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
53 'upload_date': '20130225',
58 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
60 'id': 'WO_VPRO_043706',
62 'title': 'De nieuwe mens - Deel 1',
63 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
67 # mplayer mms download
68 'skip_download': True,
73 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
74 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
76 'id': 'WO_NOS_762771',
78 'title': 'Hoe gaat Europa verder na Parijs?',
83 def _real_extract(self, url):
84 mobj = re.match(self._VALID_URL, url)
85 video_id = mobj.group('id')
86 return self._get_info(video_id)
88 def _get_info(self, video_id):
89 metadata = self._download_json(
90 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
92 # We have to remove the javascript callback
93 transform_source=strip_jsonp,
95 token_page = self._download_webpage(
96 'http://ida.omroep.nl/npoplayer/i.js',
98 note='Downloading token'
100 token = self._search_regex(r'npoplayer\.token = "(.+?)"', token_page, 'token')
104 pubopties = metadata.get('pubopties')
106 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
107 for format_id in pubopties:
108 format_info = self._download_json(
109 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
110 % (video_id, format_id, token),
111 video_id, 'Downloading %s JSON' % format_id)
112 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
114 streams = format_info.get('streams')
116 video_info = self._download_json(
117 streams[0] + '&type=json',
118 video_id, 'Downloading %s stream JSON' % format_id)
120 video_info = format_info
121 video_url = video_info.get('url')
124 if format_id == 'adaptive':
125 formats.extend(self._extract_m3u8_formats(video_url, video_id))
129 'format_id': format_id,
130 'quality': quality(format_id),
133 streams = metadata.get('streams')
135 for i, stream in enumerate(streams):
136 stream_url = stream.get('url')
139 if not '.asf' in stream_url:
142 'quality': stream.get('kwaliteit'),
145 asx = self._download_xml(
146 stream_url, video_id,
147 'Downloading stream %d ASX playlist' % i,
148 transform_source=fix_xml_ampersands)
149 ref = asx.find('./ENTRY/Ref')
152 video_url = ref.get('href')
157 'ext': stream.get('formaat', 'asf'),
158 'quality': stream.get('kwaliteit'),
161 self._sort_formats(formats)
165 'title': metadata['titel'],
166 'description': metadata['info'],
167 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
168 'upload_date': unified_strdate(metadata.get('gidsdatum')),
169 'duration': parse_duration(metadata.get('tijdsduur')),
174 class TegenlichtVproIE(NPOIE):
175 IE_NAME = 'tegenlicht.vpro.nl'
176 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
180 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
181 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
183 'id': 'VPWON_1169289',
185 'title': 'Tegenlicht',
186 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
187 'upload_date': '20130225',
192 def _real_extract(self, url):
193 name = url_basename(url)
194 webpage = self._download_webpage(url, name)
195 urn = self._html_search_meta('mediaurn', webpage)
196 info_page = self._download_json(
197 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
198 return self._get_info(info_page['mid'])