Commit daf2e4b8 authored by Eliot Berriot's avatar Eliot Berriot 💬

See #272: subsonic support for transcoding

parent b757ca46
......@@ -193,12 +193,17 @@ class SubsonicViewSet(viewsets.GenericViewSet):
@list_route(methods=["get", "post"], url_name="stream", url_path="stream")
@find_object(music_models.Track.objects.all(), filter_playable=True)
def stream(self, request, *args, **kwargs):
data = request.GET or request.POST
track = kwargs.pop("obj")
queryset = track.uploads.select_related("track__album__artist", "track__artist")
upload = queryset.first()
if not upload:
return response.Response(status=404)
return music_views.handle_serve(upload=upload, user=request.user)
format = data.get('format', 'raw')
if format == 'raw':
format = None
return music_views.handle_serve(upload=upload, user=request.user, format=format)
@list_route(methods=["get", "post"], url_name="star", url_path="star")
@find_object(music_models.Track.objects.all())
......
......@@ -4,9 +4,9 @@ import json
import pytest
from django.urls import reverse
from django.utils import timezone
from rest_framework.response import Response
import funkwhale_api
from funkwhale_api.music import models as music_models
from funkwhale_api.music import views as music_views
from funkwhale_api.subsonic import renderers, serializers
......@@ -199,11 +199,24 @@ def test_stream(f, db, logged_in_api_client, factories, mocker, queryset_equal_q
playable_by = mocker.spy(music_models.TrackQuerySet, "playable_by")
response = logged_in_api_client.get(url, {"f": f, "id": upload.track.pk})
mocked_serve.assert_called_once_with(upload=upload, user=logged_in_api_client.user)
mocked_serve.assert_called_once_with(
upload=upload, user=logged_in_api_client.user, format=None
)
assert response.status_code == 200
playable_by.assert_called_once_with(music_models.Track.objects.all(), None)
@pytest.mark.parametrize("format,expected", [("mp3", 'mp3'), ("raw", None)])
def test_stream_format(format, expected, logged_in_api_client, factories, mocker):
url = reverse("api:subsonic-stream")
mocked_serve = mocker.patch.object(music_views, "handle_serve", return_value=Response())
upload = factories["music.Upload"](playable=True)
response = logged_in_api_client.get(url, {"id": upload.track.pk, "format": format})
mocked_serve.assert_called_once_with(upload=upload, user=logged_in_api_client.user, format=expected)
assert response.status_code == 200
@pytest.mark.parametrize("f", ["xml", "json"])
def test_star(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-star")
......
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