Skip to content

Commit

Permalink
fix: #125 修复本地英文歌曲匹大小写字母配不到的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jul 15, 2024
1 parent 5cb2c84 commit 45a94f4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions xiaomusic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


# 歌曲排序
Expand Down

0 comments on commit 45a94f4

Please sign in to comment.