mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
[client] add playlists and playlist page
This commit is contained in:
@@ -50,7 +50,7 @@ def create_playlist():
|
||||
|
||||
|
||||
@playlist_bp.route("/playlist/<playlist_id>/add", methods=["POST"])
|
||||
def add_track_to_playlist(playlist_id):
|
||||
def add_track_to_playlist(playlist_id: str):
|
||||
data = request.get_json()
|
||||
|
||||
trackid = data["track"]
|
||||
@@ -61,3 +61,16 @@ def add_track_to_playlist(playlist_id):
|
||||
return {"error": str(e)}, 409
|
||||
|
||||
return {"msg": "I think It's done"}, 200
|
||||
|
||||
|
||||
@playlist_bp.route("/playlist/<playlist_id>")
|
||||
def get_single_p_info(playlist_id: str):
|
||||
for p in api.PLAYLISTS:
|
||||
if p.playlistid == playlist_id:
|
||||
return {"data": p}
|
||||
|
||||
|
||||
# @playlist_bp.route("/playlist/<playlist_id>/info")
|
||||
# def get_playlist_track(playlist_id: str):
|
||||
# tracks = playlistlib.get_playlist_tracks(playlist_id)
|
||||
# return {"data": tracks}
|
||||
|
||||
@@ -49,11 +49,13 @@ def get_album_image(album: list) -> str:
|
||||
|
||||
|
||||
def get_album_tracks(album: str, artist: str) -> List:
|
||||
return [
|
||||
track
|
||||
for track in api.PRE_TRACKS
|
||||
if track["album"] == album and track["albumartist"] == artist
|
||||
]
|
||||
tracks = []
|
||||
|
||||
for track in api.PRE_TRACKS:
|
||||
if track["album"] == album and track["albumartist"] == artist:
|
||||
tracks.append(track)
|
||||
|
||||
return tracks
|
||||
|
||||
|
||||
def create_album(track) -> models.Album:
|
||||
@@ -70,6 +72,7 @@ def create_album(track) -> models.Album:
|
||||
album["count"] = len(album_tracks)
|
||||
album["duration"] = get_album_duration(album_tracks)
|
||||
album["date"] = album_tracks[0]["date"]
|
||||
|
||||
album["artistimage"] = urllib.parse.quote_plus(
|
||||
album_tracks[0]["albumartist"] + ".webp"
|
||||
)
|
||||
|
||||
@@ -25,6 +25,13 @@ def add_track(playlistid: str, trackid: str):
|
||||
raise TrackExistsInPlaylist("Track already in playlist.")
|
||||
|
||||
|
||||
def get_playlist_tracks(pid: str):
|
||||
for p in api.PLAYLISTS:
|
||||
if p.playlistid == pid:
|
||||
return p.tracks
|
||||
|
||||
|
||||
|
||||
def create_all_playlists():
|
||||
"""
|
||||
Gets all playlists from the database.
|
||||
|
||||
Reference in New Issue
Block a user