mpv2oboeru

mpv helpers to create flashcards from movies and TV shows
git clone anongit@rnpnr.xyz:mpv2oboeru.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 591594ea321591cfc841602b1f68ff9ccc8fc310
Parent: 7f5363632ae63d68827b8cac2714ee8c37255778
Author: Ren Tatsumoto
Date:   Sun, 25 Oct 2020 22:38:12 +0300

xdotool gets btfo

Diffstat:
MREADME.md | 7+------
Msubs2srs.lua | 24++++++++++++++----------
2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md @@ -34,11 +34,6 @@ while watching your favorite TV show. <td></td> </tr> <tr> - <td><a href="https://www.archlinux.org/packages/community/x86_64/xdotool/">xdotool</a></td> - <td></td> - <td>To avoid <a href="https://github.com/FooSoft/anki-connect/issues/82/">this</a> bug</td> -</tr> -<tr> <td colspan="2" align="center"><a href="https://www.archlinux.org/packages/core/x86_64/curl/">curl</a></td> <td>Should be installed by default on all platforms</td> </tr> @@ -53,7 +48,7 @@ Install all dependencies at once (on [Arch-based](https://www.parabola.nu/) [distros](https://www.gnu.org/distros/free-distros.en.html)): ``` -$ sudo pacman -Syu mpv anki xdotool curl xclip --needed +$ sudo pacman -Syu mpv anki curl xclip --needed ``` ## Installation diff --git a/subs2srs.lua b/subs2srs.lua @@ -650,18 +650,21 @@ ankiconnect.get_note_fields = function(note_id) end end +ankiconnect.gui_browse = function(query) + ankiconnect.execute { + action = 'guiBrowse', + version = 6, + params = { + query = query + } + } +end + ankiconnect.append_media = function(note_id, note_fields, overwrite) - -- AnkiConnect will fail to update the note if the Anki Browser is open. - -- First, try to close the Anki Browser. + -- AnkiConnect will fail to update the note if it's selected in the Anki Browser. -- https://github.com/FooSoft/anki-connect/issues/82 - subprocess { - 'xdotool', - 'search', - '--name', - [[Browse \([0-9]{1,} cards? shown; [0-9]{1,} selected\)]], - 'key', - 'Escape' - } + -- Switch focus from the current note to avoid it. + ankiconnect.gui_browse("nid:1") -- impossible nid if not overwrite then note_fields = join_media_fields(note_fields, ankiconnect.get_note_fields(note_id)) @@ -683,6 +686,7 @@ ankiconnect.append_media = function(note_id, note_fields, overwrite) if error == nil then notify(string.format("Note #%d updated.", note_id)) + ankiconnect.gui_browse(string.format("nid:%d", note_id)) -- select the updated note in the card browser else notify(string.format("Error: %s.", error), "error", 2) end