2 from __future__ import unicode_literals
7 from youtube_dl import utils
8 from .common import InfoExtractor
11 class CanvasIE(InfoExtractor):
12 _VALID_URL = r'(?:https?://)?(?:www\.)?canvas\.be/video/(?P<id>.+)'
14 'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
15 'md5': 'ea838375a547ac787d4064d8c7860a6c',
17 'id': 'de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
18 'title': 'De afspraak veilt voor de Warmste Week',
24 def _real_extract(self, url):
25 video_id = self._match_id(url)
27 webpage = self._download_webpage(url, video_id)
29 title = self._search_regex(
30 r'<h1 class="video__body__header__title">(.+?)</h1>', webpage,
32 data_video = self._html_search_regex(
33 r'data-video=(["\'])(?P<id>.+?)\1', webpage, 'data-video', group='id')
34 json_url = 'https://mediazone.vrt.be/api/v1/canvas/assets/' + data_video
35 data = self._download_json(json_url, video_id)
38 for target in data['targetUrls']:
39 if 'type' and 'url' in target:
40 extension = utils.determine_ext(target['url'])
41 if target['type'] == 'PROGRESSIVE_DOWNLOAD':
43 'format_id': extension,
47 elif target['type'] == 'HLS':
48 formats.extend(self._extract_m3u8_formats(
49 target['url'], video_id, entry_protocol='m3u8_native',
54 elif target['type'] == 'HDS':
56 'format_id': extension,
60 elif target['type'] == 'RTMP':
62 'format_id': extension,
66 elif target['type'] == 'RTSP':
68 'format_id': extension,
73 self._sort_formats(formats)
74 duration = utils.int_or_none(data.get('duration')) / 1000