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: 18e060e84db362b1291e0f5f0d2d71970c09e17d
Parent: 63671cbd72cb136b62f6cabdc71acc761637f8d0
Author: Ren Tatsumoto
Date:   Mon,  7 Sep 2020 01:55:09 +0300

a function to append media to an existing note

Diffstat:
Msubs2srs.lua | 41+++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)

diff --git a/subs2srs.lua b/subs2srs.lua @@ -474,6 +474,47 @@ ankiconnect.last_note_id = function() end end +ankiconnect.append_media = function(note_id, audio_filename, snapshot_filename) + -- Ankiconnet will fail to update the note if the Anki Browser is open. + -- First, try to close the Anki Browser. + -- https://github.com/FooSoft/anki-connect/issues/82 + mp.commandv("run", + "xdotool", + "search", + "--name", + "Browse \\([0-9]{1,} cards shown; [0-9]{1,} selected\\)", + "key", + "Escape") + + local args = { + action = "updateNoteFields", + version = 6, + params = { + note = { + id = note_id, + fields = { + [config.audio_field] = string.format('[sound:%s]', audio_filename), + [config.image_field] = string.format('<img src="%s" alt="snapshot">', snapshot_filename), + }, + } + } + } + + local ret = ankiconnect.execute(args) + local _, error = ankiconnect.parse_result(ret) + local message = '' + + if error == nil then + message = string.format("Note #%d updated.", note_id) + print(message) + mp.osd_message(message, 1) + else + message = string.format("Error: %s.", error) + msg.error(message) + mp.osd_message(message, 2) + end +end + ------------------------------------------------------------ -- subtitles and timings