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: 9fdadb3ab53a96d70453ef9b906841640ecf8b6e
Parent: 112ab98d42b35eda6ad174bf3e138b855cdd3e4a
Author: Ren Tatsumoto
Date:   Wed, 24 Mar 2021 15:41:43 +0000

Merge pull request #31 from eshrh/sub_tag

allow tag substitution
Diffstat:
M.github/RELEASE/subs2srs.conf | 4++++
Msubs2srs.lua | 19++++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/.github/RELEASE/subs2srs.conf b/.github/RELEASE/subs2srs.conf @@ -15,6 +15,7 @@ image_field=Image # The tag that is added to new notes. # Leave nothing after `=` to disable tagging completely. +# Use %n for the name of the video, %t for timestamp. Spaces separate tags. note_tag=subs2srs #note_tag= @@ -47,6 +48,9 @@ clipboard_trim_enabled=yes # Add media to fields before or after existing data append_media=yes +# Remove text in brackets before substituting %n into tag +tag_nuke_brackets=yes + ################## # Image settings # ################## diff --git a/subs2srs.lua b/subs2srs.lua @@ -57,8 +57,9 @@ local config = { sentence_field = "SentKanji", audio_field = "SentAudio", image_field = "Image", - note_tag = "subs2srs", -- the tag that is added to new notes. change to "" to disable tagging - append_media = true, -- True to append video media after existing data, false to insert media before + note_tag = "subs2srs", -- the tag that is added to new notes. change to "" to disable tagging. %n for video title, %t for timestamp. Spaces separate tags. + tag_nuke_brackets = true, -- delete all text inside brackets before subsituting filename into tag + append_media=true, -- True to append video media after existing data, false to insert media before -- Forvo support use_forvo = "yes", -- 'yes', 'no', 'always' @@ -359,6 +360,17 @@ local function update_sentence(new_data, stored_data) return new_data end +local function substitute_tag(tag) + tag = tag:gsub("%%t", human_readable_time(mp.get_property_number('time-pos'))) + filename = remove_extension(mp.get_property("filename")) + if (config.tag_nuke_brackets) then + filename = remove_text_in_brackets(filename) + end + filename = remove_leading_trailing_spaces(filename):gsub(" ","_") + tag = tag:gsub("%%n", filename) + return tag +end + ------------------------------------------------------------ -- utility classes @@ -1019,7 +1031,7 @@ end ankiconnect.add_note = function(note_fields, gui) local action = gui and 'guiAddCards' or 'addNote' - local tags = is_empty(config.note_tag) and {} or { config.note_tag } + local tags = is_empty(config.note_tag) and {} or { substitute_tag(config.note_tag) } local args = { action = action, version = 6, @@ -1099,6 +1111,7 @@ end ankiconnect.add_tag = function(note_id, tag) if not is_empty(tag) then + tag = substitute_tag(tag) ankiconnect.execute { action = 'addTags', version = 6,