v1.0.5 confirm tags exist when scanning for tags

This commit is contained in:
2025-05-28 23:20:23 -05:00
parent ad962df961
commit 5dc8819cf7

26
main.go
View File

@@ -71,7 +71,10 @@ func getDir() (string, error) {
if len(os.Args) > 1 { if len(os.Args) > 1 {
return os.Args[1], nil return os.Args[1], nil
} else { } else {
dataArg := os.Getenv("SLSKD_SCRIPT_DATA") dataArg, found := os.LookupEnv("SLSKD_SCRIPT_DATA")
if !found {
return "", errors.New("missing any reference to a path")
}
var data DownloadDirectoryComplete var data DownloadDirectoryComplete
if err := json.Unmarshal([]byte(dataArg), &data); err != nil { if err := json.Unmarshal([]byte(dataArg), &data); err != nil {
return "", err return "", err
@@ -155,6 +158,7 @@ func getTagsInDir(directory string) (tag.Metadata, error) {
return nil, err return nil, err
} }
missingTags := false
for _, file := range files { for _, file := range files {
fname := path.Join(directory, file.Name()) fname := path.Join(directory, file.Name())
@@ -173,12 +177,30 @@ func getTagsInDir(directory string) (tag.Metadata, error) {
continue continue
} }
// if we found tags but they're incomplete, switch the flag
if !checkTags(tags) {
missingTags = true
continue
}
// found tag data // found tag data
return tags, nil return tags, nil
} }
// no tag data in any file // no tag data in any file
return nil, errors.New("missing tag data") if missingTags {
return nil, errors.New("files have incomplete tag data")
} else {
return nil, errors.New("unable to read tag data")
}
}
func checkTags(tags tag.Metadata) bool {
// most important tags
if tags.Album() == "" || tags.AlbumArtist() == "" || tags.Artist() == "" || tags.Title() == "" {
return false
}
return true
} }
func doMoveNotags(directory string) error { func doMoveNotags(directory string) error {