From b4bc9cb3cd5436020cf9699864d3943ebab152b6 Mon Sep 17 00:00:00 2001 From: cwilvx Date: Sun, 18 Aug 2024 06:56:51 +0300 Subject: [PATCH] fix: get all favorite tracks endpoint --- .github/changelog.md | 2 ++ TODO.md | 1 + app/api/artist.py | 6 +++++- app/api/favorites.py | 3 +-- app/api/playlist.py | 8 ++++---- app/db/userdata.py | 4 ++++ 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/changelog.md b/.github/changelog.md index 5132e9bf..09a6b020 100644 --- a/.github/changelog.md +++ b/.github/changelog.md @@ -5,6 +5,8 @@ - Auth - New artists/albums Sort by: last played, no. of streams, total stream duration - Option to show now playing track info on tab title. Go to Settings > Appearance to enable +- You can select which disc to play in an album +- Internal Backup and restore ## Improvements diff --git a/TODO.md b/TODO.md index 11178148..0b2c782e 100644 --- a/TODO.md +++ b/TODO.md @@ -44,6 +44,7 @@ - Create 2 way relationships, such that if an artist A is similar to another B with a certain weight, then artist B is similar to A with the same weight, unless overwritten. - Clean up tempfiles after transcoding +- Double sort artist tracks for consistency (alphabetically then by other field. eg. playcount) # Bug fixes diff --git a/app/api/artist.py b/app/api/artist.py index 150796cd..18fee334 100644 --- a/app/api/artist.py +++ b/app/api/artist.py @@ -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) diff --git a/app/api/favorites.py b/app/api/favorites.py index c23594a5..c0b1a3cb 100644 --- a/app/api/favorites.py +++ b/app/api/favorites.py @@ -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} diff --git a/app/api/playlist.py b/app/api/playlist.py index 8ba74cdb..b05cde8c 100644 --- a/app/api/playlist.py +++ b/app/api/playlist.py @@ -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] diff --git a/app/db/userdata.py b/app/db/userdata.py index c1debdd8..277a2614 100644 --- a/app/db/userdata.py +++ b/app/db/userdata.py @@ -225,6 +225,10 @@ class FavoritesTable(Base): res = result.fetchall() if start == 0: + # if limit == -1, return all + if limit == -1: + limit = len(res) + return res[:limit], len(res) return res, -1