added diacritics removal
fixed filename not being cleaned
This commit is contained in:
6
go.mod
6
go.mod
@@ -1,8 +1,12 @@
|
||||
module zomo.land/music-rename
|
||||
|
||||
go 1.21.1
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require (
|
||||
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8
|
||||
github.com/joho/godotenv v1.5.1
|
||||
)
|
||||
|
||||
require golang.org/x/text v0.26.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -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/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
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
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
|
||||
}
|
||||
|
||||
BIN
music-rename
BIN
music-rename
Binary file not shown.
Reference in New Issue
Block a user