views.py 2.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from rest_framework import viewsets
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.decorators import list_route

from funkwhale_api.common.permissions import ConditionalAuthentication


from .client import api


class ReleaseDetail(APIView):
    permission_classes = [ConditionalAuthentication]

    def get(self, request, *args, **kwargs):
Agate's avatar
Agate committed
16
        result = api.releases.get(id=kwargs["uuid"], includes=["artists", "recordings"])
17 18 19 20 21 22 23
        return Response(result)


class ArtistDetail(APIView):
    permission_classes = [ConditionalAuthentication]

    def get(self, request, *args, **kwargs):
Agate's avatar
Agate committed
24
        result = api.artists.get(id=kwargs["uuid"], includes=["release-groups"])
25 26 27 28 29 30 31 32
        # import json; print(json.dumps(result, indent=4))
        return Response(result)


class ReleaseGroupBrowse(APIView):
    permission_classes = [ConditionalAuthentication]

    def get(self, request, *args, **kwargs):
Agate's avatar
Agate committed
33
        result = api.release_groups.browse(artist=kwargs["artist_uuid"])
34 35 36 37 38 39 40 41
        return Response(result)


class ReleaseBrowse(APIView):
    permission_classes = [ConditionalAuthentication]

    def get(self, request, *args, **kwargs):
        result = api.releases.browse(
Agate's avatar
Agate committed
42 43 44
            release_group=kwargs["release_group_uuid"],
            includes=["recordings", "artist-credits"],
        )
45 46 47 48 49 50
        return Response(result)


class SearchViewSet(viewsets.ViewSet):
    permission_classes = [ConditionalAuthentication]

Agate's avatar
Agate committed
51
    @list_route(methods=["get"])
52
    def recordings(self, request, *args, **kwargs):
Agate's avatar
Agate committed
53
        query = request.GET["query"]
54
        results = api.recordings.search(query)
55 56
        return Response(results)

Agate's avatar
Agate committed
57
    @list_route(methods=["get"])
58
    def releases(self, request, *args, **kwargs):
Agate's avatar
Agate committed
59
        query = request.GET["query"]
60
        results = api.releases.search(query)
61 62
        return Response(results)

Agate's avatar
Agate committed
63
    @list_route(methods=["get"])
64
    def artists(self, request, *args, **kwargs):
Agate's avatar
Agate committed
65
        query = request.GET["query"]
66
        results = api.artists.search(query)
67
        # results = musicbrainzngs.search_artists(query)
68
        return Response(results)