From 60f86652f7ad2d0cf494475b9c8788d1ef7d6c8b Mon Sep 17 00:00:00 2001 From: Carl Pearson Date: Tue, 29 Apr 2025 13:59:23 -0600 Subject: [PATCH] Add extension to downloaded filename --- README.md | 1 + handlers.go | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) 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, })