]> kaliko git repositories - mpd-sima.git/blobdiff - sima/client.py
Fixed var-dir option in bash completion
[mpd-sima.git] / sima / client.py
index 667242cc7ab569a4cb94792e26550a8de4e5526c..499250fccd2d04c01ad96fab717a9b5a79b6c13d 100644 (file)
@@ -159,26 +159,28 @@ class PlayerClient(Player):
         else:
             self.log.info('Player: Initialising cache!')
         self._cache = {
-                'artists': None,
-                'nombid_artists': None,
+                'artists': frozenset(),
+                'nombid_artists': frozenset(),
                 }
-        self._cache['artists'] = frozenset(self._client.list('artist'))
-        self._cache['nombid_artists'] = frozenset(self._client.list('artist', 'musicbrainz_artistid', ''))
+        self._cache['artists'] = frozenset(self._execute('list', ['artist']))
+        if Artist.use_mbid:
+            self._cache['nombid_artists'] = frozenset(self._execute('list', ['artist', 'musicbrainz_artistid', '']))
 
     @blacklist(track=True)
     def find_track(self, artist, title=None):
         tracks = set()
-        for name in artist.names:
-            if title:
-                tracks |= set(self.find('artist', name, 'title', title))
-            else:
-                tracks |= set(self.find('artist', name))
         if artist.mbid:
             if title:
-                tracks |= set(self.find('musicbrainz_artistid', artist.mbid))
-            else:
                 tracks |= set(self.find('musicbrainz_artistid', artist.mbid,
                                         'title', title))
+            else:
+                tracks |= set(self.find('musicbrainz_artistid', artist.mbid))
+        else:
+            for name in artist.names:
+                if title:
+                    tracks |= set(self.find('artist', name, 'title', title))
+                else:
+                    tracks |= set(self.find('artist', name))
         return list(tracks)
 
     @bl_artist
@@ -195,7 +197,7 @@ class PlayerClient(Player):
         found = False
         if artist.mbid:
             # look for exact search w/ musicbrainz_artistid
-            exact_m = self._client.list('artist', 'musicbrainz_artistid', artist.mbid)
+            exact_m = self._execute('list', ['artist', 'musicbrainz_artistid', artist.mbid])
             if exact_m:
                 [artist.add_alias(name) for name in exact_m]
                 found = True
@@ -205,9 +207,9 @@ class PlayerClient(Player):
         if artist.mbid:
             # we already performed a lookup on artists with mbid set
             # search through remaining artists
-            artists = self._cache.get('nombid_artists', [])
+            artists = self._cache.get('nombid_artists')
         else:
-            artists = self._cache.get('artists', [])
+            artists = self._cache.get('artists')
         match = get_close_matches(artist.name, artists, 50, 0.73)
         if not match and not found:
             return
@@ -331,7 +333,7 @@ class PlayerClient(Player):
     def add(self, track):
         """Overriding MPD's add method to accept add signature with a Track
         object"""
-        self._client.add(track.file)
+        self._execute('add', [track.file])
 
     @property
     def artists(self):