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: ea670588efbbe2cefdbc993f0a025aeb63cca741
Parent: dfa6ad6cc46ec0b3e8543405fabf07af9b2733d9
Author: Ren Tatsumoto
Date:   Wed,  3 Nov 2021 16:59:07 +0000

Merge pull request #56 from cyphar/modify-card-without-subs

update_last_note: allow updates without subtitle text if times are set
Diffstat:
Msubs2srs.lua | 11++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/subs2srs.lua b/subs2srs.lua @@ -472,6 +472,10 @@ local function update_sentence(new_data, stored_data) if is_empty(stored_data[config.sentence_field]) then -- sentence field is empty. can't continue. return new_data + elseif is_empty(new_data[config.sentence_field]) then + -- *new* sentence field is empty, but old one contains data. don't delete the existing sentence. + new_data[config.sentence_field] = stored_data[config.sentence_field] + return new_data end local _, opentag, target, closetag, _ = stored_data[config.sentence_field]:match('^(.-)(<[^>]+>)(.-)(</[^>]+>)(.-)$') @@ -679,9 +683,14 @@ local function update_last_note(overwrite) local sub = subs.get() local last_note_id = ankiconnect.get_last_note_id() - if sub == nil or is_empty(sub['text']) then + if sub == nil then notify("Nothing to export. Have you set the timings?", "warn", 2) return + elseif is_empty(sub['text']) then + -- In this case, don't modify whatever existing text there is and just + -- modify the other fields we can. The user might be trying to add + -- audio to a card which they've manually transcribed. + sub['text'] = nil end if last_note_id < minutes_ago(10) then