]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/npo.py
Credit @m5moufl for behindkink (#3740)
[yt-dlp.git] / youtube_dl / extractor / npo.py
CommitLineData
331ae266
JMF
1from __future__ import unicode_literals
2
3import re
4
5from .common import InfoExtractor
6from ..utils import (
7 unified_strdate,
c9ea760e 8 qualities,
331ae266
JMF
9)
10
11
12class NPOIE(InfoExtractor):
13 IE_NAME = 'npo.nl'
14 _VALID_URL = r'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)'
15
16 _TEST = {
17 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
18 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
19 'info_dict': {
20 'id': 'VPWON_1220719',
c9ea760e 21 'ext': 'm4v',
331ae266
JMF
22 'title': 'Nieuwsuur',
23 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
24 'upload_date': '20140622',
25 },
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
31
32 metadata = self._download_json(
33 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
34 video_id,
35 # We have to remove the javascript callback
66149e3f 36 transform_source=lambda j: re.sub(r'parseMetadata\((.*?)\);\n//.*$', r'\1', j)
331ae266
JMF
37 )
38 token_page = self._download_webpage(
39 'http://ida.omroep.nl/npoplayer/i.js',
40 video_id,
41 note='Downloading token'
42 )
c9ea760e 43 token = self._search_regex(r'npoplayer\.token = "(.+?)"', token_page, 'token')
331ae266 44
c9ea760e
S
45 formats = []
46 quality = qualities(['adaptive', 'h264_sb', 'h264_bb', 'h264_std'])
47 for format_id in metadata['pubopties']:
48 streams_info = self._download_json(
49 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s' % (video_id, format_id, token),
50 video_id, 'Downloading %s streams info' % format_id)
51 stream_info = self._download_json(
52 streams_info['streams'][0] + '&type=json',
53 video_id, 'Downloading %s stream info' % format_id)
54 if format_id == 'adaptive':
55 formats.extend(self._extract_m3u8_formats(stream_info['url'], video_id))
56 else:
57 formats.append({
58 'url': stream_info['url'],
59 'format_id': format_id,
60 'quality': quality(format_id),
61 })
62 self._sort_formats(formats)
331ae266
JMF
63
64 return {
65 'id': video_id,
66 'title': metadata['titel'],
331ae266
JMF
67 'description': metadata['info'],
68 'thumbnail': metadata['images'][-1]['url'],
69 'upload_date': unified_strdate(metadata['gidsdatum']),
c9ea760e 70 'formats': formats,
331ae266 71 }