Commit 19b8adb3 authored by Eliot Berriot's avatar Eliot Berriot 💬

Merge branch '893-subsonic-content-type' into 'develop'

Fixed #893: empty contentType causing client crash in some Subsonic payloads

Closes #893

See merge request funkwhale/funkwhale!868
parents 53fa8e8c 8b13c076
......@@ -5,6 +5,7 @@ from rest_framework import serializers
from funkwhale_api.history import models as history_models
from import models as music_models
from import utils as music_utils
def get_artist_data(artist_values):
......@@ -71,7 +72,14 @@ def get_track_data(album, track, upload):
"track": track.position or 1,
"discNumber": track.disc_number or 1,
"contentType": upload.mimetype,
# Ugly fallback to mp3 but some subsonic clients fail if the value is empty or null, and we don't always
# have the info on legacy uploads
"contentType": upload.mimetype
or (
if upload.extension
else "audio/mpeg"
"suffix": upload.extension or "",
"duration": upload.duration or 0,
"created": track.creation_date,
import pytest
from import models as music_models
from funkwhale_api.subsonic import serializers
......@@ -61,6 +63,27 @@ def test_get_artist_serializer(factories):
assert serializers.GetArtistSerializer(artist).data == expected
"mimetype, extension, expected",
("audio/ogg", "noop", "audio/ogg"),
("", "ogg", "audio/ogg"),
("", "mp3", "audio/mpeg"),
("", "", "audio/mpeg"),
def test_get_track_data_content_type(mimetype, extension, expected, factories):
upload = factories["music.Upload"]()
upload.mimetype = mimetype
upload.audio_file = "test.{}".format(extension)
data = serializers.get_track_data(
album=upload.track.album, track=upload.track, upload=upload
assert data["contentType"] == expected
def test_get_album_serializer(factories):
artist = factories["music.Artist"]()
album = factories["music.Album"](artist=artist)
Fixed empty contentType causing client crash in some Subsonic payloads (#893)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment