sentriz / gonic

music streaming server / free-software subsonic server API implementation
ircs://irc.libera.chat/#gonic
GNU General Public License v3.0
1.57k stars 112 forks source link

DSub can't play song when bitrate is set to "unlimited" #485

Closed rholveck closed 6 months ago

rholveck commented 6 months ago

gonic version: v0.16.3

Hi ! First of all : Great job with gonic, I've been using it since a few weeks and I love it :)

Playback isn't working anymore since 0.16.3 if one wants to play a raw file (=not transcoded) in DSub.

This issue has been introduced in This commit

To reproduce :

What happens :

When fetching a song while configured with unlimited bitrate, DSub sets the maxBitRate parameter to the original file actual bitrate. Example for a MP3 v0 file :

Mar 20 13:55:50 host.domain.tld gonic[3355641]: 2024/03/20 13:55:50 response 200 GET /stream?u=user&s=xxxxxxxxxxxxxx&v=1.2.0&c=DSub&id=tr-821&maxBitRate=275

This triggers the check made in the commit indicated above and results in this error :

subsonic error code 0: maxBitRate requested and no user transcode preferences found for user "user" and client "DSub"

I think the problem here is the order in which the checks are made in the section of code below : first "pref" is checked for a gonic transcoding profile and then the requested bitrate is compared to the actual file bitrate. In my understanding these check should be done the other way around so that the raw file is served as soon as the requested bitrate is higher than the raw file bitrate, no matter if a transcoding profile is configured or not in gonic.

    if pref == nil {
        if maxBitRate > 0 {
            return spec.NewError(0, "maxBitRate requested and no user transcode preferences found for user %q and client %q", user.Name, client)
        }
        log.Printf("serving raw file, no user transcode preferences found for user %q and client %q", user.Name, client)
        http.ServeFile(w, r, file.AbsPath())
        return nil
    }

    if maxBitRate >= audioFile.AudioBitrate() {
        log.Printf("serving raw file, requested max bitrate %d is greater or equal to %d", maxBitRate, audioFile.AudioBitrate())
        http.ServeFile(w, r, file.AbsPath())
        return nil
    }

Tell me what you think ! Have a great day :)

khannurien commented 6 months ago

Confirmed, I made the same observation. This is a problem since I have to disable transcoding totally in gonic's backend, otherwise tracks don't play back correctly in a web browser (cf. https://github.com/sentriz/gonic/issues/452).

sentriz commented 6 months ago

ooops

sentriz commented 6 months ago

thanks for reporting 👍

rholveck commented 6 months ago

No problem, thanks for the quick fix :)