1
0
mirror of https://github.com/thebaer/cdr.git synced 2024-11-15 01:31:01 +00:00

Clean filenames without track numbers

Previously, we'd fail if files had no numbers. Now this ignores and
continues anyway.
This commit is contained in:
Matt Baer 2022-03-30 23:32:17 -04:00
parent 48ff27f671
commit d49fde1263

View File

@ -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)
}