diff --git a/internal/ripsort.go b/internal/ripsort.go index f22351c..c6ab40e 100644 --- a/internal/ripsort.go +++ b/internal/ripsort.go @@ -42,7 +42,12 @@ func Sort(dst, path string) { os.Exit(1) } + // Handle single file if !info.IsDir() { + if !fileSupported(path) { + slog.Error("Unsupported file format", "file", path) + os.Exit(1) + } if err := sortSong(path, dst); err != nil { slog.Error("Failed to sort single file", "file", path, "err", err) os.Exit(1) @@ -50,6 +55,7 @@ func Sort(dst, path string) { return } + // Handle directory err = filepath.WalkDir(path, func(p string, d fs.DirEntry, err error) error { if err != nil { slog.Error("Failed to walk path", "path", path, "file", p, "err", err) @@ -57,6 +63,9 @@ func Sort(dst, path string) { } if !d.IsDir() { + if !fileSupported(p) { + return nil + } if err := sortSong(p, dst); err != nil { slog.Error("Failed to sort file", "file", p, "err", err) return err diff --git a/internal/sorter.go b/internal/sorter.go index 97c32cf..fde3fe8 100644 --- a/internal/sorter.go +++ b/internal/sorter.go @@ -9,6 +9,15 @@ import ( "strings" ) +func fileSupported(file string) bool { + supported := map[string]bool{ + ".mp3": true, ".flac": true, + ".m4a": true, ".ogg": true, ".dsf": true, + } + + return supported[strings.ToLower(filepath.Ext(file))] +} + func sortSong(src, dst string) error { m, err := ReadAudioTags(src) if err != nil {