From: kaliko Date: Wed, 4 Nov 2015 11:05:21 +0000 (+0100) Subject: Prevent adding empty track to history (Closes #5) X-Git-Tag: 0.14.1~8 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=e5ac6da78e3433a1b94676f6523e358d6089f263;p=mpd-sima.git Prevent adding empty track to history (Closes #5) --- diff --git a/sima/lib/track.py b/sima/lib/track.py index 4a2e720..a774a4c 100644 --- a/sima/lib/track.py +++ b/sima/lib/track.py @@ -99,6 +99,8 @@ class Track: return hash(self) != hash(other) def __bool__(self): + if not self._file: + return False return not self._empty @property diff --git a/sima/plugins/core/history.py b/sima/plugins/core/history.py index b791053..ae98a3f 100644 --- a/sima/plugins/core/history.py +++ b/sima/plugins/core/history.py @@ -42,7 +42,9 @@ class History(Plugin): def callback_next_song(self): current = self.player.current - self.log.debug('add history: "{}"'.format(current)) + self.log.debug('add history: "%s"', current) + if not current: + self.log.warning('Cannot add "%s" to history (empty or missing file)', current) self.sdb.add_history(current) diff --git a/tests/test_track.py b/tests/test_track.py index 80a709e..62eb306 100644 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -33,6 +33,8 @@ class TestTrackObject(unittest.TestCase): def test_boolean_type(self): self.assertFalse(bool(Track())) + for trk in [{}, {'artist': 'Devolt'}, {'artist': 'Devolt', 'file':''}]: + self.assertFalse(bool(Track(**trk))) def test_albumartist(self): trk = Track(albumartist='album_artist', artist='track_artist')