46 lines
759 B
Go
46 lines
759 B
Go
package utils
|
||
|
||
import "strings"
|
||
|
||
// FormatTitle
|
||
// Format the title of a media file by replacing spaces with underscores and removing special characters
|
||
func FormatTitle(title string) string {
|
||
// remove file ext from title
|
||
if strings.Contains(title, ".") {
|
||
title = strings.Split(title, ".")[0]
|
||
}
|
||
|
||
// replace all spaces with underscores
|
||
replacements := []string{
|
||
" ", "",
|
||
"!", "",
|
||
"@", "",
|
||
"#", "",
|
||
"$", "",
|
||
"%", "",
|
||
"^", "",
|
||
"&", "",
|
||
"*", "",
|
||
"(", "(",
|
||
")", ")",
|
||
"[", "【",
|
||
"]", "】",
|
||
"{", "《",
|
||
"}", "》",
|
||
":", ":",
|
||
";", "",
|
||
"'", "",
|
||
"\"", "",
|
||
"<", "",
|
||
">", "",
|
||
",", "",
|
||
".", "",
|
||
"?", "",
|
||
}
|
||
|
||
replacer := strings.NewReplacer(replacements...)
|
||
title = replacer.Replace(title)
|
||
|
||
return title
|
||
}
|