]> kaliko git repositories - mpd-sima.git/commitdiff
Fixed top track mode with Artist objects
authorkaliko <kaliko@azylum.org>
Tue, 9 Dec 2014 20:14:59 +0000 (21:14 +0100)
committerkaliko <kaliko@azylum.org>
Tue, 9 Dec 2014 20:14:59 +0000 (21:14 +0100)
sima/client.py
sima/lib/player.py
sima/lib/webserv.py
sima/plugins/internal/randomfallback.py

index 0bfc8826be36ca0027df7b6df3af3598456527f7..2893d9b52cf52bb5a53266ec2bdedc7f0e05ebcd 100644 (file)
@@ -141,25 +141,24 @@ class PlayerClient(Player):
         self._cache['artists'] = frozenset(self._client.list('artist'))
 
     @blacklist(track=True)
-    def _find_track(self, artist, title):
-        #return getattr(self, 'find')('artist', artist, 'title', title)
-        if title:
-            return self.find('artist', artist, 'title', title)
-        return self.find('artist', artist)
-
     def find_track(self, artist, title=None):
-        tracks = list()
-        if isinstance(artist, Artist):
-            for name in artist.names:
-                tracks.extend(self._find_track(name, title=title))
-        else:
-            tracks.extend(self._find_track(artist,title=title))
-        return tracks
+        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))
+        return list(tracks)
 
-    @blacklist(track=True)
     def fuzzy_find_track(self, artist, title):
         # Retrieve all tracks from artist
-        all_tracks = self.find('artist', artist)
+        all_tracks = self.find_track(artist, title)
         # Get all titles (filter missing titles set to 'None')
         all_artist_titles = frozenset([tr.title for tr in all_tracks
                                        if tr.title is not None])
@@ -324,6 +323,8 @@ class PlayerClient(Player):
                 self.log.warning('Use of MusicBrainzIdentifier is set but MPD is '
                         'not providing related metadata')
                 self.log.info(self._client.tagtypes())
+                self.log.warning('Disabling MusicBrainzIdentifier')
+                Artist.use_mbid = False
         else:
             self.log.warning('Use of MusicBrainzIdentifier disabled!')
             self.log.info('Consider using MusicBrainzIdentifier for your music library')
index feaa4e3fe390960c16ae4057514d445532942dcf..b7d7255f9d9f2c3cb58d6b91b344baeb52512528 100644 (file)
@@ -123,8 +123,8 @@ class Player(object):
     def find_track(self, artist, title=None):
         """
         Find tracks for a specific artist or filtering with a track title
-            >>> player.find_track('The Beatles')
-            >>> player.find_track('Nirvana', title='Smells Like Teen Spirit')
+            >>> player.find_track(Artist('The Beatles'))
+            >>> player.find_track(Artist('Nirvana'), title='Smells Like Teen Spirit')
 
         Returns a list of Track objects
         """
index c05b86d971a2b2a870532b54121f23a2b0ad8c3c..cff9d6708ca46836383021b38f9a361617d8d288 100644 (file)
@@ -333,7 +333,7 @@ class WebService(Plugin):
             if self.ws.ratelimit:
                 self.log.info('{0.name} ratelimit: {0.ratelimit}'.format(self.ws))
             for trk in titles:
-                found = self.player.fuzzy_find_track(artist.name, trk.title)
+                found = self.player.fuzzy_find_track(artist, trk.title)
                 random.shuffle(found)
                 if found:
                     self.log.debug('{0}'.format(found[0]))
index 4c011fe485ec904cc18a003f576cfc59cca99d82..ee0be20b78822ed645a92bf754a93aab0d91646a 100644 (file)
@@ -28,6 +28,7 @@ import random
 
 # local import
 from ...lib.plugin import Plugin
+from ...lib.meta import Artist
 
 
 class RandomFallBack(Plugin):
@@ -88,7 +89,7 @@ class RandomFallBack(Plugin):
         if art is None:
             return None
         self.log.debug('Random art: {}'.format(art))
-        trks = self.player.find_track(art)
+        trks = self.player.find_track(Artist(art))
         if trks:
             trk = random.choice(trks)
             self.log.info('random fallback ({}): {}'.format(self.mode, trk))