]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/npo.py
fbcbe1f40c3c637c205686c09d7131c94f2771e6
[youtubedl] / youtube_dl / extractor / npo.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 unified_strdate,
8 )
9
10
11 class NPOIE(InfoExtractor):
12 IE_NAME = 'npo.nl'
13 _VALID_URL = r'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)'
14
15 _TEST = {
16 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
17 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
18 'info_dict': {
19 'id': 'VPWON_1220719',
20 'ext': 'mp4',
21 'title': 'Nieuwsuur',
22 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
23 'upload_date': '20140622',
24 },
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 metadata = self._download_json(
32 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
33 video_id,
34 # We have to remove the javascript callback
35 transform_source=lambda j: re.sub(r'parseMetadata\((.*?)\);\n//epc', r'\1', j)
36 )
37 token_page = self._download_webpage(
38 'http://ida.omroep.nl/npoplayer/i.js',
39 video_id,
40 note='Downloading token'
41 )
42 token = self._search_regex(r'npoplayer.token = "(.+?)"', token_page, 'token')
43 streams_info = self._download_json(
44 'http://ida.omroep.nl/odi/?prid=%s&puboptions=h264_std&adaptive=yes&token=%s' % (video_id, token),
45 video_id
46 )
47
48 stream_info = self._download_json(
49 streams_info['streams'][0] + '&type=json',
50 video_id,
51 'Downloading stream info'
52 )
53
54 return {
55 'id': video_id,
56 'title': metadata['titel'],
57 'ext': 'mp4',
58 'url': stream_info['url'],
59 'description': metadata['info'],
60 'thumbnail': metadata['images'][-1]['url'],
61 'upload_date': unified_strdate(metadata['gidsdatum']),
62 }