tmp
This commit is contained in:
parent
3744bd1c56
commit
e044b7ffd4
2 changed files with 86 additions and 7 deletions
|
|
@ -94,10 +94,10 @@ def fuzzy_tag_pattern_generator():
|
|||
mappings = {}
|
||||
|
||||
def fuzzy_tags_ratio(first: SongTags, second: SongTags):
|
||||
title_ratio = fuzz.ratio(first.title, second.title) / 100
|
||||
artist_ratio = fuzz.ratio(first.artist, second.artist) / 100
|
||||
album_ratio = fuzz.ratio(first.album, second.album) / 100
|
||||
return sum([title_ratio, artist_ratio, album_ratio]) / 3
|
||||
title_ratio = fuzz.token_set_ratio(first.title, second.title) / 100
|
||||
artist_ratio = fuzz.token_set_ratio(first.artist, second.artist) / 100
|
||||
album_ratio = fuzz.token_set_ratio(first.album, second.album) / 100
|
||||
return title_ratio, artist_ratio, album_ratio
|
||||
|
||||
with tqdm(total=len(local_library), desc='Searching local songs on spotify') as pbar:
|
||||
for local_track_id, local_track in local_library.items():
|
||||
|
|
@ -111,9 +111,15 @@ def fuzzy_tag_pattern_generator():
|
|||
|
||||
ratios.append((fuzzy_tags_ratio(tag1, tag2), track['id']))
|
||||
|
||||
ratios.sort(reverse=True, key=lambda x: x[0])
|
||||
if ratios[0][0] > 0.8:
|
||||
mapping['items'] = [ratios[0][1]]
|
||||
filtered_ratios = []
|
||||
threshold = 0.8
|
||||
for ratio in ratios:
|
||||
if all([val > threshold for val in ratio[0]]):
|
||||
filtered_ratios.append((sum(i for i in ratio[0]) / len(ratio[0]), ratio[1]))
|
||||
|
||||
filtered_ratios.sort(reverse=True, key=lambda x: x[0])
|
||||
if len(filtered_ratios):
|
||||
mapping['items'] = [filtered_ratios[0][1]]
|
||||
|
||||
mappings[local_track_id] = mapping
|
||||
pbar.update(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue