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