Skip to content

Commit

Permalink
replaygain: Handle missing GStreamer data (#1855)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Feb 2, 2016
1 parent e3e34b1 commit 0aea7e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions beetsplug/replaygain.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,25 @@ def compute_album_gain(self, album):
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()
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0aea7e3

Please sign in to comment.