]> kaliko git repositories - mpd-sima.git/blobdiff - sima/client.py
Attempt to fix AttributeError issue
[mpd-sima.git] / sima / client.py
index b8ccea522a2ee62993ee22beb42b631120e42c4a..06ba8961e8a6bcb305fbafd3912986bcd366efaa 100644 (file)
@@ -144,11 +144,12 @@ class PlayerClient(Player):
         return ans
 
     def __skipped_track(self, old_curr):
+        curr = self.current
         if (self.state == 'stop'
             or not hasattr(old_curr, 'id')
-            or not hasattr(self.current, 'id')):
+            or not hasattr(curr, 'id')):
             return False
-        return self.current.id != old_curr.id  # pylint: disable=no-member
+        return curr.id != old_curr.id  # pylint: disable=no-member
 
     def _flush_cache(self):
         """
@@ -195,15 +196,20 @@ class PlayerClient(Player):
         found = False
         if artist.mbid:
             # look for exact search w/ musicbrainz_artistid
-            [artist.add_alias(name) for name in
-                    self._client.list('artist', 'musicbrainz_artistid', artist.mbid)]
-            if artist.aliases:
+            exact_m = self._client.list('artist', 'musicbrainz_artistid', artist.mbid)
+            if exact_m:
+                [artist.add_alias(name) for name in exact_m]
                 found = True
         else:
             artist = Artist(name=artist.name)
         # then complete with fuzzy search on artist with no musicbrainz_artistid
-        nombid_artists = self._cache.get('nombid_artists', [])
-        match = get_close_matches(artist.name, nombid_artists, 50, 0.73)
+        if artist.mbid:
+            # we already performed a lookup on artists with mbid set
+            # search through remaining artists
+            artists = self._cache.get('nombid_artists', [])
+        else:
+            artists = self._cache.get('artists', [])
+        match = get_close_matches(artist.name, artists, 50, 0.73)
         if not match and not found:
             return
         if len(match) > 1:
@@ -292,7 +298,7 @@ class PlayerClient(Player):
                 arts = set([trk.artist for trk in album_trks])
                 if len(set(arts)) < 2:  # TODO: better heuristic, use a ratio instead
                     if album not in albums:
-                        albums.append(Album(name=album, albumartist=artist))
+                        albums.append(Album(name=album, **kwalbart))
                 elif album and album not in albums:
                     self.log.debug('"{0}" probably not an album of "{1}"'.format(
                                    album, artist) + '({0})'.format('/'.join(arts)))