mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
join routes to save artists, albums and folders into one
This commit is contained in:
+30
-77
@@ -376,92 +376,45 @@ def playlist_exists(name: str) -> bool:
|
|||||||
return count_playlist_by_name(name) > 0
|
return count_playlist_by_name(name) > 0
|
||||||
|
|
||||||
|
|
||||||
@api.route("/playlist/save-folder", methods=["POST"])
|
@api.route("/playlist/save-item", methods=["POST"])
|
||||||
def save_folder_as_folder():
|
def save_item_as_playlist():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
msg = {"error": "'path' and 'playlist_name' not provided"}, 400
|
msg = {"error": "'itemtype', 'playlist_name' and 'itemhash' not provided"}, 400
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
name = data.get("playlist_name")
|
try:
|
||||||
path = data.get("path")
|
playlist_name = data["playlist_name"]
|
||||||
|
except KeyError:
|
||||||
|
playlist_name = None
|
||||||
|
|
||||||
if path is None or name is None:
|
if playlist_exists(playlist_name):
|
||||||
return msg
|
|
||||||
|
|
||||||
if playlist_exists(name):
|
|
||||||
return {"error": "Playlist already exists"}, 409
|
return {"error": "Playlist already exists"}, 409
|
||||||
|
|
||||||
trackhashes = get_path_trackhashes(path)
|
try:
|
||||||
if len(trackhashes) == 0:
|
itemtype = data["itemtype"]
|
||||||
return {"error": "No tracks found in folder"}, 404
|
except KeyError:
|
||||||
|
itemtype = None
|
||||||
|
|
||||||
playlist = insert_playlist(name)
|
try:
|
||||||
|
itemhash = data["itemhash"]
|
||||||
if playlist is None:
|
except KeyError:
|
||||||
return {"error": "Playlist could not be created"}, 500
|
itemhash = None
|
||||||
|
|
||||||
tracks_to_playlist(playlist.id, trackhashes)
|
if itemtype == "folder":
|
||||||
PL.update_last_updated(playlist.id)
|
trackhashes = get_path_trackhashes(itemhash)
|
||||||
|
elif itemtype == "album":
|
||||||
return {"playlist_id": playlist.id}, 201
|
trackhashes = get_album_trackhashes(itemhash)
|
||||||
|
elif itemtype == "artist":
|
||||||
|
trackhashes = get_artist_trackhashes(itemhash)
|
||||||
@api.route("/playlist/save-album", methods=["POST"])
|
else:
|
||||||
def save_album_as_playlist():
|
trackhashes = []
|
||||||
data = request.get_json()
|
|
||||||
msg = {"error": "'albumhash' and 'playlist_name' not provided"}, 400
|
if len(trackhashes) == 0:
|
||||||
|
return {"error": "No tracks founds"}, 404
|
||||||
if data is None:
|
|
||||||
return msg
|
playlist = insert_playlist(playlist_name)
|
||||||
|
|
||||||
albumhash = data.get("albumhash")
|
|
||||||
name = data.get("playlist_name")
|
|
||||||
|
|
||||||
if albumhash is None or name is None:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if playlist_exists(name):
|
|
||||||
return {"error": "Playlist already exists"}, 409
|
|
||||||
|
|
||||||
trackhashes = get_album_trackhashes(albumhash)
|
|
||||||
if len(trackhashes) == 0:
|
|
||||||
return {"error": "No tracks found in album"}, 404
|
|
||||||
|
|
||||||
playlist = insert_playlist(name)
|
|
||||||
|
|
||||||
if playlist is None:
|
|
||||||
return {"error": "Playlist could not be created"}, 500
|
|
||||||
|
|
||||||
tracks_to_playlist(playlist.id, trackhashes)
|
|
||||||
PL.update_last_updated(playlist.id)
|
|
||||||
|
|
||||||
return {"playlist_id": playlist.id}, 201
|
|
||||||
|
|
||||||
|
|
||||||
@api.route("/playlist/save-artist", methods=["POST"])
|
|
||||||
def save_artist_as_playlist():
|
|
||||||
data = request.get_json()
|
|
||||||
msg = {"error": "'artisthash' and 'playlist_name' not provided"}, 400
|
|
||||||
|
|
||||||
if data is None:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
artisthash = data.get("artisthash")
|
|
||||||
name = data.get("playlist_name")
|
|
||||||
|
|
||||||
if artisthash is None or name is None:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if playlist_exists(name):
|
|
||||||
return {"error": "Playlist already exists"}, 409
|
|
||||||
|
|
||||||
trackhashes = get_artist_trackhashes(artisthash)
|
|
||||||
if len(trackhashes) == 0:
|
|
||||||
return {"error": "No tracks found in artist"}, 404
|
|
||||||
|
|
||||||
playlist = insert_playlist(name)
|
|
||||||
|
|
||||||
if playlist is None:
|
if playlist is None:
|
||||||
return {"error": "Playlist could not be created"}, 500
|
return {"error": "Playlist could not be created"}, 500
|
||||||
|
|||||||
Reference in New Issue
Block a user