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 def _real_extract(self, url):
73 mobj = re.match(self._VALID_URL, url)
74 video_id = mobj.group('id')
75 return self._get_info(video_id)
77 def _get_info(self, video_id):
78 metadata = self._download_json(
79 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
81 # We have to remove the javascript callback
82 transform_source=strip_jsonp,
84 token_page = self._download_webpage(
85 'http://ida.omroep.nl/npoplayer/i.js',
87 note='Downloading token'
89 token = self._search_regex(r'npoplayer\.token = "(.+?)"', token_page, 'token')
93 pubopties = metadata.get('pubopties')
95 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
96 for format_id in pubopties:
97 format_info = self._download_json(
98 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s'
99 % (video_id, format_id, token),
100 video_id, 'Downloading %s JSON' % format_id)
101 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
103 streams = format_info.get('streams')
105 video_info = self._download_json(
106 streams[0] + '&type=json',
107 video_id, 'Downloading %s stream JSON' % format_id)
109 video_info = format_info
110 video_url = video_info.get('url')
113 if format_id == 'adaptive':
114 formats.extend(self._extract_m3u8_formats(video_url, video_id))
118 'format_id': format_id,
119 'quality': quality(format_id),
122 streams = metadata.get('streams')
124 for i, stream in enumerate(streams):
125 stream_url = stream.get('url')
128 asx = self._download_xml(
129 stream_url, video_id,
130 'Downloading stream %d ASX playlist' % i,
131 transform_source=fix_xml_ampersands)
132 ref = asx.find('./ENTRY/Ref')
135 video_url = ref.get('href')
140 'ext': stream.get('formaat', 'asf'),
141 'quality': stream.get('kwaliteit'),
144 self._sort_formats(formats)
148 'title': metadata['titel'],
149 'description': metadata['info'],
150 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
151 'upload_date': unified_strdate(metadata.get('gidsdatum')),
152 'duration': parse_duration(metadata.get('tijdsduur')),
157 class TegenlichtVproIE(NPOIE):
158 IE_NAME = 'tegenlicht.vpro.nl'
159 _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
163 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
164 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
166 'id': 'VPWON_1169289',
168 'title': 'Tegenlicht',
169 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
170 'upload_date': '20130225',
175 def _real_extract(self, url):
176 name = url_basename(url)
177 webpage = self._download_webpage(url, name)
178 urn = self._html_search_meta('mediaurn', webpage)
179 info_page = self._download_json(
180 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
181 return self._get_info(info_page['mid'])