fix: no more slashes in template variables

This commit is contained in:
2025-07-01 02:16:10 -05:00
parent 5dc8819cf7
commit 600e60f3c4

19
main.go
View File

@@ -93,8 +93,6 @@ func mainPath(directory string) error {
return err
}
// parse $DATA
files, err := os.ReadDir(directory)
if err != nil {
return err
@@ -336,9 +334,9 @@ func doMoveTagged(filePath string, fileTags tag.Metadata) error {
}
tmplDataPath := LibTemplatePath{
Album: fileTags.Album(),
AlbumArtist: fileTags.AlbumArtist(),
Genre: fileTags.Genre(),
Album: cleanTemplateVariable(fileTags.Album()),
AlbumArtist: cleanTemplateVariable(fileTags.AlbumArtist()),
Genre: cleanTemplateVariable(fileTags.Genre()),
Year: fileTags.Year(),
}
@@ -367,9 +365,9 @@ func doMoveTaggedPathonly(filePath string, albumTags tag.Metadata) error {
tmplPath := template.Must(template.New("libPath").Parse(libTemplatePath))
tmplData := LibTemplatePath{
Album: albumTags.Album(),
AlbumArtist: albumTags.AlbumArtist(),
Genre: albumTags.Genre(),
Album: cleanTemplateVariable(albumTags.Album()),
AlbumArtist: cleanTemplateVariable(albumTags.AlbumArtist()),
Genre: cleanTemplateVariable(albumTags.Genre()),
Year: albumTags.Year(),
}
@@ -451,3 +449,8 @@ func cleanPath(str string) string {
re := regexp.MustCompile(`[<>:"|?*]`)
return re.ReplaceAllString(str, "")
}
func cleanTemplateVariable(str string) string {
re := regexp.MustCompile(`[<>:"|?*/\\]`)
return re.ReplaceAllString(str, "")
}