[toutv] detect invalid login error

This commit is contained in:
Remita Amine 2019-03-06 09:28:14 +01:00
parent 829685b88a
commit 7b6e760870

View file

@ -4,7 +4,9 @@ from __future__ import unicode_literals
import json import json
from .radiocanada import RadioCanadaIE from .radiocanada import RadioCanadaIE
from ..compat import compat_HTTPError
from ..utils import ( from ..utils import (
ExtractorError,
int_or_none, int_or_none,
merge_dicts, merge_dicts,
) )
@ -42,18 +44,24 @@ class TouTvIE(RadioCanadaIE):
email, password = self._get_login_info() email, password = self._get_login_info()
if email is None: if email is None:
return return
self._access_token = self._download_json( try:
'https://services.radio-canada.ca/toutv/profiling/accounts/login', self._access_token = self._download_json(
None, 'Logging in', data=json.dumps({ 'https://services.radio-canada.ca/toutv/profiling/accounts/login',
'ClientId': self._CLIENT_KEY, None, 'Logging in', data=json.dumps({
'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20', 'ClientId': self._CLIENT_KEY,
'Email': email, 'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20',
'Password': password, 'Email': email,
'Scope': 'id.write media-validation.read', 'Password': password,
}).encode(), headers={ 'Scope': 'id.write media-validation.read',
'Authorization': 'client-key ' + self._CLIENT_KEY, }).encode(), headers={
'Content-Type': 'application/json;charset=utf-8', 'Authorization': 'client-key ' + self._CLIENT_KEY,
})['access_token'] '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'] self._claims = self._call_api('validation/v2/getClaims')['claims']
def _real_extract(self, url): def _real_extract(self, url):