From 1b0a8fde364bf60a1fe65a1165b95bb81778382b Mon Sep 17 00:00:00 2001 From: Joren Date: Fri, 6 Sep 2024 11:58:20 +0200 Subject: [PATCH] Sanitize Filename --- main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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)