Add support for looping the playlist

This commit is contained in:
Peder Bergebakken Sundt 2019-03-13 11:26:54 +01:00
parent ebc04f3c07
commit cced6f8772
2 changed files with 24 additions and 0 deletions

View File

@ -188,3 +188,21 @@ async def playlist_move(request, mpv_control):
async def playlist_shuffle(request, mpv_control): async def playlist_shuffle(request, mpv_control):
success = await mpv_control.playlist_shuffle() success = await mpv_control.playlist_shuffle()
return locals() 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()

View File

@ -167,3 +167,9 @@ class MPVControl:
async def playlist_shuffle(self): async def playlist_shuffle(self):
resp = await self.send_request({"command":["playlist-shuffle"]}) resp = await self.send_request({"command":["playlist-shuffle"]})
return resp["error"] == "success" 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"