diff options
author | JayZed <[email protected]> | 2024-10-30 16:58:33 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-10-30 16:58:33 -0400 |
commit | 2c8712f8913169db6bae2e8e66903dafa3d88a98 (patch) | |
tree | 2e4a1484b3de7cb797bb8efcb69c794b1922b4f3 /custom_libs | |
parent | 4eb09c546d4ebb612340de80301fdfc7549843b1 (diff) | |
download | bazarr-2c8712f8913169db6bae2e8e66903dafa3d88a98.tar.gz bazarr-2c8712f8913169db6bae2e8e66903dafa3d88a98.zip |
Handle empty responses from whisper to prevent JSONDecodeErrors
Diffstat (limited to 'custom_libs')
-rw-r--r-- | custom_libs/subliminal_patch/providers/whisperai.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/custom_libs/subliminal_patch/providers/whisperai.py b/custom_libs/subliminal_patch/providers/whisperai.py index 0546717a2..4b3fa466c 100644 --- a/custom_libs/subliminal_patch/providers/whisperai.py +++ b/custom_libs/subliminal_patch/providers/whisperai.py @@ -5,6 +5,7 @@ from datetime import timedelta from requests import Session +from requests.exceptions import JSONDecodeError from subliminal_patch.subtitle import Subtitle from subliminal_patch.providers import Provider from subliminal import __short_version__ @@ -269,10 +270,19 @@ class WhisperAIProvider(Provider): params={'encode': 'false'}, files={'audio_file': out}, timeout=(self.response, self.timeout)) + + try: + results = r.json() + except JSONDecodeError: + results = {} + + if len(results) == 0: + logger.info(f"Whisper returned empty response when detecting language") + return None - logger.debug(f"Whisper detected language of {path} as {r.json()['detected_language']}") + logger.debug(f"Whisper detected language of {path} as {results['detected_language']}") - return whisper_get_language(r.json()["language_code"], r.json()["detected_language"]) + return whisper_get_language(results["language_code"], results["detected_language"]) def query(self, language, video): if language not in self.languages: |