mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
fix: get all favorite tracks endpoint
This commit is contained in:
+5
-1
@@ -2,7 +2,6 @@
|
||||
Contains all the artist(s) routes.
|
||||
"""
|
||||
|
||||
from dataclasses import asdict
|
||||
import math
|
||||
import random
|
||||
from datetime import datetime
|
||||
@@ -48,6 +47,9 @@ def get_artist(path: ArtistHashSchema, query: TrackLimitSchema):
|
||||
return {"error": "Artist not found"}, 404
|
||||
|
||||
tracks = TrackStore.get_tracks_by_trackhashes(entry.trackhashes)
|
||||
tracks = sorted(tracks, key=lambda t: t.title)
|
||||
tracks = sorted(tracks, key= lambda t: t.playcount, reverse=True)
|
||||
print([{t.title, t.playcount, t.trackhash} for t in tracks])
|
||||
tcount = len(tracks)
|
||||
|
||||
artist = entry.artist
|
||||
@@ -162,6 +164,8 @@ def get_all_artist_tracks(path: ArtistHashSchema):
|
||||
Returns all artists by a given artist.
|
||||
"""
|
||||
tracks = ArtistStore.get_artist_tracks(path.artisthash)
|
||||
tracks = sorted(tracks, key=lambda t: t.title)
|
||||
tracks = sorted(tracks, key= lambda t: t.playcount, reverse=True)
|
||||
return serialize_tracks(tracks)
|
||||
|
||||
|
||||
|
||||
@@ -131,9 +131,8 @@ def get_favorite_tracks(query: GetAllOfTypeQuery):
|
||||
Get favorite tracks
|
||||
"""
|
||||
tracks, total = FavoritesTable.get_fav_tracks(query.start, query.limit)
|
||||
|
||||
tracks.reverse()
|
||||
tracks = TrackTable.get_tracks_by_trackhashes([t.hash for t in tracks])
|
||||
tracks = TrackStore.get_tracks_by_trackhashes([t.hash for t in tracks])
|
||||
|
||||
return {"tracks": serialize_tracks(tracks), "total": total}
|
||||
|
||||
|
||||
+4
-4
@@ -13,7 +13,6 @@ from flask_openapi3 import APIBlueprint, FileStorage
|
||||
|
||||
from app import models
|
||||
from app.api.apischemas import GenericLimitSchema
|
||||
from app.db.libdata import TrackTable
|
||||
from app.db.userdata import PlaylistTable
|
||||
from app.lib import playlistlib
|
||||
from app.lib.albumslib import sort_by_track_no
|
||||
@@ -57,7 +56,7 @@ def get_path_trackhashes(path: str):
|
||||
"""
|
||||
Returns a list of trackhashes in a folder.
|
||||
"""
|
||||
tracks = TrackTable.get_tracks_in_path(path)
|
||||
tracks = TrackStore.get_tracks_in_path(path)
|
||||
return [t.trackhash for t in tracks]
|
||||
|
||||
|
||||
@@ -65,7 +64,7 @@ def get_album_trackhashes(albumhash: str):
|
||||
"""
|
||||
Returns a list of trackhashes in an album.
|
||||
"""
|
||||
tracks = TrackTable.get_tracks_by_albumhash(albumhash)
|
||||
tracks = TrackStore.get_tracks_by_albumhash(albumhash)
|
||||
tracks = sort_by_track_no(tracks)
|
||||
|
||||
return [t.trackhash for t in tracks]
|
||||
@@ -75,7 +74,8 @@ def get_artist_trackhashes(artisthash: str):
|
||||
"""
|
||||
Returns a list of trackhashes for an artist.
|
||||
"""
|
||||
tracks = TrackTable.get_tracks_by_artisthash(artisthash)
|
||||
tracks = TrackStore.get_tracks_by_artisthash(artisthash)
|
||||
tracks = sorted(tracks, key= lambda t: t.playcount, reverse=True)
|
||||
return [t.trackhash for t in tracks]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user