]>
Commit | Line | Data |
---|---|---|
59040888 | 1 | # coding: utf-8 |
8c820776 S |
2 | from __future__ import unicode_literals |
3 | ||
d7df3089 RA |
4 | import re |
5 | ||
8fecc735 | 6 | from .radiocanada import RadioCanadaIE |
98b7506e | 7 | from ..utils import ( |
8fecc735 | 8 | extract_attributes, |
98b7506e | 9 | int_or_none, |
8fecc735 | 10 | merge_dicts, |
98b7506e | 11 | urlencode_postdata, |
98b7506e | 12 | ) |
59040888 PH |
13 | |
14 | ||
8fecc735 | 15 | class TouTvIE(RadioCanadaIE): |
98b7506e | 16 | _NETRC_MACHINE = 'toutv' |
8c820776 | 17 | IE_NAME = 'tou.tv' |
e6b8803d | 18 | _VALID_URL = r'https?://ici\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/S[0-9]+[EC][0-9]+)?)' |
59040888 | 19 | |
de328af3 | 20 | _TESTS = [{ |
882af14d | 21 | 'url': 'http://ici.tou.tv/garfield-tout-court/S2015E17', |
8c820776 | 22 | 'info_dict': { |
882af14d | 23 | 'id': '122017', |
057c0609 | 24 | 'ext': 'mp4', |
882af14d | 25 | 'title': 'Saison 2015 Épisode 17', |
26 | 'description': 'La photo de famille 2', | |
27 | 'upload_date': '20100717', | |
59040888 | 28 | }, |
8c820776 | 29 | 'params': { |
882af14d | 30 | # m3u8 download |
31 | 'skip_download': True, | |
59040888 | 32 | }, |
98b7506e | 33 | 'skip': '404 Not Found', |
de328af3 S |
34 | }, { |
35 | 'url': 'http://ici.tou.tv/hackers', | |
36 | 'only_matching': True, | |
e6b8803d RA |
37 | }, { |
38 | 'url': 'https://ici.tou.tv/l-age-adulte/S01C501', | |
39 | 'only_matching': True, | |
de328af3 | 40 | }] |
59040888 | 41 | |
98b7506e RA |
42 | def _real_initialize(self): |
43 | email, password = self._get_login_info() | |
44 | if email is None: | |
45 | return | |
98b7506e | 46 | login_webpage = self._download_webpage( |
8fecc735 RA |
47 | 'https://services.radio-canada.ca/auth/oauth/v2/authorize', |
48 | None, 'Downloading login page', query={ | |
49 | 'client_id': '4dd36440-09d5-4468-8923-b6d91174ad36', | |
50 | 'redirect_uri': 'https://ici.tou.tv/logincallback', | |
98b7506e | 51 | 'response_type': 'token', |
8fecc735 RA |
52 | 'scope': 'id.write media-validation.read', |
53 | 'state': '/', | |
98b7506e | 54 | }) |
d7df3089 RA |
55 | |
56 | def extract_form_url_and_data(wp, default_form_url, form_spec_re=''): | |
57 | form, form_elem = re.search( | |
58 | r'(?s)((<form[^>]+?%s[^>]*?>).+?</form>)' % form_spec_re, wp).groups() | |
59 | form_data = self._hidden_inputs(form) | |
60 | form_url = extract_attributes(form_elem).get('action') or default_form_url | |
61 | return form_url, form_data | |
62 | ||
63 | post_url, form_data = extract_form_url_and_data( | |
64 | login_webpage, | |
65 | 'https://services.radio-canada.ca/auth/oauth/v2/authorize/login', | |
66 | r'(?:id|name)="Form-login"') | |
98b7506e RA |
67 | form_data.update({ |
68 | 'login-email': email, | |
69 | 'login-password': password, | |
70 | }) | |
d7df3089 | 71 | consent_webpage = self._download_webpage( |
98b7506e | 72 | post_url, None, 'Logging in', data=urlencode_postdata(form_data)) |
d7df3089 RA |
73 | post_url, form_data = extract_form_url_and_data( |
74 | consent_webpage, | |
75 | 'https://services.radio-canada.ca/auth/oauth/v2/authorize/consent') | |
76 | _, urlh = self._download_webpage_handle( | |
77 | post_url, None, 'Following Redirection', | |
78 | data=urlencode_postdata(form_data)) | |
98b7506e RA |
79 | self._access_token = self._search_regex( |
80 | r'access_token=([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})', | |
81 | urlh.geturl(), 'access token') | |
8fecc735 | 82 | self._claims = self._call_api('validation/v2/getClaims')['claims'] |
98b7506e | 83 | |
59040888 | 84 | def _real_extract(self, url): |
882af14d | 85 | path = self._match_id(url) |
86 | metadata = self._download_json('http://ici.tou.tv/presentation/%s' % path, path) | |
8d7a24af S |
87 | # IsDrm does not necessarily mean the video is DRM protected (see |
88 | # https://github.com/rg3/youtube-dl/issues/13994). | |
98b7506e | 89 | if metadata.get('IsDrm'): |
8d7a24af | 90 | self.report_warning('This video is probably DRM protected.', path) |
882af14d | 91 | video_id = metadata['IdMedia'] |
92 | details = metadata['Details'] | |
59040888 | 93 | |
8fecc735 | 94 | return merge_dicts({ |
59040888 | 95 | 'id': video_id, |
8fecc735 | 96 | 'title': details.get('OriginalTitle'), |
882af14d | 97 | 'thumbnail': details.get('ImageUrl'), |
98 | 'duration': int_or_none(details.get('LengthInSeconds')), | |
8fecc735 | 99 | }, self._extract_info(metadata.get('AppCode', 'toutv'), video_id)) |