Sanitize Filename

This commit is contained in:
Joren 2024-09-06 11:58:20 +02:00
parent f014b06f88
commit 1b0a8fde36
Signed by: Joren
GPG Key ID: 280E33DFBC0F1B55

13
main.go
View File

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