OpenSubsonic: MBID for artist results, added mediaType field
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2695>
This commit is contained in:
parent
e169e8edb1
commit
bf8f1e41b9
|
@ -50,6 +50,7 @@ def get_artist_data(artist_values):
|
|||
"name": artist_values["name"],
|
||||
"albumCount": artist_values["_albums_count"],
|
||||
"coverArt": "ar-{}".format(artist_values["id"]),
|
||||
"musicBrainzId": str(artist_values.get("mbid", "")),
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,7 +59,7 @@ class GetArtistsSerializer(serializers.Serializer):
|
|||
payload = {"ignoredArticles": "", "index": []}
|
||||
queryset = queryset.with_albums_count()
|
||||
queryset = queryset.order_by(functions.Lower("name"))
|
||||
values = queryset.values("id", "_albums_count", "name")
|
||||
values = queryset.values("id", "_albums_count", "name", "mbid")
|
||||
|
||||
first_letter_mapping = collections.defaultdict(list)
|
||||
for artist in values:
|
||||
|
@ -126,6 +127,7 @@ def get_track_data(album, track, upload):
|
|||
"albumId": album.pk if album else "",
|
||||
"artistId": album.artist.pk if album else track.artist.pk,
|
||||
"type": "music",
|
||||
"mediaType": "song",
|
||||
"musicBrainzId": str(track.mbid or ""),
|
||||
}
|
||||
if album and album.attachment_cover_id:
|
||||
|
@ -150,6 +152,7 @@ def get_album2_data(album):
|
|||
"created": to_subsonic_date(album.creation_date),
|
||||
"duration": album.duration,
|
||||
"playCount": album.tracks.aggregate(l=Count("listenings"))["l"] or 0,
|
||||
"mediaType": "album",
|
||||
"musicBrainzId": str(album.mbid or ""),
|
||||
}
|
||||
if album.attachment_cover_id:
|
||||
|
|
|
@ -550,7 +550,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
|
|||
"search_fields": ["name"],
|
||||
"queryset": (
|
||||
music_models.Artist.objects.with_albums_count().values(
|
||||
"id", "_albums_count", "name"
|
||||
"id", "_albums_count", "name", "mbid"
|
||||
)
|
||||
),
|
||||
"serializer": lambda qs: [serializers.get_artist_data(a) for a in qs],
|
||||
|
|
|
@ -90,12 +90,14 @@ def test_get_artists_serializer(factories):
|
|||
"name": artist1.name,
|
||||
"albumCount": 3,
|
||||
"coverArt": f"ar-{artist1.id}",
|
||||
"musicBrainzId": artist1.mbid,
|
||||
},
|
||||
{
|
||||
"id": artist2.pk,
|
||||
"name": artist2.name,
|
||||
"albumCount": 2,
|
||||
"coverArt": f"ar-{artist2.id}",
|
||||
"musicBrainzId": artist2.mbid,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -107,6 +109,7 @@ def test_get_artists_serializer(factories):
|
|||
"name": artist3.name,
|
||||
"albumCount": 0,
|
||||
"coverArt": f"ar-{artist3.id}",
|
||||
"musicBrainzId": artist3.mbid,
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -185,6 +188,7 @@ def test_get_album_serializer(factories):
|
|||
"coverArt": f"al-{album.id}",
|
||||
"genre": tagged_item.tag.name,
|
||||
"genres": [{"name": tagged_item.tag.name}],
|
||||
"mediaType": "album",
|
||||
"musicBrainzId": album.mbid,
|
||||
"duration": 43,
|
||||
"playCount": album.tracks.aggregate(l=Count("listenings"))["l"] or 0,
|
||||
|
@ -209,6 +213,7 @@ def test_get_album_serializer(factories):
|
|||
"albumId": album.pk,
|
||||
"artistId": artist.pk,
|
||||
"type": "music",
|
||||
"mediaType": "song",
|
||||
"musicBrainzId": track.mbid,
|
||||
}
|
||||
],
|
||||
|
|
|
@ -596,7 +596,7 @@ def test_search3(f, db, logged_in_api_client, factories):
|
|||
artist_qs = (
|
||||
music_models.Artist.objects.with_albums_count()
|
||||
.filter(pk=artist.pk)
|
||||
.values("_albums_count", "id", "name")
|
||||
.values("_albums_count", "id", "name", "mbid")
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data == {
|
||||
|
|
Loading…
Reference in New Issue