2019-08-02 20:14:28 +00:00
|
|
|
local tr = aegisub.gettext
|
|
|
|
|
2019-08-02 20:45:47 +00:00
|
|
|
script_name = tr"Duetto Meika"
|
|
|
|
script_description = tr"The ultimate tool for karaoke duets"
|
2019-08-02 20:14:28 +00:00
|
|
|
script_author = "amoethyst"
|
|
|
|
|
2019-08-09 09:34:28 +00:00
|
|
|
|
|
|
|
function replace_style(line, style_name, style_string)
|
|
|
|
before_style, after_style = line.text:match("^(.-{[^}]-)\\?s:".. style_name .."(.*)$")
|
|
|
|
return before_style .. style_string .. after_style
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-08-02 20:14:28 +00:00
|
|
|
function duetto(subs, sel)
|
|
|
|
styles = {}
|
|
|
|
|
|
|
|
-- create the style map
|
|
|
|
for _, line in ipairs(subs) do
|
|
|
|
if line.class == "style" then
|
|
|
|
styles[line.name] = line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- duetto~
|
|
|
|
for _, i in ipairs(sel) do
|
|
|
|
line = subs[i]
|
|
|
|
|
|
|
|
current_style = styles[line.style]
|
|
|
|
-- match every `s:` marker
|
2019-08-09 09:34:28 +00:00
|
|
|
for style_name in line.text:gmatch("{[^}]*s:([^}\\]*)[^}]*}") do
|
2019-08-02 20:14:28 +00:00
|
|
|
if style_name ~= current_style.name then
|
|
|
|
|
|
|
|
style = styles[style_name]
|
|
|
|
-- build the tags to use the new style
|
2019-08-09 09:34:28 +00:00
|
|
|
style_string = ""
|
2019-08-02 20:14:28 +00:00
|
|
|
if current_style.color1 ~= style.color1 then
|
|
|
|
style_string = style_string .. "\\c" .. style.color1
|
|
|
|
end
|
|
|
|
if current_style.color2 ~= style.color2 then
|
|
|
|
style_string = style_string .. "\\2c" .. style.color2
|
|
|
|
end
|
|
|
|
if current_style.color3 ~= style.color3 then
|
|
|
|
style_string = style_string .. "\\3c" .. style.color3
|
|
|
|
end
|
|
|
|
if current_style.color4 ~= style.color4 then
|
|
|
|
style_string = style_string .. "\\4c" .. style.color4
|
|
|
|
end
|
|
|
|
|
|
|
|
-- set style
|
2019-08-09 09:34:28 +00:00
|
|
|
line.text = replace_style(line, style_name, style_string)
|
2019-08-02 20:14:28 +00:00
|
|
|
current_style = style
|
|
|
|
else
|
|
|
|
-- remove marker to not break everything
|
2019-08-09 09:34:28 +00:00
|
|
|
line.text = replace_style(line, style_name, "")
|
2019-08-02 20:14:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
subs[i] = line
|
|
|
|
end
|
|
|
|
|
|
|
|
aegisub.set_undo_point(script_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
aegisub.register_macro(script_name, script_description, duetto)
|