From 2140bb27a30eff77645eb3eae819098f3c94fc14 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 7 Sep 2015 14:15:46 -0700 Subject: [PATCH] Fix #1592: unhandled exception in PyAudioTools --- beetsplug/replaygain.py | 8 +++++++- docs/changelog.rst | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 3c9c0042a..e621e9b21 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -711,7 +711,13 @@ class AudioToolsBackend(Backend): # of the track. # Note that the method needs an audiotools.PCMReader instance that can # be obtained from an audiofile instance. - rg_track_gain, rg_track_peak = rg.title_gain(audiofile.to_pcm()) + try: + rg_track_gain, rg_track_peak = rg.title_gain(audiofile.to_pcm()) + except ValueError as exc: + # `audiotools.replaygain` can raise a `ValueError` if the sample + # rate is incorrect. + self._log.debug('error in rg.title_gain() call: {}', exc) + raise ReplayGainError('audiotools audio data error') self._log.debug(u'ReplayGain for track {0} - {1}: {2:.2f}, {3:.2f}', item.artist, item.title, rg_track_gain, rg_track_peak) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5fb335a34..24b96fb56 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -39,6 +39,8 @@ Fixes: * Date fields are now written in the correct order (year-month-day), which eliminates an intermittent bug where the latter two fields would not get written to files. Thanks to :user:`jdetrey`. :bug:`1303` :bug:`1589` +* :doc:`/plugins/replaygain`: Avoid a crash when the PyAudioTools backend + encounters an error. :bug:`1592` 1.3.14 (August 2, 2015)