1 from __future__ import unicode_literals
5 from .common import InfoExtractor
16 class NPOIE(InfoExtractor):
18 _VALID_URL = r'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)'
22 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
23 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
25 'id': 'VPWON_1220719',
28 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
29 'upload_date': '20140622',
33 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
34 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
36 'id': 'VARA_101191800',
38 'title': 'De Mega Mike & Mega Thomas show',
39 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
40 'upload_date': '20090227',
45 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
46 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
48 'id': 'VPWON_1169289',
50 'title': 'Tegenlicht',
51 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
52 'upload_date': '20130225',
57 'url': 'http://www.npo.nl/de-nieuwe-mens-deel-1/21-07-2010/WO_VPRO_043706',
59 'id': 'WO_VPRO_043706',
61 'title': 'De nieuwe mens - Deel 1',
62 'description': 'md5:518ae51ba1293ffb80d8d8ce90b74e4b',
66 # mplayer mms download
67 'skip_download': True,
72 'url': 'http://www.npo.nl/hoe-gaat-europa-verder-na-parijs/10-01-2015/WO_NOS_762771',
73 'md5': 'b3da13de374cbe2d5332a7e910bef97f',
75 'id': 'WO_NOS_762771',
77 'title': 'Hoe gaat Europa verder na Parijs?',
82 def _real_extract(self, url):
83 mobj = re.match(self._VALID_URL, url)
84 video_id = mobj.group('id')
85 return self._get_info(video_id)
87 def _get_info(self, video_id):
88 metadata = self._download_json(
89 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
91 # We have to remove the javascript callback
92 transform_source=strip_jsonp,
94 token_page = self._download_webpage(
95 'http://ida.omroep.nl/npoplayer/i.js',
97 note='Downloading token'
99 token = self._search_regex(r'npoplayer\.token = "(.+?)"', token_page, 'token')
103 pubopties = metadata.get('pubopties')
105 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
106 for format_id in pubopties:
107 format_info = self._download_json(
108 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
109 % (video_id, format_id, token),
110 video_id, 'Downloading %s JSON' % format_id)
111 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
113 streams = format_info.get('streams')
115 video_info = self._download_json(
116 streams[0] + '&type=json',
117 video_id, 'Downloading %s stream JSON' % format_id)
119 video_info = format_info
120 video_url = video_info.get('url')
123 if format_id == 'adaptive':
124 formats.extend(self._extract_m3u8_formats(video_url, video_id))
128 'format_id': format_id,
129 'quality': quality(format_id),
132 streams = metadata.get('streams')
134 for i, stream in enumerate(streams):
135 stream_url = stream.get('url')
138 if '.asf' not in stream_url:
141 'quality': stream.get('kwaliteit'),
144 asx = self._download_xml(
145 stream_url, video_id,
146 'Downloading stream %d ASX playlist' % i,
147 transform_source=fix_xml_ampersands)
148 ref = asx.find('./ENTRY/Ref')
151 video_url = ref.get('href')
156 'ext': stream.get('formaat', 'asf'),
157 'quality': stream.get('kwaliteit'),
160 self._sort_formats(formats)
164 'title': metadata['titel'],
165 'description': metadata['info'],
166 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
167 'upload_date': unified_strdate(metadata.get('gidsdatum')),
168 'duration': parse_duration(metadata.get('tijdsduur')),
173 class TegenlichtVproIE(NPOIE):
174 IE_NAME = 'tegenlicht.vpro.nl'
175 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
179 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
180 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
182 'id': 'VPWON_1169289',
184 'title': 'Tegenlicht',
185 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
186 'upload_date': '20130225',
191 def _real_extract(self, url):
192 name = url_basename(url)
193 webpage = self._download_webpage(url, name)
194 urn = self._html_search_meta('mediaurn', webpage)
195 info_page = self._download_json(
196 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
197 return self._get_info(info_page['mid'])