subsonic: Implement getSong API endpoint
The getSong API endpoint is used by, e.g., the subsonic plugin to mopidy. Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
This commit is contained in:
parent
8193782f68
commit
7d9220ed49
3 changed files with 31 additions and 0 deletions
|
|
@ -130,6 +130,14 @@ class GetAlbumSerializer(serializers.Serializer):
|
|||
return payload
|
||||
|
||||
|
||||
class GetSongSerializer(serializers.Serializer):
|
||||
def to_representation(self, track):
|
||||
tf = track.files.all()
|
||||
if not len(tf):
|
||||
return {}
|
||||
return get_track_data(track.album, track, tf[0])
|
||||
|
||||
|
||||
def get_starred_tracks_data(favorites):
|
||||
by_track_id = {f.track_id: f for f in favorites}
|
||||
tracks = (
|
||||
|
|
|
|||
|
|
@ -147,6 +147,15 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
|||
|
||||
return response.Response(payload, status=200)
|
||||
|
||||
@list_route(methods=["get", "post"], url_name="get_song", url_path="getSong")
|
||||
@find_object(music_models.Track.objects.all())
|
||||
def get_song(self, request, *args, **kwargs):
|
||||
track = kwargs.pop("obj")
|
||||
data = serializers.GetSongSerializer(track).data
|
||||
payload = {"song": data}
|
||||
|
||||
return response.Response(payload, status=200)
|
||||
|
||||
@list_route(
|
||||
methods=["get", "post"], url_name="get_artist_info2", url_path="getArtistInfo2"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue