From 5d32536758268d9c7c15fc3c0670bc2317eeea87 Mon Sep 17 00:00:00 2001 From: cwilvx Date: Fri, 19 Jul 2024 23:46:28 +0300 Subject: [PATCH] implement getting all playlist tracks --- app/api/playlist.py | 3 +++ app/store/playlists.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/api/playlist.py b/app/api/playlist.py index fe382785..7e9aa3a3 100644 --- a/app/api/playlist.py +++ b/app/api/playlist.py @@ -205,6 +205,9 @@ def get_playlist(path: PlaylistIDPath, query: GetPlaylistQuery): return {"msg": "Playlist not found"}, 404 playlist = entry.playlist + if query.limit == -1: + query.limit = None + tracks = PlaylistStore.get_playlist_tracks(playlistid, query.start, query.limit) duration = sum(t.duration for t in tracks) diff --git a/app/store/playlists.py b/app/store/playlists.py index c74827f8..a575e11e 100644 --- a/app/store/playlists.py +++ b/app/store/playlists.py @@ -32,7 +32,7 @@ class PlaylistStore: print(cls.playlistmap) @classmethod - def get_playlist_tracks(cls, playlist_id: str, start: int, limit: int): + def get_playlist_tracks(cls, playlist_id: str, start: int, limit: int | None): """ Returns the trackhashes for a playlist. """ @@ -41,6 +41,9 @@ class PlaylistStore: if entry is None: return [] + if limit is None: + return TrackStore.get_tracks_by_trackhashes(entry.trackhashes[start:]) + return TrackStore.get_tracks_by_trackhashes( entry.trackhashes[start : start + limit] ) @@ -71,4 +74,4 @@ class PlaylistStore: if playlist.trackhashes.index(track["trackhash"]) == track["index"]: playlist.trackhashes.remove(track["trackhash"]) - playlist.rebuild_images() \ No newline at end of file + playlist.rebuild_images()