removing suffix
This commit is contained in:
@@ -31,6 +31,63 @@ func IsNumeric(num string) bool {
|
|||||||
return true
|
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 {
|
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
|
return title
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user