Skip to content

Commit

Permalink
fixup! handle libsndfile error
Browse files Browse the repository at this point in the history
  • Loading branch information
tandy-1000 committed Sep 24, 2023
1 parent f685231 commit 9e8830a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions beetsplug/autobpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from beets.plugins import BeetsPlugin

from librosa import load, beat
from soundfile import LibsndfileError

class AutoBPMPlugin(BeetsPlugin):

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 9e8830a

Please sign in to comment.