1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56: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:
raise UnsupportedParameter("size")
maxBitRate, format, estimateContentLength = map(
maxBitRate, request_format, estimateContentLength = map(
request.values.get, ["maxBitRate", "format", "estimateContentLength"]
)
if format:
format = format.lower()
if request_format:
request_format = request_format.lower()
src_suffix = res.suffix()
dst_suffix = res.suffix()
@ -90,10 +90,17 @@ def stream_media():
dst_mimetype = res.mimetype
config = current_app.config["TRANSCODING"]
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
else:
using_default_format = True
dst_suffix = src_suffix
if prefs.bitrate and prefs.bitrate < dst_bitrate:
dst_bitrate = prefs.bitrate
@ -102,17 +109,17 @@ def stream_media():
if dst_bitrate > maxBitRate and maxBitRate != 0:
dst_bitrate = maxBitRate
if not format:
format = config.get("default_transcode_target")
if using_default_format:
dst_suffix = config.get("default_transcode_target") or dst_suffix
if format and format != "raw" and format != src_suffix:
dst_suffix = format
# Find new mimetype if we're changing formats
if dst_suffix != src_suffix:
dst_mimetype = (
mimetypes.guess_type("dummyname." + dst_suffix, False)[0]
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
cache = current_app.transcode_cache
cache_key = "{}-{}.{}".format(res.id, dst_bitrate, dst_suffix)