From 37a832290efeddcd5cd571a23b7b9c4400b71d7a Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Wed, 13 Mar 2019 12:10:29 +0100 Subject: [PATCH] Add ability to go to specific position in the playlist --- grzegorz/api.py | 11 +++++++++++ grzegorz/mpv.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/grzegorz/api.py b/grzegorz/api.py index 1099f3f..8091331 100644 --- a/grzegorz/api.py +++ b/grzegorz/api.py @@ -148,6 +148,17 @@ async def playlist_previous(request, mpv_control): success = await mpv_control.playlist_prev() return locals() +@bp.post("/playlist/goto") +@doc.summary("Go chosen item in the playlist") +@doc.consumes({"index": doc.Integer("The 0 indexed playlist item to go to")}, required=True) +@response_json +async def playlist_goto(request, mpv_control): + if "index" not in request.args: + raise APIError("Missing the required parameter: \"index\"") + success = await mpv_control.playlist_goto( + int(request.args["index"][0])) + return locals() + @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")}) diff --git a/grzegorz/mpv.py b/grzegorz/mpv.py index 3b2c3c4..eb5a56a 100644 --- a/grzegorz/mpv.py +++ b/grzegorz/mpv.py @@ -155,6 +155,9 @@ class MPVControl: async def playlist_prev(self): resp = await self.send_request({"command":["playlist-prev", "weak"]}) return resp["error"] == "success" + async def playlist_goto(self, index): + resp = await self.send_request({"command":["set_property", "playlist-pos", index]}) + return resp["error"] == "success" async def playlist_clear(self): resp = await self.send_request({"command":["playlist-clear"]}) return resp["error"] == "success"