Commit: 3209db20e81b91c683f07b7504a28dabe8946b66
Parent: 90cad36e4bf14d6d75f394854544ce509f8f279c
Author: Ren Tatsumoto
Date: Thu, 17 Dec 2020 14:42:42 +0300
Fixes #15
Diffstat:
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -347,11 +347,13 @@ local function update_last_note(overwrite)
local snapshot_filename, audio_filename = construct_media_filenames(sub)
local snapshot_timestamp = (sub['start'] + sub['end']) / 2
- encoder.create_snapshot(snapshot_timestamp, snapshot_filename)
- encoder.create_audio(sub['start'], sub['end'], audio_filename)
+ local create_media = function()
+ encoder.create_snapshot(snapshot_timestamp, snapshot_filename)
+ encoder.create_audio(sub['start'], sub['end'], audio_filename)
+ end
local note_fields = construct_note_fields(sub['text'], snapshot_filename, audio_filename)
- ankiconnect.append_media(last_note_id, note_fields, overwrite)
+ ankiconnect.append_media(last_note_id, note_fields, overwrite, create_media)
subs.clear()
end
@@ -882,7 +884,7 @@ ankiconnect.gui_browse = function(query)
}
end
-ankiconnect.append_media = function(note_id, appended_data, overwrite)
+ankiconnect.append_media = function(note_id, appended_data, overwrite, create_media_fn)
-- AnkiConnect will fail to update the note if it's selected in the Anki Browser.
-- https://github.com/FooSoft/anki-connect/issues/82
-- Switch focus from the current note to avoid it.
@@ -910,8 +912,9 @@ ankiconnect.append_media = function(note_id, appended_data, overwrite)
local result_notify = function(_, result, _)
local _, error = ankiconnect.parse_result(result)
if not error then
- notify(string.format("Note #%s updated.", note_id))
+ create_media_fn()
ankiconnect.gui_browse(string.format("nid:%s", note_id)) -- select the updated note in the card browser
+ notify(string.format("Note #%s updated.", note_id))
else
notify(string.format("Error: %s.", error), "error", 2)
end