From 16318dac200b8f66dd105a2ef5638cac3f53e1b3 Mon Sep 17 00:00:00 2001 From: acute_interpreter_panic <223899499+acute-interpreter-panic@users.noreply.github.com> Date: Fri, 10 Oct 2025 01:27:35 +0200 Subject: [PATCH] removing suffix --- internal/common/strings.go | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/internal/common/strings.go b/internal/common/strings.go index 9fd7ae9..422ccf7 100644 --- a/internal/common/strings.go +++ b/internal/common/strings.go @@ -31,6 +31,63 @@ func IsNumeric(num string) bool { return true } +var commonTitleSuffix = []string{"(official video)"} + +const openBrackets = "([" +const closeBrackets = ")]" + +var forbiddenSubstringInBrackets = []string{"official", "video", "audio", "lyrics", "prod", "remix", "ft", "feat", "ft.", "feat."} + func CleanSongTitle(title string, artistName string) string { + /* + # remove brackets and their content if they contain disallowed substrings + for open_bracket, close_bracket in zip(OPEN_BRACKETS, CLOSE_BRACKETS): + if open_bracket not in raw_song_title or close_bracket not in raw_song_title: + continue + + start = 0 + + while True: + try: + open_bracket_index = raw_song_title.index(open_bracket, start) + except ValueError: + break + try: + close_bracket_index = raw_song_title.index(close_bracket, open_bracket_index + 1) + except ValueError: + break + + substring = raw_song_title[open_bracket_index + 1:close_bracket_index] + if any(disallowed_substring in substring.lower() for disallowed_substring in DISALLOWED_SUBSTRING_IN_BRACKETS): + raw_song_title = raw_song_title[:open_bracket_index] + raw_song_title[close_bracket_index + 1:] + else: + start = close_bracket_index + 1 + + # everything that requires the artist name + if artist_name is not None: + artist_name = artist_name.strip() + + # Remove artist from the start of the title + if raw_song_title.lower().startswith(artist_name.lower()): + + possible_new_name = raw_song_title[len(artist_name):].strip() + + for char in ("-", "–", ":", "|"): + if possible_new_name.startswith(char): + raw_song_title = possible_new_name[1:].strip() + break + + return raw_song_title.strip() + + */ + + title = strings.TrimSpace(title) + + for _, d := range commonTitleSuffix { + if strings.HasSuffix(strings.ToLower(d), d) { + title = strings.TrimSpace(title[:len(d)-1]) + } + } + return title }