Add extension to downloaded filename

This commit is contained in:
Carl Pearson
2025-04-29 13:59:23 -06:00
parent 5d51d1a45a
commit 60f86652f7
2 changed files with 5 additions and 4 deletions

View File

@@ -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

View File

@@ -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,
})