From 265e72abad83a927ac63fcf4e95f41281210e0ae Mon Sep 17 00:00:00 2001 From: lars Date: Sun, 13 Nov 2022 16:40:44 +0100 Subject: [PATCH] fixed little bug that had to do with youtube putting feature artists in the track name --- src/utils/phonetic_compares.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/utils/phonetic_compares.py b/src/utils/phonetic_compares.py index 96da52c..d2d18d5 100644 --- a/src/utils/phonetic_compares.py +++ b/src/utils/phonetic_compares.py @@ -11,8 +11,25 @@ def unify_punctuation(to_unify: str) -> str: return to_unify +def remove_feature_part_from_track(title: str) -> str: + if ")" != title[-1]: + return title + if "(" not in title: + return title + + return title[:title.index("(")] + + +def modify_title(to_modify: str) -> str: + to_modify = to_modify.strip() + to_modify = to_modify.lower() + to_modify = remove_feature_part_from_track(to_modify) + to_modify = unify_punctuation(to_modify) + return to_modify + + def match_titles(title_1: str, title_2: str) -> (bool, int): - title_1, title_2 = unify_punctuation(title_1).lower(), unify_punctuation(title_2).lower() + title_1, title_2 = modify_title(title_1), modify_title(title_2) distance = jellyfish.levenshtein_distance(title_1, title_2) return distance > TITLE_THRESHOLD_LEVENSHTEIN, distance