added diacritics removal
fixed filename not being cleaned
This commit is contained in:
36
main.go
36
main.go
@@ -13,9 +13,14 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"slices"
|
||||
|
||||
"golang.org/x/text/runes"
|
||||
"golang.org/x/text/transform"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
|
||||
"github.com/dhowden/tag"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
@@ -320,12 +325,12 @@ func doMoveTagged(filePath string, fileTags tag.Metadata) error {
|
||||
tmplFile := template.Must(template.New("libFile").Parse(libTemplateFile))
|
||||
|
||||
tmplDataFile := LibTemplateFile{
|
||||
Title: fileTags.Title(),
|
||||
Album: fileTags.Album(),
|
||||
Artist: fileTags.Artist(),
|
||||
AlbumArtist: fileTags.AlbumArtist(),
|
||||
Composer: fileTags.Composer(),
|
||||
Genre: fileTags.Genre(),
|
||||
Title: cleanTemplateVariable(fileTags.Title()),
|
||||
Album: cleanTemplateVariable(fileTags.Album()),
|
||||
Artist: cleanTemplateVariable(fileTags.Artist()),
|
||||
AlbumArtist: cleanTemplateVariable(fileTags.AlbumArtist()),
|
||||
Composer: cleanTemplateVariable(fileTags.Composer()),
|
||||
Genre: cleanTemplateVariable(fileTags.Genre()),
|
||||
Year: fileTags.Year(),
|
||||
Track: track,
|
||||
TrackCount: trackCount,
|
||||
@@ -446,11 +451,22 @@ func moveFile(source, destination string) (err error) {
|
||||
}
|
||||
|
||||
func cleanPath(str string) string {
|
||||
re := regexp.MustCompile(`[<>:"|?*]`)
|
||||
return re.ReplaceAllString(str, "")
|
||||
return doClean(str, `[<>:"|?*]`)
|
||||
}
|
||||
|
||||
func cleanTemplateVariable(str string) string {
|
||||
re := regexp.MustCompile(`[<>:"|?*/\\]`)
|
||||
return re.ReplaceAllString(str, "")
|
||||
return doClean(str, `[<>:"|?*/\\.]`)
|
||||
}
|
||||
|
||||
func doClean(str string, reg string) string {
|
||||
re := regexp.MustCompile(reg)
|
||||
s := re.ReplaceAllString(str, "")
|
||||
|
||||
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
|
||||
result, _, err := transform.String(t, s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user