1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Fix wrong mimetype being returned when transcoding

Previously, when a client that was configured to always transcode
requested a stream without specifying a format, the mimetype would not
be set to the transcode target type.

This commit simplifies the logic that decides which format should be
used and always sets the mimetype if the destination format doesn't
match the source format.
This commit is contained in:
Carey Metcalfe 2020-01-22 10:50:57 -05:00
parent acb6b773a9
commit 94624518ed

View File

@ -78,11 +78,11 @@ def stream_media():
if "size" in request.values: if "size" in request.values:
raise UnsupportedParameter("size") raise UnsupportedParameter("size")
maxBitRate, format, estimateContentLength = map( maxBitRate, request_format, estimateContentLength = map(
request.values.get, ["maxBitRate", "format", "estimateContentLength"] request.values.get, ["maxBitRate", "format", "estimateContentLength"]
) )
if format: if request_format:
format = format.lower() request_format = request_format.lower()
src_suffix = res.suffix() src_suffix = res.suffix()
dst_suffix = res.suffix() dst_suffix = res.suffix()
@ -90,10 +90,17 @@ def stream_media():
dst_mimetype = res.mimetype dst_mimetype = res.mimetype
config = current_app.config["TRANSCODING"] config = current_app.config["TRANSCODING"]
prefs = request.client prefs = request.client
if prefs.format:
using_default_format = False
if request_format:
dst_suffix = src_suffix if request_format == "raw" else request_format
elif prefs.format:
dst_suffix = prefs.format dst_suffix = prefs.format
else:
using_default_format = True
dst_suffix = src_suffix
if prefs.bitrate and prefs.bitrate < dst_bitrate: if prefs.bitrate and prefs.bitrate < dst_bitrate:
dst_bitrate = prefs.bitrate dst_bitrate = prefs.bitrate
@ -102,17 +109,17 @@ def stream_media():
if dst_bitrate > maxBitRate and maxBitRate != 0: if dst_bitrate > maxBitRate and maxBitRate != 0:
dst_bitrate = maxBitRate dst_bitrate = maxBitRate
if not format: if using_default_format:
format = config.get("default_transcode_target") dst_suffix = config.get("default_transcode_target") or dst_suffix
if format and format != "raw" and format != src_suffix: # Find new mimetype if we're changing formats
dst_suffix = format if dst_suffix != src_suffix:
dst_mimetype = ( dst_mimetype = (
mimetypes.guess_type("dummyname." + dst_suffix, False)[0] mimetypes.guess_type("dummyname." + dst_suffix, False)[0]
or "application/octet-stream" or "application/octet-stream"
) )
if format != "raw" and (dst_suffix != src_suffix or dst_bitrate != res.bitrate): if dst_suffix != src_suffix or dst_bitrate != res.bitrate:
# Requires transcoding # Requires transcoding
cache = current_app.transcode_cache cache = current_app.transcode_cache
cache_key = "{}-{}.{}".format(res.id, dst_bitrate, dst_suffix) cache_key = "{}-{}.{}".format(res.id, dst_bitrate, dst_suffix)