clean_k_tags: log/keep going on error

This commit is contained in:
odrling 2021-07-05 02:04:28 +02:00
parent 026734c423
commit 470752574a
No known key found for this signature in database
GPG Key ID: A56620C3E2B7EB46
1 changed files with 30 additions and 17 deletions

View File

@ -5,26 +5,39 @@ script_description = tr"Remove double k tags"
script_author = "amoethyst"
script_version = "1.0"
local double_k = "^(.-{\\k[^}]-)(\\k.+)$"
-- if the first tag is K/kf this would break the timing for the previous timing
local expr = "^(.-){\\(ko?)([0-9.]+)[^}]-}([^{]-){\\[kK][fo]?([0-9.]+)[^}]-}( -{(\\[kK][fo]?)[0-9.]+[^}]-}.*)$"
function _special_k(subs, i)
line = subs[i]
before, after = line.text:match(double_k)
while after ~= nil do
line.text = before .. "}{" .. after
before, after = line.text:match(double_k)
end
before, tag, k1, between, k2, after = line.text:match(expr)
while after ~= nil do
line.text = before .. "{\\" .. tag .. tonumber(k1) + tonumber(k2) .. "}" .. between .. after
before, tag, k1, between, k2, after = line.text:match(expr)
end
return line
end
function special_k(subs, sel)
local double_k = "^(.-{\\k[^}]-)(\\k.+)$"
-- if the first tag is K/kf this would break the timing for the previous timing
local expr = "^(.-){\\(ko?)([0-9.]+)[^}]-}([^{]-){\\[kK][fo]?([0-9.]+)[^}]-}( -{(\\[kK][fo]?)[0-9.]+[^}]-}.*)$"
for _, i in ipairs(sel) do
line = subs[i]
before, after = line.text:match(double_k)
while after ~= nil do
line.text = before .. "}{" .. after
before, after = line.text:match(double_k)
end
before, tag, k1, between, k2, after = line.text:match(expr)
while after ~= nil do
line.text = before .. "{\\" .. tag .. tonumber(k1) + tonumber(k2) .. "}" .. between .. after
subs[i] = line
before, tag, k1, between, k2, after = line.text:match(expr)
ok, res = pcall(_special_k, subs, i)
if ok then
subs[i] = res
else
aegisub.log("error on line " .. i .. ": " .. line.text .. "\n")
aegisub.log(res .. "\n")
end
end