diff options
author | Remita Amine <remitamine@gmail.com> | 2019-03-06 09:28:14 +0100 |
---|---|---|
committer | Remita Amine <remitamine@gmail.com> | 2019-03-06 09:28:14 +0100 |
commit | 7b6e76087080eac54e14cdead4e3bc0225c654b5 (patch) | |
tree | 202c1ddac4813ce5a7c41cf5172f67fe5a3c916d /youtube_dl/extractor | |
parent | 829685b88a0c7610a874b980bc25b308c4f34590 (diff) | |
download | youtube-dl-7b6e76087080eac54e14cdead4e3bc0225c654b5.tar.xz |
[toutv] detect invalid login error
Diffstat (limited to 'youtube_dl/extractor')
-rw-r--r-- | youtube_dl/extractor/toutv.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/youtube_dl/extractor/toutv.py b/youtube_dl/extractor/toutv.py index 124ca064c..25e1fd46d 100644 --- a/youtube_dl/extractor/toutv.py +++ b/youtube_dl/extractor/toutv.py @@ -4,7 +4,9 @@ from __future__ import unicode_literals import json from .radiocanada import RadioCanadaIE +from ..compat import compat_HTTPError from ..utils import ( + ExtractorError, int_or_none, merge_dicts, ) @@ -42,18 +44,24 @@ class TouTvIE(RadioCanadaIE): email, password = self._get_login_info() if email is None: return - self._access_token = self._download_json( - 'https://services.radio-canada.ca/toutv/profiling/accounts/login', - None, 'Logging in', data=json.dumps({ - 'ClientId': self._CLIENT_KEY, - 'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20', - 'Email': email, - 'Password': password, - 'Scope': 'id.write media-validation.read', - }).encode(), headers={ - 'Authorization': 'client-key ' + self._CLIENT_KEY, - 'Content-Type': 'application/json;charset=utf-8', - })['access_token'] + try: + self._access_token = self._download_json( + 'https://services.radio-canada.ca/toutv/profiling/accounts/login', + None, 'Logging in', data=json.dumps({ + 'ClientId': self._CLIENT_KEY, + 'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20', + 'Email': email, + 'Password': password, + 'Scope': 'id.write media-validation.read', + }).encode(), headers={ + 'Authorization': 'client-key ' + self._CLIENT_KEY, + 'Content-Type': 'application/json;charset=utf-8', + })['access_token'] + except ExtractorError as e: + if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401: + error = self._parse_json(e.cause.read().decode(), None)['Message'] + raise ExtractorError(error, expected=True) + raise self._claims = self._call_api('validation/v2/getClaims')['claims'] def _real_extract(self, url): |