From f41dd0818ba95e27fbad376438585a1057f60382 Mon Sep 17 00:00:00 2001 From: sentriz Date: Thu, 22 Sep 2022 01:16:19 +0200 Subject: [PATCH] feat(subsonic): skip transcoding if request bitrate is the same as track bitrate fixes #241 --- server/ctrlsubsonic/handlers_raw.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/ctrlsubsonic/handlers_raw.go b/server/ctrlsubsonic/handlers_raw.go index ce52a7ca..2c1cdc0f 100644 --- a/server/ctrlsubsonic/handlers_raw.go +++ b/server/ctrlsubsonic/handlers_raw.go @@ -264,7 +264,10 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R }() } - if format, _ := params.Get("format"); format == "raw" { + maxBitRate, _ := params.GetInt("maxBitRate") + format, _ := params.Get("format") + + if format == "raw" || maxBitRate >= file.AudioBitrate() { http.ServeFile(w, r, audioPath) return nil } @@ -282,8 +285,8 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R if !ok { return spec.NewError(0, "unknown transcode user profile %q", pref.Profile) } - if max, _ := params.GetInt("maxBitRate"); max > 0 && int(profile.BitRate()) > max { - profile = transcode.WithBitrate(profile, transcode.BitRate(max)) + if maxBitRate > 0 && int(profile.BitRate()) > maxBitRate { + profile = transcode.WithBitrate(profile, transcode.BitRate(maxBitRate)) } log.Printf("trancoding to %q with max bitrate %dk", profile.MIME(), profile.BitRate())