mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
return albums in get artist
This commit is contained in:
@@ -24,7 +24,6 @@ class ArtistHashSchema(BaseModel):
|
|||||||
"""
|
"""
|
||||||
Extending this class will give you a model with the `artisthash` field
|
Extending this class will give you a model with the `artisthash` field
|
||||||
"""
|
"""
|
||||||
|
|
||||||
artisthash: str = Field(
|
artisthash: str = Field(
|
||||||
description="The artist hash",
|
description="The artist hash",
|
||||||
example=Defaults.API_ARTISTHASH,
|
example=Defaults.API_ARTISTHASH,
|
||||||
@@ -68,6 +67,7 @@ class TrackLimitSchema(BaseModel):
|
|||||||
description="The number of tracks to return",
|
description="The number of tracks to return",
|
||||||
example=Defaults.API_CARD_LIMIT,
|
example=Defaults.API_CARD_LIMIT,
|
||||||
default=Defaults.API_CARD_LIMIT,
|
default=Defaults.API_CARD_LIMIT,
|
||||||
|
alias="tracklimit",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-9
@@ -3,6 +3,7 @@ Contains all the artist(s) routes.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
from pprint import pprint
|
||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from itertools import groupby
|
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])
|
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>")
|
@api.get("/<string:artisthash>")
|
||||||
def get_artist(path: ArtistHashSchema, query: TrackLimitSchema):
|
def get_artist(path: ArtistHashSchema, query: GetArtistQuery):
|
||||||
"""
|
"""
|
||||||
Get artist
|
Get artist
|
||||||
|
|
||||||
@@ -73,11 +84,18 @@ def get_artist(path: ArtistHashSchema, query: TrackLimitSchema):
|
|||||||
tracks = [
|
tracks = [
|
||||||
{
|
{
|
||||||
**serialize_track(t),
|
**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]
|
for t in tracks[:limit]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
query.limit = query.albumlimit
|
||||||
|
albums = get_artist_albums(path, query)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"artist": {
|
"artist": {
|
||||||
**serialize_for_card(artist),
|
**serialize_for_card(artist),
|
||||||
@@ -88,15 +106,10 @@ def get_artist(path: ArtistHashSchema, query: TrackLimitSchema):
|
|||||||
"is_favorite": artist.is_favorite,
|
"is_favorite": artist.is_favorite,
|
||||||
},
|
},
|
||||||
"tracks": tracks,
|
"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")
|
@api.get("/<artisthash>/albums")
|
||||||
def get_artist_albums(path: ArtistHashSchema, query: GetArtistAlbumsQuery):
|
def get_artist_albums(path: ArtistHashSchema, query: GetArtistAlbumsQuery):
|
||||||
"""
|
"""
|
||||||
@@ -176,7 +189,11 @@ def get_all_artist_tracks(path: ArtistHashSchema):
|
|||||||
tracks = [
|
tracks = [
|
||||||
{
|
{
|
||||||
**serialize_track(t),
|
**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
|
for t in tracks
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import locale
|
|||||||
from app.db.userdata import ScrobbleTable
|
from app.db.userdata import ScrobbleTable
|
||||||
from app.lib.extras import get_extra_info
|
from app.lib.extras import get_extra_info
|
||||||
from app.models.album import Album
|
from app.models.album import Album
|
||||||
|
from app.models.stats import StatItem
|
||||||
from app.models.track import Track
|
from app.models.track import Track
|
||||||
from app.serializers.artist import serialize_for_card
|
from app.serializers.artist import serialize_for_card
|
||||||
from app.serializers.album import serialize_for_card as serialize_for_album_card
|
from app.serializers.album import serialize_for_card as serialize_for_album_card
|
||||||
@@ -304,35 +305,35 @@ def get_stats():
|
|||||||
now = int(datetime.now().timestamp())
|
now = int(datetime.now().timestamp())
|
||||||
one_week_ago = now - 23731580
|
one_week_ago = now - 23731580
|
||||||
|
|
||||||
total_tracks = {
|
total_tracks = StatItem(
|
||||||
"class": "trackcount",
|
"trackcount",
|
||||||
"text": "Total tracks",
|
"Total tracks",
|
||||||
"value": len(TrackStore.get_flat_list()),
|
len(TrackStore.get_flat_list()),
|
||||||
}
|
)
|
||||||
last_7_tracks, last_7_days_playcount, last_7_days_playduration = (
|
last_7_tracks, last_7_days_playcount, last_7_days_playduration = (
|
||||||
get_tracks_in_period(one_week_ago, now)
|
get_tracks_in_period(one_week_ago, now)
|
||||||
)
|
)
|
||||||
|
|
||||||
last_7_days_playcount = {
|
last_7_days_playcount = StatItem(
|
||||||
"class": "streams",
|
"streams",
|
||||||
"text": "Track plays last week",
|
"Track plays last week",
|
||||||
"value": last_7_days_playcount,
|
last_7_days_playcount,
|
||||||
}
|
)
|
||||||
|
|
||||||
last_7_days_playduration = {
|
last_7_days_playduration = StatItem(
|
||||||
"class": "playtime",
|
"playtime",
|
||||||
"text": "Playtime last week",
|
"Playtime last week",
|
||||||
"value": seconds_to_time_string(last_7_days_playduration),
|
seconds_to_time_string(last_7_days_playduration),
|
||||||
}
|
)
|
||||||
|
|
||||||
last_7_tracks = sorted(last_7_tracks, key=lambda t: t.playduration, reverse=True)
|
last_7_tracks = sorted(last_7_tracks, key=lambda t: t.playduration, reverse=True)
|
||||||
|
|
||||||
# Find the top track from the last 7 days
|
# Find the top track from the last 7 days
|
||||||
top_track = {
|
top_track = StatItem(
|
||||||
"class": "toptrack",
|
"toptrack",
|
||||||
"text": "Top track last week",
|
"Top track last week",
|
||||||
"value": last_7_tracks[0].title,
|
last_7_tracks[0].title,
|
||||||
}
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"stats": [
|
"stats": [
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class StatItem:
|
||||||
|
cssclass: str
|
||||||
|
text: str
|
||||||
|
value: str | int
|
||||||
Reference in New Issue
Block a user