From e4e85376346a66e53044d0c0593863b4427584cd Mon Sep 17 00:00:00 2001 From: odrling Date: Fri, 9 Aug 2019 11:34:28 +0200 Subject: [PATCH] [duetto meika] fix: work after cleantags --- duetto-meika.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/duetto-meika.lua b/duetto-meika.lua index 6b022db..0d6c610 100644 --- a/duetto-meika.lua +++ b/duetto-meika.lua @@ -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