diff --git a/grzegorz/api.py b/grzegorz/api.py index dbb5840..1099f3f 100644 --- a/grzegorz/api.py +++ b/grzegorz/api.py @@ -188,3 +188,21 @@ async def playlist_move(request, mpv_control): async def playlist_shuffle(request, mpv_control): success = await mpv_control.playlist_shuffle() return locals() + +@bp.get("/playlist/loop") +@doc.summary("See whether it loops the playlist or not") +@response_json +async def playlist_get_looping(request, mpv_control): + value = await mpv_control.playlist_get_looping() + return locals() + +@bp.post("/playlist/loop") +@doc.summary("Sets whether to loop the playlist or not") +@doc.consumes({"loop": doc.Boolean("Whether to be looping or not")}, required=True) +@response_json +async def playlist_set_looping(request, mpv_control): + if "loop" not in request.args: + raise APIError("Missing the required parameter: \"loop\"") + success = await mpv_control.playlist_set_looping( + request.args["loop"][0].lower() in ("1", "true", "on", "inf")) + return locals() diff --git a/grzegorz/mpv.py b/grzegorz/mpv.py index 7bc6f30..3b2c3c4 100644 --- a/grzegorz/mpv.py +++ b/grzegorz/mpv.py @@ -167,3 +167,9 @@ class MPVControl: async def playlist_shuffle(self): resp = await self.send_request({"command":["playlist-shuffle"]}) return resp["error"] == "success" + async def playlist_get_looping(self): + resp = await self.send_request({"command":["get_property", "loop-playlist"]}) + return resp["data"] == "inf" if "data" in resp else False + async def playlist_set_looping(self, value): + resp = await self.send_request({"command":["set_property", "loop-playlist", "inf" if value else "no"]}) + return resp["error"] == "success"