]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/canvas.py
6899f8431788fad62e4615a33d95f3ffa65f4ea1
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  12 class CanvasIE(InfoExtractor
): 
  13     _VALID_URL 
= r
'https?://mediazone\.vrt\.be/api/v1/(?P<site_id>canvas|een|ketnet)/assets/(?P<id>m[dz]-ast-[^/?#&]+)' 
  15         'url': 'https://mediazone.vrt.be/api/v1/ketnet/assets/md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475', 
  16         'md5': '90139b746a0a9bd7bb631283f6e2a64e', 
  18             'id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475', 
  19             'display_id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475', 
  21             'title': 'Nachtwacht: De Greystook', 
  22             'description': 'md5:1db3f5dc4c7109c821261e7512975be7', 
  23             'thumbnail': r
're:^https?://.*\.jpg$', 
  26         'expected_warnings': ['is not a supported codec', 'Unknown MIME type'], 
  28         'url': 'https://mediazone.vrt.be/api/v1/canvas/assets/mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e', 
  29         'only_matching': True, 
  32     def _real_extract(self
, url
): 
  33         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  34         site_id
, video_id 
= mobj
.group('site_id'), mobj
.group('id') 
  36         data 
= self
._download
_json
( 
  37             'https://mediazone.vrt.be/api/v1/%s/assets/%s' 
  38             % (site_id
, video_id
), video_id
) 
  41         description 
= data
.get('description') 
  44         for target 
in data
['targetUrls']: 
  45             format_url
, format_type 
= target
.get('url'), target
.get('type') 
  46             if not format_url 
or not format_type
: 
  48             if format_type 
== 'HLS': 
  49                 formats
.extend(self
._extract
_m
3u8_formats
( 
  50                     format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', 
  51                     m3u8_id
=format_type
, fatal
=False)) 
  52             elif format_type 
== 'HDS': 
  53                 formats
.extend(self
._extract
_f
4m
_formats
( 
  54                     format_url
, video_id
, f4m_id
=format_type
, fatal
=False)) 
  55             elif format_type 
== 'MPEG_DASH': 
  56                 formats
.extend(self
._extract
_mpd
_formats
( 
  57                     format_url
, video_id
, mpd_id
=format_type
, fatal
=False)) 
  58             elif format_type 
== 'HSS': 
  59                 formats
.extend(self
._extract
_ism
_formats
( 
  60                     format_url
, video_id
, ism_id
='mss', fatal
=False)) 
  63                     'format_id': format_type
, 
  66         self
._sort
_formats
(formats
) 
  69         subtitle_urls 
= data
.get('subtitleUrls') 
  70         if isinstance(subtitle_urls
, list): 
  71             for subtitle 
in subtitle_urls
: 
  72                 subtitle_url 
= subtitle
.get('url') 
  73                 if subtitle_url 
and subtitle
.get('type') == 'CLOSED': 
  74                     subtitles
.setdefault('nl', []).append({'url': subtitle_url
}) 
  78             'display_id': video_id
, 
  80             'description': description
, 
  82             'duration': float_or_none(data
.get('duration'), 1000), 
  83             'thumbnail': data
.get('posterImageUrl'), 
  84             'subtitles': subtitles
, 
  88 class CanvasEenIE(InfoExtractor
): 
  89     IE_DESC 
= 'canvas.be and een.be' 
  90     _VALID_URL 
= r
'https?://(?:www\.)?(?P<site_id>canvas|een)\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)' 
  92         'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week', 
  93         'md5': 'ed66976748d12350b118455979cca293', 
  95             'id': 'mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e', 
  96             'display_id': 'de-afspraak-veilt-voor-de-warmste-week', 
  98             'title': 'De afspraak veilt voor de Warmste Week', 
  99             'description': 'md5:24cb860c320dc2be7358e0e5aa317ba6', 
 100             'thumbnail': r
're:^https?://.*\.jpg$', 
 103         'expected_warnings': ['is not a supported codec'], 
 106         'url': 'http://www.canvas.be/video/panorama/2016/pieter-0167', 
 108             'id': 'mz-ast-5240ff21-2d30-4101-bba6-92b5ec67c625', 
 109             'display_id': 'pieter-0167', 
 111             'title': 'Pieter 0167', 
 112             'description': 'md5:943cd30f48a5d29ba02c3a104dc4ec4e', 
 113             'thumbnail': r
're:^https?://.*\.jpg$', 
 122             'skip_download': True, 
 124         'skip': 'Pagina niet gevonden', 
 126         'url': 'https://www.een.be/sorry-voor-alles/herbekijk-sorry-voor-alles', 
 128             'id': 'mz-ast-11a587f8-b921-4266-82e2-0bce3e80d07f', 
 129             'display_id': 'herbekijk-sorry-voor-alles', 
 131             'title': 'Herbekijk Sorry voor alles', 
 132             'description': 'md5:8bb2805df8164e5eb95d6a7a29dc0dd3', 
 133             'thumbnail': r
're:^https?://.*\.jpg$', 
 137             'skip_download': True, 
 139         'skip': 'Episode no longer available', 
 141         'url': 'https://www.canvas.be/check-point/najaar-2016/de-politie-uw-vriend', 
 142         'only_matching': True, 
 145     def _real_extract(self
, url
): 
 146         mobj 
= re
.match(self
._VALID
_URL
, url
) 
 147         site_id
, display_id 
= mobj
.group('site_id'), mobj
.group('id') 
 149         webpage 
= self
._download
_webpage
(url
, display_id
) 
 151         title 
= strip_or_none(self
._search
_regex
( 
 152             r
'<h1[^>]+class="video__body__header__title"[^>]*>(.+?)</h1>', 
 153             webpage
, 'title', default
=None) or self
._og
_search
_title
( 
 154             webpage
, default
=None)) 
 156         video_id 
= self
._html
_search
_regex
( 
 157             r
'data-video=(["\'])(?P
<id>(?
:(?
!\
1).)+)\
1', webpage, 'video 
id', 
 161             '_type
': 'url_transparent
', 
 162             'url
': 'https
://mediazone
.vrt
.be
/api
/v1
/%s/assets
/%s' % (site_id, video_id), 
 163             'ie_key
': CanvasIE.ie_key(), 
 165             'display_id
': display_id, 
 167             'description
': self._og_search_description(webpage),