found = False
if self.use_mbid and artist.mbid:
# look for exact search w/ musicbrainz_artistid
- found = bool(self.list('artist', f"(MUSICBRAINZ_ARTISTID == '{artist.mbid}')"))
- if found:
+ library = self.list('artist', f"(MUSICBRAINZ_ARTISTID == '{artist.mbid}')")
+ if library:
+ found = True
self.log.trace('Found mbid "%r" in library', artist)
+ # library could fetch several artist name for a single MUSICBRAINZ_ARTISTID
+ if len(library) > 1:
+ self.log.warning('I got "%s" searching for %r', library, artist)
+ elif len(library) == 1 and library[0] != artist.name:
+ self.log.debug('Update artist name %s->%s', artist, library[0])
+ artist = Artist(name=library[0], mbid=artist.mbid)
# Fetches remaining artists for potential match
artists = self._cache['nombid_artists']
else: # not using MusicBrainzIDs
self.log.trace('no fuzzy matching for %r', artist)
if found:
return artist
+ return None
# Now perform fuzzy search
for fuzz in match:
if fuzz in artist.names: # Already found in lower cased comparison
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)
+ tracks = []
if not match:
return []
for mtitle in match:
- leven = levenshtein_ratio(title.lower(), mtitle.lower())
+ leven = levenshtein_ratio(title, mtitle)
if leven == 1:
- pass
- elif leven >= 0.79: # PARAM
+ tracks.extend([t for t in all_tracks if t.title == mtitle])
+ elif leven >= 0.77:
self.log.debug('title: "%s" should match "%s" (lr=%1.3f)',
mtitle, title, leven)
+ tracks.extend([t for t in all_tracks if t.title == mtitle])
else:
self.log.debug('title: "%s" does not match "%s" (lr=%1.3f)',
mtitle, title, leven)
- return []
- return self.find('artist', artist, 'title', mtitle)
+ return tracks
@blacklist(album=True)
def search_albums(self, artist):