v1.0.8 filename length limit
This commit is contained in:
@@ -2,3 +2,5 @@ LIBRARY_ROOT= # root directory for library
|
|||||||
LIBRARY_FILETEMPLATE_PATH= # go text/template string that represents the path in the library
|
LIBRARY_FILETEMPLATE_PATH= # go text/template string that represents the path in the library
|
||||||
LIBRARY_FILETEMPLATE_FILE= # go text/template string that represents the file name in the library path
|
LIBRARY_FILETEMPLATE_FILE= # go text/template string that represents the file name in the library path
|
||||||
LIBRARY_NOTAGS_ROOT= # path to put files without tags
|
LIBRARY_NOTAGS_ROOT= # path to put files without tags
|
||||||
|
|
||||||
|
FILENAME_LIMIT= # max length of a filename, default 255
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -9,4 +9,4 @@ require (
|
|||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require golang.org/x/text v0.26.0 // indirect
|
require golang.org/x/text v0.28.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -2,5 +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.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||||
|
|||||||
37
main.go
37
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@@ -151,9 +152,37 @@ func testEnv() error {
|
|||||||
return errors.New("missing LIBRARY_NOTAGS_ROOT")
|
return errors.New("missing LIBRARY_NOTAGS_ROOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !testEnvFilenameLimit() {
|
||||||
|
return errors.New("unable to parse FILENAME_LIMIT")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testEnvFilenameLimit() bool {
|
||||||
|
limit, ok := os.LookupEnv("FILENAME_LIMIT")
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
_, err := strconv.Atoi(limit)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnvFilenameLimit() int {
|
||||||
|
limit, ok := os.LookupEnv("FILENAME_LIMIT")
|
||||||
|
if !ok {
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
limit_i, err := strconv.Atoi(limit)
|
||||||
|
if err != nil {
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
return limit_i
|
||||||
|
}
|
||||||
|
|
||||||
func getTagsInDir(directory string) (tag.Metadata, error) {
|
func getTagsInDir(directory string) (tag.Metadata, error) {
|
||||||
files, err := os.ReadDir(directory)
|
files, err := os.ReadDir(directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -356,7 +385,13 @@ func doMoveTagged(filePath string, fileTags tag.Metadata) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
libFile := path.Join(libRoot, bufPath.String(), bufFile.String() + fileExt)
|
filenameLimit := getEnvFilenameLimit() - len(fileExt)
|
||||||
|
filename := bufFile.String()
|
||||||
|
if len(filename) > filenameLimit {
|
||||||
|
filename = filename[:filenameLimit]
|
||||||
|
}
|
||||||
|
|
||||||
|
libFile := path.Join(libRoot, bufPath.String(), filename + fileExt)
|
||||||
|
|
||||||
return move(filePath, libFile)
|
return move(filePath, libFile)
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
music-rename
BIN
music-rename
Binary file not shown.
Reference in New Issue
Block a user