From d49fde12633d650367ba4bfca440caa631f497c4 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 30 Mar 2022 23:32:17 -0400 Subject: [PATCH] Clean filenames without track numbers Previously, we'd fail if files had no numbers. Now this ignores and continues anyway. --- sanitize.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sanitize.go b/sanitize.go index 8027d0d..dccfe02 100644 --- a/sanitize.go +++ b/sanitize.go @@ -41,15 +41,16 @@ func RenameTrack(file string) string { return "" } + ext := t.Filename[strings.LastIndex(t.Filename, "."):] + // Extract playlist track number from filename fMatch := trackNameReg.FindStringSubmatch(t.Filename) if len(fMatch) < 2 { - log.Fatal("Unexpect filename format") + log.Printf("No track number found: '%s'. Continuing anyway.\n", t.Filename) + return fmt.Sprintf("%s-%s%s", Sanitize(t.Artist), Sanitize(t.Title), ext) } + trackNum := fMatch[1] - - ext := t.Filename[strings.LastIndex(t.Filename, "."):] - return fmt.Sprintf("%s-%s-%s%s", trackNum, Sanitize(t.Artist), Sanitize(t.Title), ext) }