+ @blacklist(track=True)
+ def fuzzy_find_track(self, artist, title):
+ # Retrieve all tracks from artist
+ all_tracks = self.find('artist', artist)
+ # 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)
+ if not match:
+ return []
+ for title_ in match:
+ leven = levenshtein_ratio(title.lower(), title_.lower())
+ if leven == 1:
+ pass
+ elif leven >= 0.79: # PARAM
+ self.log.debug('title: "%s" should match "%s" (lr=%1.3f)' %
+ (title_, title, leven))
+ else:
+ self.log.debug('title: "%s" does not match "%s" (lr=%1.3f)' %
+ (title_, title, leven))
+ return []
+ return self.find('artist', artist, 'title', title_)
+
+ @blacklist(artist=True)
+ def fuzzy_find_artist(self, art):
+ """
+ Controls presence of artist in music library.
+ Crosschecking artist names with SimaStr objects / difflib / levenshtein
+
+ TODO: proceed crosschecking even when an artist matched !!!
+ Not because we found "The Doors" as "The Doors" that there is no
+ remaining entries as "Doors" :/
+ not straight forward, need probably heavy refactoring.
+ """
+ matching_artists = list()
+ artist = SimaStr(art)
+
+ # Check against the actual string in artist list
+ if artist.orig in self.artists:
+ self.log.debug('found exact match for "%s"' % artist)
+ return [artist.orig]
+ # Then proceed with fuzzy matching if got nothing
+ match = get_close_matches(artist.orig, self.artists, 50, 0.73)
+ if not match:
+ return []
+ self.log.debug('found close match for "%s": %s' %
+ (artist, '/'.join(match)))
+ # Does not perform fuzzy matching on short and single word strings
+ # Only lowercased comparison
+ if ' ' not in artist.orig and len(artist) < 8:
+ for fuzz_art in match:
+ # Regular string comparison SimaStr().lower is regular string
+ if artist.lower() == fuzz_art.lower():
+ matching_artists.append(fuzz_art)
+ self.log.debug('"%s" matches "%s".' % (fuzz_art, artist))
+ return matching_artists
+ for fuzz_art in match:
+ # Regular string comparison SimaStr().lower is regular string
+ if artist.lower() == fuzz_art.lower():
+ matching_artists.append(fuzz_art)
+ self.log.debug('"%s" matches "%s".' % (fuzz_art, artist))
+ return matching_artists
+ # SimaStr string __eq__ (not regular string comparison here)
+ if artist == fuzz_art:
+ matching_artists.append(fuzz_art)
+ self.log.info('"%s" quite probably matches "%s" (SimaStr)' %
+ (fuzz_art, artist))
+ else:
+ self.log.debug('FZZZ: "%s" does not match "%s"' %
+ (fuzz_art, artist))
+ return matching_artists
+