From 9e8830a9119fd705730711c893f9d321abd04ec5 Mon Sep 17 00:00:00 2001 From: tandy1000 Date: Sun, 24 Sep 2023 22:18:20 +0100 Subject: [PATCH] fixup! handle libsndfile error --- beetsplug/autobpm.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/beetsplug/autobpm.py b/beetsplug/autobpm.py index 81c936c8dc..f0921c0860 100644 --- a/beetsplug/autobpm.py +++ b/beetsplug/autobpm.py @@ -22,6 +22,7 @@ from beets.plugins import BeetsPlugin from librosa import load, beat +from soundfile import LibsndfileError class AutoBPMPlugin(BeetsPlugin): @@ -54,10 +55,15 @@ def calculate_bpm(self, items, write=False): if item['bpm'] and not overwrite: continue - y, sr = load(util.syspath(item.path), res_type="kaiser_fast") - tempo, _ = beat.beat_track(y=y, sr=sr) - bpm = round(tempo) + try: + y, sr = load(util.syspath(item.path), res_type="kaiser_fast") + tempo, _ = beat.beat_track(y=y, sr=sr) + except LibsndfileError: + self._log.error('failed to load track for {0}', + util.displayable_path(item.path)) + continue + bpm = round(tempo) item['bpm'] = bpm self._log.info('added computed bpm {0} for {1}', bpm, util.displayable_path(item.path))