]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/toutv.py
2e7876cc5b392be0f6524744c676664d66c2b5f8
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class TouTvIE(InfoExtractor
):
17 _NETRC_MACHINE
= 'toutv'
19 _VALID_URL
= r
'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+[EC][0-9]+)?)'
24 'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17',
28 'title': 'Saison 2015 Épisode 17',
29 'description': 'La photo de famille 2',
30 'upload_date': '20100717',
34 'skip_download': True,
36 'skip': '404 Not Found',
38 'url': 'http://ici.tou.tv/hackers',
39 'only_matching': True,
41 'url': 'https://ici.tou.tv/l-age-adulte/S01C501',
42 'only_matching': True,
45 def _real_initialize(self
):
46 email
, password
= self
._get
_login
_info
()
49 state
= 'http://ici.tou.tv/'
50 webpage
= self
._download
_webpage
(state
, None, 'Downloading homepage')
51 toutvlogin
= self
._parse
_json
(self
._search
_regex
(
52 r
'(?s)toutvlogin\s*=\s*({.+?});', webpage
, 'toutvlogin'), None, js_to_json
)
53 authorize_url
= toutvlogin
['host'] + '/auth/oauth/v2/authorize'
54 login_webpage
= self
._download
_webpage
(
55 authorize_url
, None, 'Downloading login page', query
={
56 'client_id': toutvlogin
['clientId'],
57 'redirect_uri': 'https://ici.tou.tv/login/loginCallback',
58 'response_type': 'token',
59 'scope': 'media-drmt openid profile email id.write media-validation.read.privileged',
63 def extract_form_url_and_data(wp
, default_form_url
, form_spec_re
=''):
64 form
, form_elem
= re
.search(
65 r
'(?s)((<form[^>]+?%s[^>]*?>).+?</form>)' % form_spec_re
, wp
).groups()
66 form_data
= self
._hidden
_inputs
(form
)
67 form_url
= extract_attributes(form_elem
).get('action') or default_form_url
68 return form_url
, form_data
70 post_url
, form_data
= extract_form_url_and_data(
72 'https://services.radio-canada.ca/auth/oauth/v2/authorize/login',
73 r
'(?:id|name)="Form-login"')
76 'login-password': password
,
78 consent_webpage
= self
._download
_webpage
(
79 post_url
, None, 'Logging in', data
=urlencode_postdata(form_data
))
80 post_url
, form_data
= extract_form_url_and_data(
82 'https://services.radio-canada.ca/auth/oauth/v2/authorize/consent')
83 _
, urlh
= self
._download
_webpage
_handle
(
84 post_url
, None, 'Following Redirection',
85 data
=urlencode_postdata(form_data
))
86 self
._access
_token
= self
._search
_regex
(
87 r
'access_token=([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
88 urlh
.geturl(), 'access token')
89 self
._claims
= self
._download
_json
(
90 'https://services.radio-canada.ca/media/validation/v2/getClaims',
91 None, 'Extracting Claims', query
={
92 'token': self
._access
_token
,
93 'access_token': self
._access
_token
,
96 def _real_extract(self
, url
):
97 path
= self
._match
_id
(url
)
98 metadata
= self
._download
_json
('http://ici.tou.tv/presentation/%s' % path
, path
)
99 # IsDrm does not necessarily mean the video is DRM protected (see
100 # https://github.com/rg3/youtube-dl/issues/13994).
101 if metadata
.get('IsDrm'):
102 self
.report_warning('This video is probably DRM protected.', path
)
103 video_id
= metadata
['IdMedia']
104 details
= metadata
['Details']
105 title
= details
['OriginalTitle']
106 video_url
= 'radiocanada:%s:%s' % (metadata
.get('AppCode', 'toutv'), video_id
)
107 if self
._access
_token
and self
._claims
:
108 video_url
= smuggle_url(video_url
, {
109 'access_token': self
._access
_token
,
110 'claims': self
._claims
,
114 '_type': 'url_transparent',
118 'thumbnail': details
.get('ImageUrl'),
119 'duration': int_or_none(details
.get('LengthInSeconds')),