From: kaliko Date: Tue, 9 Dec 2014 20:14:59 +0000 (+0100) Subject: Fixed top track mode with Artist objects X-Git-Tag: 0.13.0~15 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=c2c435f2d5a6e13d610f91d16764a62ae6cb315a;p=mpd-sima.git Fixed top track mode with Artist objects --- diff --git a/sima/client.py b/sima/client.py index 0bfc882..2893d9b 100644 --- a/sima/client.py +++ b/sima/client.py @@ -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') diff --git a/sima/lib/player.py b/sima/lib/player.py index feaa4e3..b7d7255 100644 --- a/sima/lib/player.py +++ b/sima/lib/player.py @@ -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 """ diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index c05b86d..cff9d67 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -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])) diff --git a/sima/plugins/internal/randomfallback.py b/sima/plugins/internal/randomfallback.py index 4c011fe..ee0be20 100644 --- a/sima/plugins/internal/randomfallback.py +++ b/sima/plugins/internal/randomfallback.py @@ -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))