From 0b64705fdb2d0de85a62987641c5825f40b6427a Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 4 Mar 2018 14:35:12 +0100 Subject: [PATCH] Implement api.playlist_remove_or_clear It handles both mpv_control.playlist_remove and mpv_control.playlist_clear --- grzegorz/api.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/grzegorz/api.py b/grzegorz/api.py index 3f00172..b1e8b50 100644 --- a/grzegorz/api.py +++ b/grzegorz/api.py @@ -138,7 +138,7 @@ async def playlist_get(request, mpv_control): v["index"] = i if "current" in v and v["current"] == True: v["playing"] = await mpv_control.pause_get() == False - del i, v + if value: del i, v return locals() @bp.post("/playlist/next") @@ -155,16 +155,17 @@ async def playlist_previous(request, mpv_control): success = await mpv_control.playlist_prev() return locals() -#@bp.get("/something") +@bp.delete("/playlist") +@doc.summary("Clears single item or whole playlist") +@doc.consumes({"index": doc.Integer("Index to item in playlist to remove. If unset, the whole playlist is cleared")}) @response_json -async def noe(request, mpv_control): - value = await mpv_control.playlist_clear() - return locals() - -#@bp.get("/something") -@response_json -async def noe(request, mpv_control): - value = await mpv_control.playlist_remove(index=None) +async def playlist_remove_or_clear(request, mpv_control): + if "index" in request.args: + success = await mpv_control.playlist_remove(int(request.args["index"][0])) + action = f"remove #{request.args['index'][0]}" + else: + success = await mpv_control.playlist_clear() + action = "clear all" return locals() #@bp.get("/something")