]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/toutv.py
e59ed266109d16e12e7c64a9ba499ef4c116e449
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
14 class TouTvIE(InfoExtractor
):
15 _NETRC_MACHINE
= 'toutv'
17 _VALID_URL
= r
'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+E[0-9]+)?)'
22 'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17',
26 'title': 'Saison 2015 Épisode 17',
27 'description': 'La photo de famille 2',
28 'upload_date': '20100717',
32 'skip_download': True,
34 'skip': '404 Not Found',
36 'url': 'http://ici.tou.tv/hackers',
37 'only_matching': True,
40 def _real_initialize(self
):
41 email
, password
= self
._get
_login
_info
()
44 state
= 'http://ici.tou.tv//'
45 webpage
= self
._download
_webpage
(state
, None, 'Downloading homepage')
46 toutvlogin
= self
._parse
_json
(self
._search
_regex
(
47 r
'(?s)toutvlogin\s*=\s*({.+?});', webpage
, 'toutvlogin'), None, js_to_json
)
48 authorize_url
= toutvlogin
['host'] + '/auth/oauth/v2/authorize'
49 login_webpage
= self
._download
_webpage
(
50 authorize_url
, None, 'Downloading login page', query
={
51 'client_id': toutvlogin
['clientId'],
52 'redirect_uri': 'https://ici.tou.tv/login/loginCallback',
53 'response_type': 'token',
54 'scope': 'media-drmt openid profile email id.write media-validation.read.privileged',
57 login_form
= self
._search
_regex
(
58 r
'(?s)(<form[^>]+(?:id|name)="Form-login".+?</form>)', login_webpage
, 'login form')
59 form_data
= self
._hidden
_inputs
(login_form
)
62 'login-password': password
,
64 post_url
= extract_attributes(login_form
).get('action') or authorize_url
65 _
, urlh
= self
._download
_webpage
_handle
(
66 post_url
, None, 'Logging in', data
=urlencode_postdata(form_data
))
67 self
._access
_token
= self
._search
_regex
(
68 r
'access_token=([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
69 urlh
.geturl(), 'access token')
70 self
._claims
= self
._download
_json
(
71 'https://services.radio-canada.ca/media/validation/v2/getClaims',
72 None, 'Extracting Claims', query
={
73 'token': self
._access
_token
,
74 'access_token': self
._access
_token
,
77 def _real_extract(self
, url
):
78 path
= self
._match
_id
(url
)
79 metadata
= self
._download
_json
('http://ici.tou.tv/presentation/%s' % path
, path
)
80 # IsDrm does not necessarily mean the video is DRM protected (see
81 # https://github.com/rg3/youtube-dl/issues/13994).
82 if metadata
.get('IsDrm'):
83 self
.report_warning('This video is probably DRM protected.', path
)
84 video_id
= metadata
['IdMedia']
85 details
= metadata
['Details']
86 title
= details
['OriginalTitle']
87 video_url
= 'radiocanada:%s:%s' % (metadata
.get('AppCode', 'toutv'), video_id
)
88 if self
._access
_token
and self
._claims
:
89 video_url
= smuggle_url(video_url
, {
90 'access_token': self
._access
_token
,
91 'claims': self
._claims
,
95 '_type': 'url_transparent',
99 'thumbnail': details
.get('ImageUrl'),
100 'duration': int_or_none(details
.get('LengthInSeconds')),