summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-06 08:04:06 +0300
committerPaul Buetow <paul@buetow.org>2026-05-06 08:04:06 +0300
commit885dd0912dd0e4f9df86b6676a6c467bdb367660 (patch)
treecd77d4baf36c5817c7c3b29ace6e7ab6f5c04073 /internal
parent532747899cb6db7e5208a454779c37092c8c6451 (diff)
Fix music video duration display in progress bar
Diffstat (limited to 'internal')
-rw-r--r--internal/api/handlers.go9
-rw-r--r--internal/service/browse.go1
-rw-r--r--internal/service/service.go1
-rw-r--r--internal/service/share.go1
4 files changed, 9 insertions, 3 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go
index 5a289a1..411607d 100644
--- a/internal/api/handlers.go
+++ b/internal/api/handlers.go
@@ -127,7 +127,7 @@ func (s *Server) serveFileResult(w http.ResponseWriter, r *http.Request, res *se
}
if !attachment && probe.LooksLikeMPEGTS(res.Path) {
- s.serveRemuxedMP4(w, r, res, stat.Size())
+ s.serveRemuxedMP4(w, r, res)
return
}
@@ -143,10 +143,13 @@ func (s *Server) serveFileResult(w http.ResponseWriter, r *http.Request, res *se
http.ServeContent(w, r, res.FileName, stat.ModTime(), f)
}
-func (s *Server) serveRemuxedMP4(w http.ResponseWriter, r *http.Request, res *service.FileResult, size int64) {
+func (s *Server) serveRemuxedMP4(w http.ResponseWriter, r *http.Request, res *service.FileResult) {
w.Header().Set("Content-Type", "video/mp4")
w.Header().Set("Cache-Control", "no-store")
- s.logger.Info("api remux stream file", "file", res.FileName, "size", size, "range", r.Header.Get("Range"))
+ if res.Duration > 0 {
+ w.Header().Set("X-Duration", fmt.Sprintf("%f", res.Duration))
+ }
+ s.logger.Info("api remux stream file", "file", res.FileName, "size", res.FileSize, "range", r.Header.Get("Range"))
if err := s.remuxer.Remux(r.Context(), res.Path, w); err != nil {
s.logger.Error("remux media", "file", res.FileName, "err", err)
}
diff --git a/internal/service/browse.go b/internal/service/browse.go
index d1f32cc..b420d70 100644
--- a/internal/service/browse.go
+++ b/internal/service/browse.go
@@ -166,6 +166,7 @@ func (s *browseService) StreamMedia(ctx context.Context, mediaID, userID int64)
Path: media.AbsPath,
FileName: media.FileName,
FileSize: media.FileSizeBytes,
+ Duration: media.Duration,
}, nil
}
diff --git a/internal/service/service.go b/internal/service/service.go
index 818ae3f..6a5f6e6 100644
--- a/internal/service/service.go
+++ b/internal/service/service.go
@@ -233,6 +233,7 @@ type FileResult struct {
Path string
FileName string
FileSize int64
+ Duration float64 // DB-stored duration (seconds), used for remuxed streams.
}
// MediaDetail combines media with related data.
diff --git a/internal/service/share.go b/internal/service/share.go
index c87d8f6..2b917f7 100644
--- a/internal/service/share.go
+++ b/internal/service/share.go
@@ -129,6 +129,7 @@ func (s *shareService) StreamSharedMedia(ctx context.Context, token string) (*Fi
Path: media.AbsPath,
FileName: media.FileName,
FileSize: media.FileSizeBytes,
+ Duration: media.Duration,
}, nil
}