From 150965d61e73979d78a7f55e341b01cbd61df4c7 Mon Sep 17 00:00:00 2001 From: odrling Date: Thu, 16 Apr 2020 22:16:03 +0200 Subject: [PATCH] add clean k tags macro removes useless k tags in karaoke lines --- clean-k-tags.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 clean-k-tags.lua diff --git a/clean-k-tags.lua b/clean-k-tags.lua new file mode 100644 index 0000000..1112713 --- /dev/null +++ b/clean-k-tags.lua @@ -0,0 +1,22 @@ +local tr = aegisub.gettext + +script_name = tr"Clean k tags" +script_description = tr"Remove double k tags" +script_author = "amoethyst" +script_version = "1.0" + +function special_k(subs, sel) + + -- if the first tag is K/kf this would break the timing for the previous timing + local expr = "^(.-){\\(ko?)(%d*)[^}]-}([^{]-){\\[kK][fo]?(%d*)[^}]-}( -{(\\[kK][fo]?)%d*[^}]-}.*)$" + + for _, i in ipairs(sel) do + line = subs[i] + before, tag, k1, between, k2, after = line.text:match(expr) + line.text = before .. "{\\" .. tag .. tonumber(k1) + tonumber(k2) .. "}" .. between .. after + subs[i] = line + end + +end + +aegisub.register_macro(script_name, script_description, special_k)