feat(subsonic): support timeOffset in stream.view (#384)

as per
https://github.com/opensubsonic/open-subsonic-api/pull/54
https://github.com/opensubsonic/open-subsonic-api/discussions/21

dont cache partial transcodes

add a transcode seek test
This commit is contained in:
Senan Kelly
2023-10-08 17:10:49 +01:00
committed by GitHub
parent 318b62415d
commit 7eaf602e69
4 changed files with 48 additions and 1 deletions

View File

@@ -38,7 +38,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{
{Name: "transcodeOffset", Versions: []int{1}},
}
return sub
}

View File

@@ -186,6 +186,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())
@@ -208,6 +209,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())