1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from .gigya
import GigyaBaseIE
8 from ..compat
import compat_HTTPError
21 class CanvasIE(InfoExtractor
):
22 _VALID_URL
= r
'https?://mediazone\.vrt\.be/api/v1/(?P<site_id>canvas|een|ketnet|vrt(?:video|nieuws)|sporza)/assets/(?P<id>[^/?#&]+)'
24 'url': 'https://mediazone.vrt.be/api/v1/ketnet/assets/md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
25 'md5': '68993eda72ef62386a15ea2cf3c93107',
27 'id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
28 'display_id': 'md-ast-4ac54990-ce66-4d00-a8ca-9eac86f4c475',
30 'title': 'Nachtwacht: De Greystook',
31 'description': 'Nachtwacht: De Greystook',
32 'thumbnail': r
're:^https?://.*\.jpg$',
35 'expected_warnings': ['is not a supported codec', 'Unknown MIME type'],
37 'url': 'https://mediazone.vrt.be/api/v1/canvas/assets/mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e',
38 'only_matching': True,
41 _HLS_ENTRY_PROTOCOLS_MAP
= {
45 _REST_API_BASE
= 'https://media-services-public.vrt.be/vualto-video-aggregator-web/rest/external/v1'
47 def _real_extract(self
, url
):
48 mobj
= re
.match(self
._VALID
_URL
, url
)
49 site_id
, video_id
= mobj
.group('site_id'), mobj
.group('id')
52 if site_id
!= 'vrtvideo':
53 # Old API endpoint, serves more formats but may fail for some videos
54 data
= self
._download
_json
(
55 'https://mediazone.vrt.be/api/v1/%s/assets/%s'
56 % (site_id
, video_id
), video_id
, 'Downloading asset JSON',
57 'Unable to download asset JSON', fatal
=False)
61 headers
= self
.geo_verification_headers()
62 headers
.update({'Content-Type': 'application/json'}
)
63 token
= self
._download
_json
(
64 '%s/tokens' % self
._REST
_API
_BASE
, video_id
,
65 'Downloading token', data
=b
'', headers
=headers
)['vrtPlayerToken']
66 data
= self
._download
_json
(
67 '%s/videos/%s' % (self
._REST
_API
_BASE
, video_id
),
68 video_id
, 'Downloading video JSON', query
={
69 'vrtPlayerToken': token
,
70 'client': '%s@PROD' % site_id
,
71 }, expected_status
=400)
72 if not data
.get('title'):
73 code
= data
.get('code')
74 if code
== 'AUTHENTICATION_REQUIRED':
75 self
.raise_login_required()
76 elif code
== 'INVALID_LOCATION':
77 self
.raise_geo_restricted(countries
=['BE'])
78 raise ExtractorError(data
.get('message') or code
, expected
=True)
81 description
= data
.get('description')
84 for target
in data
['targetUrls']:
85 format_url
, format_type
= url_or_none(target
.get('url')), str_or_none(target
.get('type'))
86 if not format_url
or not format_type
:
88 format_type
= format_type
.upper()
89 if format_type
in self
._HLS
_ENTRY
_PROTOCOLS
_MAP
:
90 formats
.extend(self
._extract
_m
3u8_formats
(
91 format_url
, video_id
, 'mp4', self
._HLS
_ENTRY
_PROTOCOLS
_MAP
[format_type
],
92 m3u8_id
=format_type
, fatal
=False))
93 elif format_type
== 'HDS':
94 formats
.extend(self
._extract
_f
4m
_formats
(
95 format_url
, video_id
, f4m_id
=format_type
, fatal
=False))
96 elif format_type
== 'MPEG_DASH':
97 formats
.extend(self
._extract
_mpd
_formats
(
98 format_url
, video_id
, mpd_id
=format_type
, fatal
=False))
99 elif format_type
== 'HSS':
100 formats
.extend(self
._extract
_ism
_formats
(
101 format_url
, video_id
, ism_id
='mss', fatal
=False))
104 'format_id': format_type
,
107 self
._sort
_formats
(formats
)
110 subtitle_urls
= data
.get('subtitleUrls')
111 if isinstance(subtitle_urls
, list):
112 for subtitle
in subtitle_urls
:
113 subtitle_url
= subtitle
.get('url')
114 if subtitle_url
and subtitle
.get('type') == 'CLOSED':
115 subtitles
.setdefault('nl', []).append({'url': subtitle_url}
)
119 'display_id': video_id
,
121 'description': description
,
123 'duration': float_or_none(data
.get('duration'), 1000),
124 'thumbnail': data
.get('posterImageUrl'),
125 'subtitles': subtitles
,
129 class CanvasEenIE(InfoExtractor
):
130 IE_DESC
= 'canvas.be and een.be'
131 _VALID_URL
= r
'https?://(?:www\.)?(?P<site_id>canvas|een)\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)'
133 'url': 'http://www.canvas.be/video/de-afspraak/najaar-2015/de-afspraak-veilt-voor-de-warmste-week',
134 'md5': 'ed66976748d12350b118455979cca293',
136 'id': 'mz-ast-5e5f90b6-2d72-4c40-82c2-e134f884e93e',
137 'display_id': 'de-afspraak-veilt-voor-de-warmste-week',
139 'title': 'De afspraak veilt voor de Warmste Week',
140 'description': 'md5:24cb860c320dc2be7358e0e5aa317ba6',
141 'thumbnail': r
're:^https?://.*\.jpg$',
144 'expected_warnings': ['is not a supported codec'],
147 'url': 'http://www.canvas.be/video/panorama/2016/pieter-0167',
149 'id': 'mz-ast-5240ff21-2d30-4101-bba6-92b5ec67c625',
150 'display_id': 'pieter-0167',
152 'title': 'Pieter 0167',
153 'description': 'md5:943cd30f48a5d29ba02c3a104dc4ec4e',
154 'thumbnail': r
're:^https?://.*\.jpg$',
163 'skip_download': True,
165 'skip': 'Pagina niet gevonden',
167 'url': 'https://www.een.be/thuis/emma-pakt-thilly-aan',
169 'id': 'md-ast-3a24ced2-64d7-44fb-b4ed-ed1aafbf90b8',
170 'display_id': 'emma-pakt-thilly-aan',
172 'title': 'Emma pakt Thilly aan',
173 'description': 'md5:c5c9b572388a99b2690030afa3f3bad7',
174 'thumbnail': r
're:^https?://.*\.jpg$',
178 'skip_download': True,
180 'expected_warnings': ['is not a supported codec'],
182 'url': 'https://www.canvas.be/check-point/najaar-2016/de-politie-uw-vriend',
183 'only_matching': True,
186 def _real_extract(self
, url
):
187 mobj
= re
.match(self
._VALID
_URL
, url
)
188 site_id
, display_id
= mobj
.group('site_id'), mobj
.group('id')
190 webpage
= self
._download
_webpage
(url
, display_id
)
192 title
= strip_or_none(self
._search
_regex
(
193 r
'<h1[^>]+class="video__body__header__title"[^>]*>(.+?)</h1>',
194 webpage
, 'title', default
=None) or self
._og
_search
_title
(
195 webpage
, default
=None))
197 video_id
= self
._html
_search
_regex
(
198 r
'data-video=(["\'])(?P
<id>(?
:(?
!\
1).)+)\
1', webpage, 'video
id',
202 '_type
': 'url_transparent
',
203 'url
': 'https
://mediazone
.vrt
.be
/api
/v1
/%s/assets
/%s' % (site_id, video_id),
204 'ie_key
': CanvasIE.ie_key(),
206 'display_id
': display_id,
208 'description
': self._og_search_description(webpage),
212 class VrtNUIE(GigyaBaseIE):
214 _VALID_URL = r'https?
://(?
:www\
.)?vrt\
.be
/vrtnu
/a
-z
/(?
:[^
/]+/){2}
(?P
<id>[^
/?
#&]+)'
216 # Available via old API endpoint
217 'url': 'https://www.vrt.be/vrtnu/a-z/postbus-x/1989/postbus-x-s1989a1/',
219 'id': 'pbs-pub-e8713dac-899e-41de-9313-81269f4c04ac$vid-90c932b1-e21d-4fb8-99b1-db7b49cf74de',
221 'title': 'Postbus X - Aflevering 1 (Seizoen 1989)',
222 'description': 'md5:b704f669eb9262da4c55b33d7c6ed4b7',
224 'thumbnail': r
're:^https?://.*\.jpg$',
225 'series': 'Postbus X',
226 'season': 'Seizoen 1989',
227 'season_number': 1989,
228 'episode': 'De zwarte weduwe',
230 'timestamp': 1595822400,
231 'upload_date': '20200727',
233 'skip': 'This video is only available for registered users',
235 'username': '<snip>',
236 'password': '<snip>',
238 'expected_warnings': ['is not a supported codec'],
240 # Only available via new API endpoint
241 'url': 'https://www.vrt.be/vrtnu/a-z/kamp-waes/1/kamp-waes-s1a5/',
243 'id': 'pbs-pub-0763b56c-64fb-4d38-b95b-af60bf433c71$vid-ad36a73c-4735-4f1f-b2c0-a38e6e6aa7e1',
245 'title': 'Aflevering 5',
246 'description': 'Wie valt door de mand tijdens een missie?',
248 'season': 'Season 1',
252 'skip': 'This video is only available for registered users',
254 'username': '<snip>',
255 'password': '<snip>',
257 'expected_warnings': ['Unable to download asset JSON', 'is not a supported codec', 'Unknown MIME type'],
259 _NETRC_MACHINE
= 'vrtnu'
260 _APIKEY
= '3_0Z2HujMtiWq_pkAjgnS2Md2E11a1AwZjYiBETtwNE-EoEHDINgtnvcAOpNgmrVGy'
261 _CONTEXT_ID
= 'R3595707040'
263 def _real_initialize(self
):
267 username
, password
= self
._get
_login
_info
()
272 'APIKey': self
._APIKEY
,
273 'targetEnv': 'jssdk',
275 'password': password
,
276 'authMode': 'cookie',
279 auth_info
= self
._gigya
_login
(auth_data
)
281 # Sometimes authentication fails for no good reason, retry
283 while login_attempt
<= 3:
285 # When requesting a token, no actual token is returned, but the
286 # necessary cookies are set.
287 self
._request
_webpage
(
288 'https://token.vrt.be',
289 None, note
='Requesting a token', errnote
='Could not get a token',
291 'Content-Type': 'application/json',
292 'Referer': 'https://www.vrt.be/vrtnu/',
295 'uid': auth_info
['UID'],
296 'uidsig': auth_info
['UIDSignature'],
297 'ts': auth_info
['signatureTimestamp'],
298 'email': auth_info
['profile']['email'],
300 except ExtractorError
as e
:
301 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
303 self
.report_warning('Authentication failed')
304 self
._sleep
(1, None, msg_template
='Waiting for %(timeout)s seconds before trying again')
310 def _real_extract(self
, url
):
311 display_id
= self
._match
_id
(url
)
313 webpage
= self
._download
_webpage
(url
, display_id
)
315 attrs
= extract_attributes(self
._search
_regex
(
316 r
'(<nui-media[^>]+>)', webpage
, 'media element'))
317 video_id
= attrs
['videoid']
318 publication_id
= attrs
.get('publicationid')
320 video_id
= publication_id
+ '$' + video_id
322 page
= (self
._parse
_json
(self
._search
_regex
(
323 r
'digitalData\s*=\s*({.+?});', webpage
, 'digial data',
324 default
='{}'), video_id, fatal=False) or {}).get('page
') or {}
326 info = self._search_json_ld(webpage, display_id, default={})
327 return merge_dicts(info, {
328 '_type
': 'url_transparent
',
329 'url
': 'https
://mediazone
.vrt
.be
/api
/v1
/vrtvideo
/assets
/%s' % video_id,
330 'ie_key
': CanvasIE.ie_key(),
332 'display_id
': display_id,
333 'season_number
': int_or_none(page.get('episode_season
')),