- matching_artists = list()
- artist = SimaStr(art)
- all_artists = self.list('artist')
-
- # Check against the actual string in artist list
- if artist.orig in all_artists:
- self.log.debug('found exact match for "%s"' % artist)
- return [artist]
- # Then proceed with fuzzy matching if got nothing
- match = get_close_matches(artist.orig, all_artists, 50, 0.73)
+ if isinstance(self._cache, dict):
+ self.log.info('Player: Flushing cache!')
+ else:
+ self.log.info('Player: Initialising cache!')
+ self._cache = {
+ 'artists': None,
+ }
+ self._cache['artists'] = frozenset(self._client.list('artist'))
+
+ @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))
+ return list(tracks)
+
+ def fuzzy_find_track(self, artist, title):
+ # Retrieve all tracks from 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])
+ match = get_close_matches(title, all_artist_titles, 50, 0.78)