feat(subsonic): skip transcoding if request bitrate is the same as track bitrate

fixes #241
This commit is contained in:
sentriz
2022-09-22 01:16:19 +02:00
parent 03df207e63
commit f41dd0818b

View File

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