diff --git a/audalign/recognizers/correcognize/correcognize.py b/audalign/recognizers/correcognize/correcognize.py index c3f98ba..bad0f24 100644 --- a/audalign/recognizers/correcognize/correcognize.py +++ b/audalign/recognizers/correcognize/correcognize.py @@ -336,8 +336,10 @@ def _correcognize_dir( **kwargs, ) - except CouldntDecodeError: + except CouldntDecodeError as e: print(f'File "{against_file_path}" could not be decoded') + if config.fail_on_decode_error: + raise e return {} diff --git a/audalign/recognizers/correcognizeSpectrogram/correcognize_spectrogram.py b/audalign/recognizers/correcognizeSpectrogram/correcognize_spectrogram.py index 5cb5552..289ec15 100644 --- a/audalign/recognizers/correcognizeSpectrogram/correcognize_spectrogram.py +++ b/audalign/recognizers/correcognizeSpectrogram/correcognize_spectrogram.py @@ -336,8 +336,10 @@ def _correcognize_dir( **kwargs, ) - except CouldntDecodeError: + except CouldntDecodeError as e: print(f'File "{against_file_path}" could not be decoded') + if config.fail_on_decode_error: + raise e return {} diff --git a/audalign/recognizers/fingerprint/__init__.py b/audalign/recognizers/fingerprint/__init__.py index 8f5f4e1..3adbb18 100644 --- a/audalign/recognizers/fingerprint/__init__.py +++ b/audalign/recognizers/fingerprint/__init__.py @@ -10,6 +10,7 @@ import pickle import json import typing +from pydub.exceptions import CouldntDecodeError class FingerprintRecognizer(BaseRecognizer): @@ -266,6 +267,8 @@ def _fingerprint_directory( print("All files in directory already fingerprinted") else: print("Directory contains 0 files or could not be found") + if self.config.fail_on_decode_error: + raise CouldntDecodeError("Directory contains 0 files or could not be found") return if _file_audsegs is not None: diff --git a/audalign/recognizers/fingerprint/fingerprinter.py b/audalign/recognizers/fingerprint/fingerprinter.py index 4d73137..f8adfff 100644 --- a/audalign/recognizers/fingerprint/fingerprinter.py +++ b/audalign/recognizers/fingerprint/fingerprinter.py @@ -52,10 +52,12 @@ def _fingerprint_worker( except FileNotFoundError: print(f'"{file_path}" not found') return None, None - except ( - CouldntDecodeError, - IndexError, - ): # Pydub throws IndexErrors for some files on Ubuntu (json, txt, others?) + except CouldntDecodeError as e: + print(f'File "{file_name}" could not be decoded') + if config.fail_on_decode_error: + raise e + return None, None + except IndexError: # Pydub throws IndexErrors for some files on Ubuntu (json, txt, others?) print(f'File "{file_name}" could not be decoded') return None, None elif type(file_path) == tuple: diff --git a/audalign/recognizers/visrecognize/visrecognize.py b/audalign/recognizers/visrecognize/visrecognize.py index 9d8a540..6b660dc 100644 --- a/audalign/recognizers/visrecognize/visrecognize.py +++ b/audalign/recognizers/visrecognize/visrecognize.py @@ -176,8 +176,10 @@ def _visrecognize_directory( imgB_title=os.path.basename(file_path), ) return single_file_match - except CouldntDecodeError: + except CouldntDecodeError as e: print(f'File "{file_path}" could not be decoded') + if config.fail_on_decode_error: + raise e return {}