diff --git a/main.go b/main.go index 16cc925..5b1643d 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( "time" "embed" + "regexp" "github.com/BurntSushi/toml" "github.com/asticode/go-astisub" @@ -274,7 +275,9 @@ func getDownloadCommand(item Item, mpdPath string) string { command += " --auto-select" - filename := fmt.Sprintf("\"%s\"", item.Filename) + sanitizedFilename := sanitizeFilename(item.Filename) + + filename := fmt.Sprintf("\"%s\"", sanitizedFilename) command += fmt.Sprintf(" --save-name %s", filename) command += fmt.Sprintf(" --mux-after-done format=%s", config.Format) @@ -292,6 +295,14 @@ func getDownloadCommand(item Item, mpdPath string) string { return command } +func sanitizeFilename(filename string) string { + filename = regexp.MustCompile(`[<>:"/\\|?*]`).ReplaceAllString(filename, "_") + + filename = strings.Trim(filename, ".") + + return filename +} + func downloadFile(item Item) error { fmt.Println("Downloading:", item.Filename)