diff --git a/docs/transcoding.md b/docs/transcoding.md index 889a4ed..ed97c63 100644 --- a/docs/transcoding.md +++ b/docs/transcoding.md @@ -28,6 +28,7 @@ All these are defined by the following variables: * `trancoder` * `decoder` * `encoder` +* `default_transcode_target` where `EXT` is the lowercase file extension of the matching audio format. `transcoder`s variables have two extensions: the first one is the source @@ -61,6 +62,9 @@ One final note: the original file should be provided as an argument of transcoders and decoders. All transcoders, decoders and encoders should write to standard output, and encoders should read from standard input. +The value of `default_transcode_target` will be used as output format when a +client requests a bitrate lower than the original file and no specific format. + ## Suggested configuration Here are some example configuration that you could use. This is provided as-is, @@ -75,5 +79,6 @@ decoder_ogg = oggdec -o %srcpath decoder_flac = flac -d -c -s %srcpath encoder_mp3 = lame --quiet -b %outrate - - encoder_ogg = oggenc2 -q -M %outrate - +default_transcode_target = mp3 ``` diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 71825fc..fc7d18d 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -83,6 +83,8 @@ def stream_media(): dst_bitrate = res.bitrate dst_mimetype = res.mimetype + config = current_app.config["TRANSCODING"] + prefs = request.client if prefs.format: dst_suffix = prefs.format @@ -94,6 +96,8 @@ def stream_media(): if dst_bitrate > maxBitRate and maxBitRate != 0: dst_bitrate = maxBitRate + if not format: + format = config.get("default_transcode_target") if format and format != "raw" and format != src_suffix: dst_suffix = format @@ -112,7 +116,6 @@ def stream_media(): cache.get(cache_key), mimetype=dst_mimetype, conditional=True ) except CacheMiss: - config = current_app.config["TRANSCODING"] transcoder = config.get("transcoder_{}_{}".format(src_suffix, dst_suffix)) decoder = config.get("decoder_" + src_suffix) or config.get("decoder") encoder = config.get("encoder_" + dst_suffix) or config.get("encoder")