From 45a94f4bfe51c5ff8ef03e0d566a74d9f7a91fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Mon, 15 Jul 2024 16:44:56 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20#125=20=E4=BF=AE=E5=A4=8D=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E8=8B=B1=E6=96=87=E6=AD=8C=E6=9B=B2=E5=8C=B9=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=86=99=E5=AD=97=E6=AF=8D=E9=85=8D=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaomusic/utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/xiaomusic/utils.py b/xiaomusic/utils.py index f52e450..21adf9b 100644 --- a/xiaomusic/utils.py +++ b/xiaomusic/utils.py @@ -73,12 +73,21 @@ def validate_proxy(proxy_str: str) -> bool: # 模糊搜索 def fuzzyfinder(user_input, collection): - return difflib.get_close_matches(user_input, collection, n=10, cutoff=0.1) + lower_collection = {item.lower(): item for item in collection} + user_input = user_input.lower() + matches = difflib.get_close_matches( + user_input, lower_collection.keys(), n=10, cutoff=0.1 + ) + return [lower_collection[match] for match in matches] def find_best_match(user_input, collection, cutoff=0.6): - matches = difflib.get_close_matches(user_input, collection, n=1, cutoff=cutoff) - return matches[0] if matches else None + lower_collection = {item.lower(): item for item in collection} + user_input = user_input.lower() + matches = difflib.get_close_matches( + user_input, lower_collection.keys(), n=1, cutoff=cutoff + ) + return lower_collection[matches[0]] if matches else None # 歌曲排序