Fixed opensubtitles.com exception when invalid JSON is returned from provider. #1572

This commit is contained in:
morpheus65535 2021-10-10 08:20:54 -04:00
parent ff8865555a
commit 95a509cf23
1 changed files with 16 additions and 14 deletions

View File

@ -43,7 +43,7 @@ def fix_tv_naming(title):
def fix_movie_naming(title):
return fix_inconsistent_naming(title, {
}, True)
}, True)
class OpenSubtitlesComSubtitle(Subtitle):
@ -299,6 +299,8 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
try:
result = res.json()
if 'data' not in result:
raise ValueError
except ValueError:
raise ProviderError('Invalid JSON returned by provider')
else:
@ -323,19 +325,19 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
if len(item['attributes']['files']):
subtitle = OpenSubtitlesComSubtitle(
language=Language.fromietf(item['attributes']['language']),
forced=item['attributes']['foreign_parts_only'],
hearing_impaired=item['attributes']['hearing_impaired'],
page_link=item['attributes']['url'],
file_id=item['attributes']['files'][0]['file_id'],
releases=item['attributes']['release'],
uploader=item['attributes']['uploader']['name'],
title=item['attributes']['feature_details']['movie_name'],
year=item['attributes']['feature_details']['year'],
season=season_number,
episode=episode_number,
hash_matched=moviehash_match
)
language=Language.fromietf(item['attributes']['language']),
forced=item['attributes']['foreign_parts_only'],
hearing_impaired=item['attributes']['hearing_impaired'],
page_link=item['attributes']['url'],
file_id=item['attributes']['files'][0]['file_id'],
releases=item['attributes']['release'],
uploader=item['attributes']['uploader']['name'],
title=item['attributes']['feature_details']['movie_name'],
year=item['attributes']['feature_details']['year'],
season=season_number,
episode=episode_number,
hash_matched=moviehash_match
)
subtitle.get_matches(self.video)
subtitles.append(subtitle)