[duetto meika] fix: work after cleantags

This commit is contained in:
odrling 2019-08-09 11:34:28 +02:00
parent 90e33f4bdb
commit e4e8537634

View file

@ -4,6 +4,13 @@ script_name = tr"Duetto Meika"
script_description = tr"The ultimate tool for karaoke duets"
script_author = "amoethyst"
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
function duetto(subs, sel)
styles = {}
@ -20,12 +27,12 @@ function duetto(subs, sel)
current_style = styles[line.style]
-- match every `s:` marker
for style_name in line.text:gmatch("{s:([^}]*)}") do
for style_name in line.text:gmatch("{[^}]*s:([^}\\]*)[^}]*}") do
if style_name ~= current_style.name then
style = styles[style_name]
-- build the tags to use the new style
style_string = "{"
style_string = ""
if current_style.color1 ~= style.color1 then
style_string = style_string .. "\\c" .. style.color1
end
@ -38,14 +45,13 @@ function duetto(subs, sel)
if current_style.color4 ~= style.color4 then
style_string = style_string .. "\\4c" .. style.color4
end
style_string = style_string .. "}"
-- set style
line.text = line.text:gsub("{s:" .. style_name .. "}", style_string, 1)
line.text = replace_style(line, style_name, style_string)
current_style = style
else
-- remove marker to not break everything
line.text = line.text:gsub("{s:" .. style_name .. "}", "", 1)
line.text = replace_style(line, style_name, "")
end
end
subs[i] = line