]> kaliko git repositories - mpd-sima.git/blobdiff - sima/client.py
New, slightly enhanced, meta Objects.
[mpd-sima.git] / sima / client.py
index c04b259a90a147e4d3545012f8232fcd8ff39270..1d3a0103c54353c4e74a4613fa68cda17489b9be 100644 (file)
@@ -58,6 +58,8 @@ def blacklist(artist=False, album=False, track=False):
     field = (artist, album, track)
     def decorated(func):
         def wrapper(*args, **kwargs):
+            if not args[0].database:
+                return func(*args, **kwargs)
             cls = args[0]
             boolgen = (bl for bl in field)
             bl_fun = (cls.database.get_bl_artist,
@@ -96,7 +98,7 @@ class PlayerClient(Player):
     TODO: handle exception in command not going through _client_wrapper() (ie.
           removeā€¦)
     """
-    database = None  # sima database (history, blaclist)
+    database = None  # sima database (history, blacklist)
 
     def __init__(self, host="localhost", port="6600", password=None):
         super().__init__()
@@ -217,7 +219,7 @@ class PlayerClient(Player):
         # Check against the actual string in artist list
         if artist.orig in self.artists:
             self.log.debug('found exact match for "%s"' % artist)
-            return [artist]
+            return [artist.orig]
         # Then proceed with fuzzy matching if got nothing
         match = get_close_matches(artist.orig, self.artists, 50, 0.73)
         if not match:
@@ -288,9 +290,9 @@ class PlayerClient(Player):
     def monitor(self):
         curr = self.current
         try:
-            self._client.send_idle('database', 'playlist', 'player', 'options')
+            self.send_idle('database', 'playlist', 'player', 'options')
             select([self._client], [], [], 60)
-            ret = self._client.fetch_idle()
+            ret = self.fetch_idle()
             if self.__skipped_track(curr):
                 ret.append('skipped')
             if 'database' in ret:
@@ -299,8 +301,16 @@ class PlayerClient(Player):
         except (MPDError, IOError) as err:
             raise PlayerError("Couldn't init idle: %s" % err)
 
+    def clean(self):
+        """Clean blocking event (idle) and pending commands
+        """
+        if 'idle' in self._client._pending:
+            self._client.noidle()
+        elif self._client._pending:
+            self.log.warning('pending commands: {}'.format(self._client._pending))
+
     def remove(self, position=0):
-        self._client.delete(position)
+        self.delete(position)
 
     def add(self, track):
         """Overriding MPD's add method to accept add signature with a Track
@@ -313,7 +323,7 @@ class PlayerClient(Player):
 
     @property
     def state(self):
-        return str(self._client.status().get('state'))
+        return str(self.status().get('state'))
 
     @property
     def current(self):