diff --git a/README.md b/README.md index a147762..26e0087 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,4 @@ Build and push this container to ghcr - [x] sort videos most to least recent - [x] header on playlist page - [x] Choose database directory +- [x] add extension to download diff --git a/handlers.go b/handlers.go index e04b9a9..3ef7bda 100644 --- a/handlers.go +++ b/handlers.go @@ -788,8 +788,8 @@ func makeNiceFilename(input string) string { } // Remove any remaining non-alphanumeric characters (except underscores) - reg := regexp.MustCompile("[^a-z0-9_\\.]+") - input = reg.ReplaceAllString(input, "") + reg := regexp.MustCompile("[^a-z0-9_.-]") + input = reg.ReplaceAllString(input, "x") // Trim leading/trailing underscores input = strings.Trim(input, "_") @@ -849,7 +849,7 @@ func videoHandler(c echo.Context) error { FPS: fmt.Sprintf("%.1f", video.FPS), Size: humanSize(video.Size), Filename: video.Filename, - DownloadFilename: makeNiceFilename(orig.Title), + DownloadFilename: makeNiceFilename(orig.Title + filepath.Ext(tempURL.FilePath)), StreamRate: fmt.Sprintf("%.1f KiB/s", rate/1024), TempURL: tempURL, }) @@ -869,7 +869,7 @@ func videoHandler(c echo.Context) error { Kbps: fmt.Sprintf("%.1f kbps", kbps), Size: humanSize(audio.Size), Filename: audio.Filename, - DownloadFilename: makeNiceFilename(orig.Title), + DownloadFilename: makeNiceFilename(orig.Title + filepath.Ext(tempURL.FilePath)), StreamRate: fmt.Sprintf("%.1f KiB/s", rate/1024), TempURL: tempURL, })