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

pull/1581/head
morpheus65535 3 years ago
parent ff8865555a
commit 95a509cf23

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

Loading…
Cancel
Save