From bb661a4b7d487664a906ae9d3fcfe7652d007b10 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 30 Sep 2017 17:24:34 +1000 Subject: [PATCH] mpv.py fixes - enable input keys for video seeking - output debug info to stdout so it's not caught by anki's error handler - before sending a command, check the process is still alive, and restart if necessary - otherwise a user who closes a video window will end up with errors --- anki/mpv.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/anki/mpv.py b/anki/mpv.py index 8d88fa46c..9d25f56a8 100644 --- a/anki/mpv.py +++ b/anki/mpv.py @@ -64,7 +64,6 @@ class MPVBase: default_argv = [ "--idle", - "--no-input-default-bindings", "--no-terminal" ] @@ -193,7 +192,7 @@ class MPVBase: buf = buf[newline + 1:] if self.debug: - sys.stderr.write("<<< " + data.decode("utf8", "replace")) + sys.stdout.write("<<< " + data.decode("utf8", "replace")) message = self._parse_message(data) self._handle_message(message) @@ -245,7 +244,7 @@ class MPVBase: data = self._compose_message(message) if self.debug: - sys.stderr.write(">>> " + data.decode("utf8", "replace")) + sys.stdout.write(">>> " + data.decode("utf8", "replace")) # Request/response cycles are coordinated across different threads, so # that they don't get mixed up. This makes it possible to use commands @@ -299,6 +298,7 @@ class MPVBase: def _send_request(self, message, timeout=None): """Send a command to the mpv process and collect the result. """ + self.ensure_running() self._send_message(message, timeout) try: return self._get_response(timeout) @@ -313,6 +313,18 @@ class MPVBase: """ return self._proc.poll() is None + def ensure_running(self): + if not self.is_running(): + self._stop_thread() + self._stop_process() + self._stop_socket() + self._prepare_socket() + self._prepare_process() + self._start_process() + self._start_socket() + self._prepare_thread() + self._start_thread() + def close(self): """Shutdown the mpv process and our communication setup. """