1
1
mirror of https://github.com/ytdl-org/youtube-dl synced 2024-11-27 06:36:49 +01:00

Improve error handling logic, follow code conventions

This commit is contained in:
NobleKangaroo 2021-01-27 17:01:25 -05:00
parent 4ecbc49a15
commit fd311fb1e3

View File

@ -110,24 +110,18 @@ class FunimationIE(InfoExtractor):
headers = {} headers = {}
if self._TOKEN: if self._TOKEN:
headers['Authorization'] = 'Token %s' % self._TOKEN headers['Authorization'] = 'Token %s' % self._TOKEN
try: meta = self._download_json(
sources = self._download_json( 'https://www.funimation.com/api/showexperience/%s/' % video_id,
'https://www.funimation.com/api/showexperience/%s/' % video_id, video_id, headers=headers, query={
video_id, headers=headers, query={ 'pinst_id': ''.join([random.choice(string.digits + string.ascii_letters) for _ in range(8)]),
'pinst_id': ''.join([random.choice(string.digits + string.ascii_letters) for _ in range(8)]), })
}) sources = meta.get('items') or []
sources = sources['items'] errors = meta.get('errors')
except KeyError: if errors:
if 'errors' in sources: if isinstance(errors, list):
errors = sources['errors'] raise ExtractorError('\nERROR: '.join([error.get('detail') or error.get('title') or str(error) for error in errors]), expected=True)
if len(errors) > 0: else:
error = errors[0] raise ExtractorError(errors, expected=True)
if 'detail' in error:
detail = error['detail']
raise ExtractorError('%s said: %s' % (
self.IE_NAME, detail), expected=True)
else:
raise ExtractorError(error, expected=True)
except ExtractorError as e: except ExtractorError as e:
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
error = self._parse_json(e.cause.read(), video_id)['errors'][0] error = self._parse_json(e.cause.read(), video_id)['errors'][0]