diff options
author | Remita Amine <remitamine@gmail.com> | 2018-05-21 15:07:24 +0100 |
---|---|---|
committer | Remita Amine <remitamine@gmail.com> | 2018-05-21 15:07:24 +0100 |
commit | e5187493002f1d089d450fc3b2b4af64c996dc71 (patch) | |
tree | 863a345368cb73de7582b9b7587bde33e30eff02 /youtube_dl/extractor/globo.py | |
parent | db2058f63e64ff59ffad0e1e8ad5e18d18d3da71 (diff) |
[globo] handle login errors
Diffstat (limited to 'youtube_dl/extractor/globo.py')
-rw-r--r-- | youtube_dl/extractor/globo.py | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/youtube_dl/extractor/globo.py b/youtube_dl/extractor/globo.py index 730deda6b..9c2360464 100644 --- a/youtube_dl/extractor/globo.py +++ b/youtube_dl/extractor/globo.py @@ -8,7 +8,10 @@ import random import re from .common import InfoExtractor -from ..compat import compat_str +from ..compat import ( + compat_HTTPError, + compat_str, +) from ..utils import ( ExtractorError, float_or_none, @@ -71,16 +74,22 @@ class GloboIE(InfoExtractor): if email is None: return - self._download_json( - 'https://login.globo.com/api/authentication', None, data=json.dumps({ - 'payload': { - 'email': email, - 'password': password, - 'serviceId': 4654, - }, - }).encode(), headers={ - 'Content-Type': 'application/json; charset=utf-8', - }) + try: + self._download_json( + 'https://login.globo.com/api/authentication', None, data=json.dumps({ + 'payload': { + 'email': email, + 'password': password, + 'serviceId': 4654, + }, + }).encode(), headers={ + 'Content-Type': 'application/json; charset=utf-8', + }) + except ExtractorError as e: + if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401: + resp = self._parse_json(e.cause.read(), None) + raise ExtractorError(resp.get('userMessage') or resp['id'], expected=True) + raise self._LOGGED_IN = True def _real_extract(self, url): |