1 from __future__ import unicode_literals
5 from .common import InfoExtractor
13 class NPOIE(InfoExtractor):
15 _VALID_URL = r'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)'
19 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
20 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
22 'id': 'VPWON_1220719',
25 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
26 'upload_date': '20140622',
30 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
31 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
33 'id': 'VARA_101191800',
35 'title': 'De Mega Mike & Mega Thomas show',
36 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
37 'upload_date': '20090227',
42 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
43 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
45 'id': 'VPWON_1169289',
47 'title': 'Tegenlicht',
48 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
49 'upload_date': '20130225',
55 def _real_extract(self, url):
56 mobj = re.match(self._VALID_URL, url)
57 video_id = mobj.group('id')
59 metadata = self._download_json(
60 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
62 # We have to remove the javascript callback
63 transform_source=lambda j: re.sub(r'parseMetadata\((.*?)\);\n//.*$', r'\1', j)
65 token_page = self._download_webpage(
66 'http://ida.omroep.nl/npoplayer/i.js',
68 note='Downloading token'
70 token = self._search_regex(r'npoplayer\.token = "(.+?)"', token_page, 'token')
73 quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
74 for format_id in metadata['pubopties']:
75 format_info = self._download_json(
76 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s' % (video_id, format_id, token),
77 video_id, 'Downloading %s JSON' % format_id)
78 if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
80 streams = format_info.get('streams')
82 video_info = self._download_json(
83 streams[0] + '&type=json',
84 video_id, 'Downloading %s stream JSON' % format_id)
86 video_info = format_info
87 video_url = video_info.get('url')
90 if format_id == 'adaptive':
91 formats.extend(self._extract_m3u8_formats(video_url, video_id))
95 'format_id': format_id,
96 'quality': quality(format_id),
98 self._sort_formats(formats)
102 'title': metadata['titel'],
103 'description': metadata['info'],
104 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
105 'upload_date': unified_strdate(metadata.get('gidsdatum')),
106 'duration': parse_duration(metadata.get('tijdsduur')),