add clean k tags macro

removes useless k tags in karaoke lines
This commit is contained in:
odrling 2020-04-16 22:16:03 +02:00
parent 80fee5f4a3
commit 150965d61e

22
clean-k-tags.lua Normal file
View file

@ -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)