]> kaliko git repositories - mpd-sima.git/blobdiff - sima/client.py
Add SimaDB and deal with history
[mpd-sima.git] / sima / client.py
index e19a5aafdabbdce12ad18e747eb5d8c16e5f83ea..641fa22166f106ff2adfa32611223e783b091c71 100644 (file)
@@ -26,6 +26,7 @@ class PlayerError(Exception):
 class PlayerCommandError(PlayerError):
     """Command error"""
 
+PlayerUnHandledError = MPDError
 
 class PlayerClient(Player):
     """MPC Client
@@ -91,6 +92,13 @@ class PlayerClient(Player):
                 return Track(**ans)
         return ans
 
+    def __skipped_track(self, old_curr):
+        if (self.state == 'stop'
+            or not hasattr(old_curr, 'id')
+            or not hasattr(self.current, 'id')):
+            return False
+        return (self.current.id != old_curr.id)  # pylint: disable=no-member
+
     def find_track(self, artist, title=None):
         #return getattr(self, 'find')('artist', artist, 'title', title)
         if title:
@@ -108,18 +116,14 @@ class PlayerClient(Player):
         return self.find('artist', artist, 'album', album)
 
     def monitor(self):
+        curr = self.current
         try:
             self._client.send_idle('database', 'playlist', 'player', 'options')
             select([self._client], [], [], 60)
-            return self._client.fetch_idle()
-        except (MPDError, IOError) as err:
-            raise PlayerError("Couldn't init idle: %s" % err)
-
-    def idle(self):
-        try:
-            self._client.send_idle('database', 'playlist', 'player', 'options')
-            select([self._client], [], [], 60)
-            return self._client.fetch_idle()
+            ret = self._client.fetch_idle()
+            if self.__skipped_track(curr):
+                ret.append('skipped')
+            return ret
         except (MPDError, IOError) as err:
             raise PlayerError("Couldn't init idle: %s" % err)
 
@@ -134,6 +138,7 @@ class PlayerClient(Player):
     def current(self):
         return self.currentsong()
 
+    @property
     def playlist(self):
         """
         Override deprecated MPD playlist command
@@ -192,7 +197,6 @@ class PlayerClient(Player):
         # If that fails, don't worry, just ignore it and disconnect
         except (MPDError, IOError):
             pass
-
         try:
             self._client.disconnect()
         # Disconnecting failed, so use a new client object instead