added diacritics removal

fixed filename not being cleaned
This commit is contained in:
2025-07-01 20:40:28 -05:00
parent 353c1edcca
commit 73502669ea
4 changed files with 33 additions and 11 deletions

6
go.mod
View File

@@ -1,8 +1,12 @@
module zomo.land/music-rename module zomo.land/music-rename
go 1.21.1 go 1.23.0
toolchain go1.23.10
require ( require (
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
) )
require golang.org/x/text v0.26.0 // indirect

2
go.sum
View File

@@ -2,3 +2,5 @@ github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 h1:OtSeLS5y0Uy01jaKK4m
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8/go.mod h1:apkPC/CR3s48O2D7Y++n1XWEpgPNNCjXYga3PPbJe2E= github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8/go.mod h1:apkPC/CR3s48O2D7Y++n1XWEpgPNNCjXYga3PPbJe2E=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=

36
main.go
View File

@@ -13,9 +13,14 @@ import (
"strings" "strings"
"text/template" "text/template"
"time" "time"
"unicode"
"slices" "slices"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"github.com/dhowden/tag" "github.com/dhowden/tag"
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
@@ -320,12 +325,12 @@ func doMoveTagged(filePath string, fileTags tag.Metadata) error {
tmplFile := template.Must(template.New("libFile").Parse(libTemplateFile)) tmplFile := template.Must(template.New("libFile").Parse(libTemplateFile))
tmplDataFile := LibTemplateFile{ tmplDataFile := LibTemplateFile{
Title: fileTags.Title(), Title: cleanTemplateVariable(fileTags.Title()),
Album: fileTags.Album(), Album: cleanTemplateVariable(fileTags.Album()),
Artist: fileTags.Artist(), Artist: cleanTemplateVariable(fileTags.Artist()),
AlbumArtist: fileTags.AlbumArtist(), AlbumArtist: cleanTemplateVariable(fileTags.AlbumArtist()),
Composer: fileTags.Composer(), Composer: cleanTemplateVariable(fileTags.Composer()),
Genre: fileTags.Genre(), Genre: cleanTemplateVariable(fileTags.Genre()),
Year: fileTags.Year(), Year: fileTags.Year(),
Track: track, Track: track,
TrackCount: trackCount, TrackCount: trackCount,
@@ -446,11 +451,22 @@ func moveFile(source, destination string) (err error) {
} }
func cleanPath(str string) string { func cleanPath(str string) string {
re := regexp.MustCompile(`[<>:"|?*]`) return doClean(str, `[<>:"|?*]`)
return re.ReplaceAllString(str, "")
} }
func cleanTemplateVariable(str string) string { func cleanTemplateVariable(str string) string {
re := regexp.MustCompile(`[<>:"|?*/\\]`) return doClean(str, `[<>:"|?*/\\.]`)
return re.ReplaceAllString(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
} }

Binary file not shown.