Add cleanup in MPV class and shorthand command method in MPVControl
This commit is contained in:
parent
694f7aab11
commit
4f7aebd6fb
@ -6,7 +6,7 @@ from . import nyasync
|
||||
mpv_control = mpv.MPVControl()
|
||||
|
||||
async def test():
|
||||
await mpv_control.send_request({"command":["loadfile",'grzegorz/res/logo.jpg']})
|
||||
await mpv_control.loadfile('grzegorz/res/logo.jpg')
|
||||
|
||||
async def entry():
|
||||
await asyncio.gather(
|
||||
|
@ -1,3 +1,4 @@
|
||||
import os
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
@ -32,18 +33,25 @@ class MPV:
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
raise Exception("MPV died before socket connected")
|
||||
|
||||
await asyncio.gather(
|
||||
|
||||
self._future = asyncio.gather(
|
||||
self.ensure_running(),
|
||||
self.process_outgoing(),
|
||||
self.process_incomming(),
|
||||
)
|
||||
await self._future
|
||||
|
||||
def _cleanup(self):
|
||||
if os.path.exists(self._ipc_endpoint):
|
||||
os.remove(self._ipc_endpoint)
|
||||
self._future.cancel()#reduces a lot of errors on exit
|
||||
|
||||
def is_running(self):
|
||||
return self.proc.returncode is None
|
||||
|
||||
async def ensure_running(self):
|
||||
await self.proc.wait()
|
||||
self._cleanup()
|
||||
raise Exception("MPV died unexpectedly")
|
||||
|
||||
async def process_outgoing(self):
|
||||
@ -81,3 +89,8 @@ class MPVControl:
|
||||
# is the safest option.
|
||||
self.mpv.requests.put_nowait(msg)
|
||||
return await self.mpv.responses.get()
|
||||
|
||||
#Shorthand command requests:
|
||||
async def loadfile(self, file):
|
||||
return await self.send_request({"command":["loadfile", file]})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user