[karaoke split] properly split several times
This commit is contained in:
parent
7616e4111a
commit
dccaf94d60
|
@ -1,38 +1,47 @@
|
|||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"Karaoke split line"
|
||||
script_description = tr"split line at marker according to ktags"
|
||||
script_author = "amoethyst"
|
||||
script_version = "1.0"
|
||||
|
||||
function split_line(subs, sel)
|
||||
|
||||
function getduration(line)
|
||||
d = 0
|
||||
|
||||
kduration = "{[^}]-\\[kK][fo]?(%d+)[^}]-}"
|
||||
for match in line:gmatch(kduration) do
|
||||
d = d + tonumber(match)
|
||||
end
|
||||
|
||||
return d * 10
|
||||
end
|
||||
|
||||
for _, i in ipairs(sel) do
|
||||
line1 = subs[i]
|
||||
line2 = subs[i]
|
||||
|
||||
line1.text, line2.text = line1.text:match("(.-){split}(.*)")
|
||||
|
||||
if line1.text ~= nil then
|
||||
line1.end_time = line1.start_time + getduration(line1.text)
|
||||
line2.start_time = line1.end_time
|
||||
end
|
||||
|
||||
subs[i] = line1
|
||||
subs.insert(i+1, line2)
|
||||
end
|
||||
aegisub.set_undo_point(tr"Karaoke split")
|
||||
end
|
||||
|
||||
aegisub.register_macro(script_name, script_description, split_line)
|
||||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"Karaoke split line"
|
||||
script_description = tr"split line at marker according to ktags"
|
||||
script_author = "amoethyst"
|
||||
script_version = "1.0"
|
||||
|
||||
function split_line(subs, sel)
|
||||
|
||||
function getduration(line)
|
||||
d = 0
|
||||
|
||||
kduration = "{[^}]-\\[kK][fo]?(%d+)[^}]-}"
|
||||
for match in line:gmatch(kduration) do
|
||||
d = d + tonumber(match)
|
||||
end
|
||||
|
||||
return d * 10
|
||||
end
|
||||
|
||||
insertions = 0
|
||||
for _, i in ipairs(sel) do
|
||||
i = i + insertions
|
||||
line1 = subs[i]
|
||||
line2 = subs[i]
|
||||
|
||||
line1.text, line2.text = line1.text:match("(.-){split}(.*)")
|
||||
|
||||
while line1.text ~= nil do
|
||||
line1.end_time = line1.start_time + getduration(line1.text)
|
||||
line2.start_time = line1.end_time
|
||||
|
||||
subs[i] = line1
|
||||
i = i + 1
|
||||
insertions = insertions + 1
|
||||
subs.insert(i, line2)
|
||||
line1 = subs[i]
|
||||
|
||||
line1.text, line2.text = line1.text:match("(.-){split}(.*)")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
aegisub.set_undo_point(tr"Karaoke split")
|
||||
end
|
||||
|
||||
aegisub.register_macro(script_name, script_description, split_line)
|
||||
|
|
Loading…
Reference in a new issue