From 336559104ff6371262244fcf128851cdbda2fcb9 Mon Sep 17 00:00:00 2001 From: sentriz Date: Thu, 28 Sep 2023 21:24:57 +0100 Subject: [PATCH] feat(subsonic): support timeOffset in stream.view as per https://github.com/opensubsonic/open-subsonic-api/pull/54 https://github.com/opensubsonic/open-subsonic-api/discussions/21 --- server/ctrlsubsonic/handlers_common.go | 4 +++- server/ctrlsubsonic/handlers_raw.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/ctrlsubsonic/handlers_common.go b/server/ctrlsubsonic/handlers_common.go index fb2ed9ce..cef02f03 100644 --- a/server/ctrlsubsonic/handlers_common.go +++ b/server/ctrlsubsonic/handlers_common.go @@ -37,7 +37,9 @@ func (c *Controller) ServePing(_ *http.Request) *spec.Response { func (c *Controller) ServeGetOpenSubsonicExtensions(_ *http.Request) *spec.Response { sub := spec.NewResponse() - sub.OpenSubsonicExtensions = spec.OpenSubsonicExtensions{} + sub.OpenSubsonicExtensions = spec.OpenSubsonicExtensions{ + "transcodeOffset": {1}, + } return sub } diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index 650572ba..e14b39cc 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -218,6 +218,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R maxBitRate, _ := params.GetInt("maxBitRate") format, _ := params.Get("format") + timeOffset, _ := params.GetInt("timeOffset") if format == "raw" || maxBitRate >= audioFile.AudioBitrate() { http.ServeFile(w, r, file.AbsPath()) @@ -240,6 +241,9 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R if maxBitRate > 0 && int(profile.BitRate()) > maxBitRate { profile = transcode.WithBitrate(profile, transcode.BitRate(maxBitRate)) } + if timeOffset > 0 { + profile = transcode.WithSeek(profile, time.Second*time.Duration(timeOffset)) + } log.Printf("trancoding to %q with max bitrate %dk", profile.MIME(), profile.BitRate())