]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ketnet.py
Prepare to upload.
[youtubedl] / youtube_dl / extractor / ketnet.py
1 from __future__ import unicode_literals
2
3 from .canvas import CanvasIE
4 from .common import InfoExtractor
5
6
7 class KetnetIE(InfoExtractor):
8 _VALID_URL = r'https?://(?:www\.)?ketnet\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)'
9 _TESTS = [{
10 'url': 'https://www.ketnet.be/kijken/zomerse-filmpjes',
11 'md5': '6bdeb65998930251bbd1c510750edba9',
12 'info_dict': {
13 'id': 'zomerse-filmpjes',
14 'ext': 'mp4',
15 'title': 'Gluur mee op de filmset en op Pennenzakkenrock',
16 'description': 'Gluur mee met Ghost Rockers op de filmset',
17 'thumbnail': r're:^https?://.*\.jpg$',
18 }
19 }, {
20 # mzid in playerConfig instead of sources
21 'url': 'https://www.ketnet.be/kijken/nachtwacht/de-greystook',
22 'md5': '90139b746a0a9bd7bb631283f6e2a64e',
23 'info_dict': {
24 'id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
25 'display_id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
26 'ext': 'flv',
27 'title': 'Nachtwacht: De Greystook',
28 'description': 'md5:1db3f5dc4c7109c821261e7512975be7',
29 'thumbnail': r're:^https?://.*\.jpg$',
30 'duration': 1468.03,
31 },
32 'expected_warnings': ['is not a supported codec', 'Unknown MIME type'],
33 }, {
34 'url': 'https://www.ketnet.be/kijken/karrewiet/uitzending-8-september-2016',
35 'only_matching': True,
36 }, {
37 'url': 'https://www.ketnet.be/achter-de-schermen/sien-repeteert-voor-stars-for-life',
38 'only_matching': True,
39 }, {
40 # mzsource, geo restricted to Belgium
41 'url': 'https://www.ketnet.be/kijken/nachtwacht/de-bermadoe',
42 'only_matching': True,
43 }]
44
45 def _real_extract(self, url):
46 video_id = self._match_id(url)
47
48 webpage = self._download_webpage(url, video_id)
49
50 config = self._parse_json(
51 self._search_regex(
52 r'(?s)playerConfig\s*=\s*({.+?})\s*;', webpage,
53 'player config'),
54 video_id)
55
56 mzid = config.get('mzid')
57 if mzid:
58 return self.url_result(
59 'https://mediazone.vrt.be/api/v1/ketnet/assets/%s' % mzid,
60 CanvasIE.ie_key(), video_id=mzid)
61
62 title = config['title']
63
64 formats = []
65 for source_key in ('', 'mz'):
66 source = config.get('%ssource' % source_key)
67 if not isinstance(source, dict):
68 continue
69 for format_id, format_url in source.items():
70 if format_id == 'hls':
71 formats.extend(self._extract_m3u8_formats(
72 format_url, video_id, 'mp4',
73 entry_protocol='m3u8_native', m3u8_id=format_id,
74 fatal=False))
75 elif format_id == 'hds':
76 formats.extend(self._extract_f4m_formats(
77 format_url, video_id, f4m_id=format_id, fatal=False))
78 else:
79 formats.append({
80 'url': format_url,
81 'format_id': format_id,
82 })
83 self._sort_formats(formats)
84
85 return {
86 'id': video_id,
87 'title': title,
88 'description': config.get('description'),
89 'thumbnail': config.get('image'),
90 'series': config.get('program'),
91 'episode': config.get('episode'),
92 'formats': formats,
93 }