]>
Commit | Line | Data |
---|---|---|
be2d40a5 TG |
1 | from __future__ import unicode_literals |
2 | ||
bb5ebd44 S |
3 | import re |
4 | ||
be2d40a5 | 5 | from .common import InfoExtractor |
4e2743ab | 6 | from ..utils import float_or_none |
be2d40a5 TG |
7 | |
8 | ||
9 | class CanvasIE(InfoExtractor): | |
41b263ac | 10 | IE_DESC = 'canvas.be and een.be' |
bb5ebd44 | 11 | _VALID_URL = r'https?://(?:www\.)?(?P<site_id>canvas|een)\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)' |
6eff2605 | 12 | _TESTS = [{ |
be2d40a5 TG |
13 | 'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week', |
14 | 'md5': 'ea838375a547ac787d4064d8c7860a6c', | |
15 | 'info_dict': { | |
4e2743ab S |
16 | 'id': 'mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e', |
17 | 'display_id': 'de-afspraak-veilt-voor-de-warmste-week', | |
be2d40a5 | 18 | 'ext': 'mp4', |
4e2743ab S |
19 | 'title': 'De afspraak veilt voor de Warmste Week', |
20 | 'description': 'md5:24cb860c320dc2be7358e0e5aa317ba6', | |
ec85ded8 | 21 | 'thumbnail': r're:^https?://.*\.jpg$', |
4e2743ab | 22 | 'duration': 49.02, |
be2d40a5 | 23 | } |
6eff2605 S |
24 | }, { |
25 | # with subtitles | |
26 | 'url': 'http://www.canvas.be/video/panorama/2016/pieter-0167', | |
27 | 'info_dict': { | |
28 | 'id': 'mz-ast-5240ff21-2d30-4101-bba6-92b5ec67c625', | |
29 | 'display_id': 'pieter-0167', | |
30 | 'ext': 'mp4', | |
31 | 'title': 'Pieter 0167', | |
32 | 'description': 'md5:943cd30f48a5d29ba02c3a104dc4ec4e', | |
ec85ded8 | 33 | 'thumbnail': r're:^https?://.*\.jpg$', |
6eff2605 S |
34 | 'duration': 2553.08, |
35 | 'subtitles': { | |
36 | 'nl': [{ | |
37 | 'ext': 'vtt', | |
38 | }], | |
39 | }, | |
40 | }, | |
41 | 'params': { | |
42 | 'skip_download': True, | |
43 | } | |
bb5ebd44 S |
44 | }, { |
45 | 'url': 'https://www.een.be/sorry-voor-alles/herbekijk-sorry-voor-alles', | |
46 | 'info_dict': { | |
47 | 'id': 'mz-ast-11a587f8-b921-4266-82e2-0bce3e80d07f', | |
48 | 'display_id': 'herbekijk-sorry-voor-alles', | |
49 | 'ext': 'mp4', | |
50 | 'title': 'Herbekijk Sorry voor alles', | |
51 | 'description': 'md5:8bb2805df8164e5eb95d6a7a29dc0dd3', | |
ec85ded8 | 52 | 'thumbnail': r're:^https?://.*\.jpg$', |
bb5ebd44 S |
53 | 'duration': 3788.06, |
54 | }, | |
55 | 'params': { | |
56 | 'skip_download': True, | |
57 | } | |
58 | }, { | |
59 | 'url': 'https://www.canvas.be/check-point/najaar-2016/de-politie-uw-vriend', | |
60 | 'only_matching': True, | |
6eff2605 | 61 | }] |
be2d40a5 TG |
62 | |
63 | def _real_extract(self, url): | |
bb5ebd44 S |
64 | mobj = re.match(self._VALID_URL, url) |
65 | site_id, display_id = mobj.group('site_id'), mobj.group('id') | |
be2d40a5 | 66 | |
4e2743ab | 67 | webpage = self._download_webpage(url, display_id) |
be2d40a5 | 68 | |
bb5ebd44 | 69 | title = (self._search_regex( |
4e2743ab | 70 | r'<h1[^>]+class="video__body__header__title"[^>]*>(.+?)</h1>', |
bb5ebd44 S |
71 | webpage, 'title', default=None) or self._og_search_title( |
72 | webpage)).strip() | |
4e2743ab S |
73 | |
74 | video_id = self._html_search_regex( | |
490b7557 | 75 | r'data-video=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'video id', group='id') |
4e2743ab S |
76 | |
77 | data = self._download_json( | |
bb5ebd44 S |
78 | 'https://mediazone.vrt.be/api/v1/%s/assets/%s' |
79 | % (site_id, video_id), display_id) | |
be2d40a5 TG |
80 | |
81 | formats = [] | |
82 | for target in data['targetUrls']: | |
4e2743ab S |
83 | format_url, format_type = target.get('url'), target.get('type') |
84 | if not format_url or not format_type: | |
85 | continue | |
86 | if format_type == 'HLS': | |
87 | formats.extend(self._extract_m3u8_formats( | |
88 | format_url, display_id, entry_protocol='m3u8_native', | |
89 | ext='mp4', preference=0, fatal=False, m3u8_id=format_type)) | |
90 | elif format_type == 'HDS': | |
91 | formats.extend(self._extract_f4m_formats( | |
92 | format_url, display_id, f4m_id=format_type, fatal=False)) | |
67dcbc0a RA |
93 | elif format_type == 'MPEG_DASH': |
94 | formats.extend(self._extract_mpd_formats( | |
95 | format_url, display_id, mpd_id=format_type, fatal=False)) | |
4e2743ab S |
96 | else: |
97 | formats.append({ | |
98 | 'format_id': format_type, | |
99 | 'url': format_url, | |
100 | }) | |
be2d40a5 | 101 | self._sort_formats(formats) |
fd7a3ea4 | 102 | |
8d3eeb36 | 103 | subtitles = {} |
fd7a3ea4 S |
104 | subtitle_urls = data.get('subtitleUrls') |
105 | if isinstance(subtitle_urls, list): | |
106 | for subtitle in subtitle_urls: | |
107 | subtitle_url = subtitle.get('url') | |
108 | if subtitle_url and subtitle.get('type') == 'CLOSED': | |
109 | subtitles.setdefault('nl', []).append({'url': subtitle_url}) | |
4e2743ab | 110 | |
be2d40a5 TG |
111 | return { |
112 | 'id': video_id, | |
4e2743ab | 113 | 'display_id': display_id, |
be2d40a5 | 114 | 'title': title, |
4e2743ab | 115 | 'description': self._og_search_description(webpage), |
be2d40a5 | 116 | 'formats': formats, |
4e2743ab S |
117 | 'duration': float_or_none(data.get('duration'), 1000), |
118 | 'thumbnail': data.get('posterImageUrl'), | |
8d3eeb36 | 119 | 'subtitles': subtitles, |
be2d40a5 | 120 | } |