]> kaliko git repositories - mpd-sima.git/commitdiff
MPD client: Improved search_track
authorkaliko <kaliko@azylum.org>
Fri, 15 May 2020 15:45:03 +0000 (17:45 +0200)
committerkaliko <kaliko@azylum.org>
Fri, 15 May 2020 15:45:03 +0000 (17:45 +0200)
sima/mpdclient.py

index 0866e4c59c46a60994c94d51378f139036bc08a6..bbc7e071e95d0706a6b063663c792c1ad39d1dad 100644 (file)
@@ -421,20 +421,21 @@ class MPD(MPDClient):
         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):