remove invalid characters from generated filename (windows/linux)

This commit is contained in:
mappu 2021-04-12 12:15:42 +12:00
parent 793f3b5900
commit 8b5f2e035b

View File

@ -153,7 +153,14 @@ func performDownload(ctx context.Context, cfg *config, targetUrl string) error {
return err
}
outputFile = fmt.Sprintf(`[Loadtup] %s [%08X].mkv`, ltc.Title, hw.Sum())
var invalidChars *strings.Replacer
if runtime.GOOS == "windows" { // compile-time constant comparison will be elided
invalidChars = strings.NewReplacer(`"`, `_`, `*`, `_`, `<`, `_`, `>`, `_`, `?`, `_`, `\`, `_`, `|`, `_`, `/`, `_`, `:`, `_`)
} else {
invalidChars = strings.NewReplacer(`/`, `_`)
}
outputFile = fmt.Sprintf(`[Loadtup] %s [%08X].mkv`, invalidChars.Replace(ltc.Title), hw.Sum())
}
err = os.Rename(filepath.Join(tmpdir, "muxed.mkv"), outputFile)