From 610f9eb23624834e3dfeb2fd37014626efc38efe Mon Sep 17 00:00:00 2001 From: kelciour Date: Fri, 26 Jun 2020 20:36:58 +0300 Subject: [PATCH] Replace default mpv quit keybindings if mpv version is >= 0.30 https://github.com/mpv-player/mpv/commit/4614d432a8d21ab135af25a183f57efd5059bb62 --- qt/aqt/mpv.py | 4 ++++ qt/aqt/sound.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/qt/aqt/mpv.py b/qt/aqt/mpv.py index eab2e4514..c5b8a1e29 100644 --- a/qt/aqt/mpv.py +++ b/qt/aqt/mpv.py @@ -448,6 +448,10 @@ class MPV(MPVBase): if not inspect.ismethod(method): continue + # Bypass MPVError: no such event 'init' + if method_name == "on_init": + continue + if method_name.startswith("on_property_"): name = method_name[12:] name = name.replace("_", "-") diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index 5c8634308..dca5b0c1e 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -19,7 +19,7 @@ from anki.lang import _ from anki.sound import AV_REF_RE, AVTag, SoundOrVideoTag from anki.utils import isLin, isMac, isWin from aqt import gui_hooks -from aqt.mpv import MPV, MPVBase +from aqt.mpv import MPV, MPVBase, MPVCommandError from aqt.qt import * from aqt.taskman import TaskManager from aqt.utils import restoreGeom, saveGeom, showWarning, startup_info @@ -334,6 +334,16 @@ class MpvManager(MPV, SoundOrVideoPlayer): self.default_argv += ["--config-dir=" + base_path] super().__init__(window_id=None, debug=False) + def on_init(self) -> None: + try: + self.command("keybind", "q", "stop") + self.command("keybind", "Q", "stop") + self.command("keybind", "CLOSE_WIN", "stop") + self.command("keybind", "ctrl+w", "stop") + self.command("keybind", "ctrl+c", "stop") + except MPVCommandError: + print("mpv too old") + def play(self, tag: AVTag, on_done: OnDoneCallback) -> None: assert isinstance(tag, SoundOrVideoTag) self._on_done = on_done