return albums in get artist

This commit is contained in:
cwilvx
2024-10-13 18:13:00 +03:00
parent 99b30b5894
commit 7ef63c1f10
4 changed files with 56 additions and 30 deletions
+26 -9
View File
@@ -3,6 +3,7 @@ Contains all the artist(s) routes.
"""
import math
from pprint import pprint
import random
from datetime import datetime
from itertools import groupby
@@ -32,8 +33,18 @@ bp_tag = Tag(name="Artist", description="Single artist")
api = APIBlueprint("artist", __name__, url_prefix="/artist", abp_tags=[bp_tag])
class GetArtistAlbumsQuery(AlbumLimitSchema):
all: bool = Field(
description="Whether to ignore albumlimit and return all albums", default=False
)
class GetArtistQuery(TrackLimitSchema, GetArtistAlbumsQuery):
albumlimit: int = Field(7, description="The number of albums to return")
@api.get("/<string:artisthash>")
def get_artist(path: ArtistHashSchema, query: TrackLimitSchema):
def get_artist(path: ArtistHashSchema, query: GetArtistQuery):
"""
Get artist
@@ -73,11 +84,18 @@ def get_artist(path: ArtistHashSchema, query: TrackLimitSchema):
tracks = [
{
**serialize_track(t),
"help_text": "unplayed" if t.playcount == 0 else f"{t.playcount} play{'' if t.playcount == 1 else 's'}"
"help_text": (
"unplayed"
if t.playcount == 0
else f"{t.playcount} play{'' if t.playcount == 1 else 's'}"
),
}
for t in tracks[:limit]
]
query.limit = query.albumlimit
albums = get_artist_albums(path, query)
return {
"artist": {
**serialize_for_card(artist),
@@ -88,15 +106,10 @@ def get_artist(path: ArtistHashSchema, query: TrackLimitSchema):
"is_favorite": artist.is_favorite,
},
"tracks": tracks,
"albums": albums,
}
class GetArtistAlbumsQuery(AlbumLimitSchema):
all: bool = Field(
description="Whether to ignore limit and return all albums", default=False
)
@api.get("/<artisthash>/albums")
def get_artist_albums(path: ArtistHashSchema, query: GetArtistAlbumsQuery):
"""
@@ -176,7 +189,11 @@ def get_all_artist_tracks(path: ArtistHashSchema):
tracks = [
{
**serialize_track(t),
"help_text": "unplayed" if t.playcount == 0 else f"{t.playcount} play{'' if t.playcount == 1 else 's'}"
"help_text": (
"unplayed"
if t.playcount == 0
else f"{t.playcount} play{'' if t.playcount == 1 else 's'}"
),
}
for t in tracks
]