mirror of
https://github.com/xhongc/music-tag-web.git
synced 2026-02-02 17:59:07 +08:00
feature:优化匹配规则
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
from applications.task.utils import match_score
|
||||
from applications.task.utils import match_score, match_artist
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from component import music_tag
|
||||
@@ -32,8 +31,14 @@ class SmartTagClient:
|
||||
for songs in results:
|
||||
for song in songs:
|
||||
title_score = match_score(title, song["name"])
|
||||
artist_score = match_score(artist if artist else title, song["artist"])
|
||||
artist_score = match_artist(artist if artist else title, song["artist"])
|
||||
album_score = match_score(album if album else title, song["album"])
|
||||
if artist and artist_score == 0:
|
||||
artist_score = -2
|
||||
# 标题包含艺术家信息
|
||||
if not artist and artist_score >= 1:
|
||||
if title_score >= 1:
|
||||
title_score = 2
|
||||
song["score"] = title_score + artist_score + album_score
|
||||
max_score = max(max_score, song["score"])
|
||||
if title_score == 0:
|
||||
|
||||
@@ -50,6 +50,14 @@ def match_score(my_value, u_value):
|
||||
return 0
|
||||
|
||||
|
||||
def match_artist(my_value, u_value):
|
||||
if "," in u_value:
|
||||
return match_score(my_value, u_value.split(",")[0].replace(" ", "")) \
|
||||
+ match_score(my_value, u_value.split(",")[1].replace(" ", ""))
|
||||
else:
|
||||
return match_score(my_value, u_value)
|
||||
|
||||
|
||||
def match_song(resource, song_path, select_mode):
|
||||
from applications.task.services.music_resource import MusicResource
|
||||
|
||||
@@ -71,8 +79,14 @@ def match_song(resource, song_path, select_mode):
|
||||
}
|
||||
for song in songs:
|
||||
match_score_map["title"] = match_score(title, song["name"])
|
||||
match_score_map["artist"] = match_score(artist if artist else title, song["artist"])
|
||||
match_score_map["artist"] = match_artist(artist if artist else title, song["artist"])
|
||||
match_score_map["album"] = match_score(album if album else title, song["album"])
|
||||
if artist and match_score_map["artist"] == 0:
|
||||
match_score_map["artist"] = -2
|
||||
# 标题包含艺术家信息
|
||||
if not artist and match_score_map["artist"] >= 1:
|
||||
if match_score_map["title"] >= 1:
|
||||
match_score_map["title"] = 2
|
||||
if sum(match_score_map.values()) >= 3:
|
||||
is_match = True
|
||||
song_select = song
|
||||
@@ -120,3 +134,7 @@ def detect_language(lyrics):
|
||||
return '泰文'
|
||||
else:
|
||||
return '未知'
|
||||
|
||||
|
||||
def parse_discnumber(discnumber):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user