diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index acf996bd2..babb469ad 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -501,14 +501,25 @@ class GStreamerBackend(Backend): if len(self._file_tags) != len(items): raise ReplayGainError("Some items in album did not receive tags") - ret = [] + # Collect track gains. + track_gains = [] for item in items: - ret.append(Gain(self._file_tags[item]["TRACK_GAIN"], - self._file_tags[item]["TRACK_PEAK"])) + try: + gain = self._file_tags[item]["TRACK_GAIN"] + peak = self._file_tags[item]["TRACK_PEAK"] + except KeyError: + raise ReplayGainError("results missing for track") + track_gains.append(Gain(gain, peak)) + # Get album gain information from the last track. last_tags = self._file_tags[items[-1]] - return AlbumGain(Gain(last_tags["ALBUM_GAIN"], - last_tags["ALBUM_PEAK"]), ret) + try: + gain = last_tags["ALBUM_GAIN"] + peak = last_tags["ALBUM_PEAK"] + except KeyError: + raise ReplayGainError("results missing for album") + + return AlbumGain(Gain(gain, peak), track_gains) def close(self): self._bus.remove_signal_watch() diff --git a/docs/changelog.rst b/docs/changelog.rst index 7dac1a1a9..45cd01ecb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -53,6 +53,8 @@ Fixes: inaccessible. :bug:`1806` * :doc:`/plugins/fetchart`: Possibly fix a Unicode-related crash when using some versions of pyOpenSSL. :bug:`1805` +* :doc:`/plugins/replaygain`: Fix an intermittent crash with the GStreamer + backend. :bug:`1855` .. _beets.io: http://beets.io/ .. _Beetbox: https://github.com/beetbox