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: f2bfe60fc16e9872e4a3d252e6c41e578f2bf400
Parent: 2ee5c3b86912100a02baeecbee2c063ded28638c
Author: Aleksa Sarai
Date:   Fri, 11 Mar 2022 17:48:09 +1100

dvd_subtitles: don't overwrite text field with dummy text

Since commit d492c83da114 ("update_last_note: allow updates without
subtitle text if times are set") it has not been necessary to include
dummy text to be able to make cards. However, for image-based subtitles
because we had some dummy text which would overwrite any text the user
might've manually transcribed (which is quite annoying).

However, if there's no existing text in the modified card field we add
some dummy text to clarify the situation. Same goes for when creating a
card directly.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>

Diffstat:
Msubs2srs.lua | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/subs2srs.lua b/subs2srs.lua @@ -698,7 +698,8 @@ local function update_last_note(overwrite) 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. + -- audio to a card which they've manually transcribed (either the video + -- has no subtitles or it has image subtitles). sub['text'] = nil end @@ -730,6 +731,12 @@ local function update_last_note(overwrite) end end + -- If the text is still empty, put some dummy text to let the user know why + -- there's no text in the sentence field. + if is_empty(new_data[config.sentence_field]) then + new_data[config.sentence_field] = string.format("mpvacious wasn't able to grab subtitles (%s)", os.time()) + end + ankiconnect.append_media(last_note_id, new_data, create_media) subs.clear() end @@ -1394,7 +1401,7 @@ function Subtitle:now() local delay = mp.get_property_native("sub-delay") - mp.get_property_native("audio-delay") local text = mp.get_property("sub-text") local this = self:new { - ['text'] = not is_empty(text) and text or "<PGS subtitles>", + ['text'] = text, -- if is_empty then it's dealt with later ['start'] = mp.get_property_number("sub-start"), ['end'] = mp.get_property_number("sub-end"), } @@ -1408,7 +1415,7 @@ function Subtitle:delay(delay) end function Subtitle:valid() - return not is_empty(self['text']) and self['start'] and self['end'] and self['start'] >= 0 and self['end'] > 0 + return self['start'] and self['end'] and self['start'] >= 0 and self['end'] > 0 end Subtitle.__eq = function(lhs, rhs)