]> kaliko git repositories - mpd-sima.git/commitdiff
Prevent adding empty track to history (Closes #5)
authorkaliko <kaliko@azylum.org>
Wed, 4 Nov 2015 11:05:21 +0000 (12:05 +0100)
committerkaliko <kaliko@azylum.org>
Wed, 4 Nov 2015 11:05:21 +0000 (12:05 +0100)
sima/lib/track.py
sima/plugins/core/history.py
tests/test_track.py

index 4a2e72001b1d44f47d9794afc03f52dda7be884c..a774a4ceafdceeb7ec7c0c5c57d819c20a35d378 100644 (file)
@@ -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
index b79105333a54dffe12841a9a19f0dc72a3fbabdd..ae98a3ff5490f204c72626f61bec7e114a533b3f 100644 (file)
@@ -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)
 
 
index 80a709e04fdfcb2034d2292a9215c7dc773e4373..62eb30617f5761c8a0369513cd3aaf591d14a936 100644 (file)
@@ -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')