Add ability to go to specific position in the playlist

This commit is contained in:
Peder Bergebakken Sundt 2019-03-13 12:10:29 +01:00
parent cced6f8772
commit 37a832290e
2 changed files with 14 additions and 0 deletions

View File

@ -148,6 +148,17 @@ async def playlist_previous(request, mpv_control):
success = await mpv_control.playlist_prev() success = await mpv_control.playlist_prev()
return locals() 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") @bp.delete("/playlist")
@doc.summary("Clears single item or whole 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")}) @doc.consumes({"index": doc.Integer("Index to item in playlist to remove. If unset, the whole playlist is cleared")})

View File

@ -155,6 +155,9 @@ class MPVControl:
async def playlist_prev(self): async def playlist_prev(self):
resp = await self.send_request({"command":["playlist-prev", "weak"]}) resp = await self.send_request({"command":["playlist-prev", "weak"]})
return resp["error"] == "success" 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): async def playlist_clear(self):
resp = await self.send_request({"command":["playlist-clear"]}) resp = await self.send_request({"command":["playlist-clear"]})
return resp["error"] == "success" return resp["error"] == "success"