From 48d46762b9fbca73b68a7cfd6bac9e10f212a659 Mon Sep 17 00:00:00 2001 From: odrling Date: Tue, 13 Aug 2019 22:40:46 +0200 Subject: [PATCH] [mugenizer] don't add template line if it's already there This way you can just run the script then the templater to reset the playback resolution to 0x0 --- karaoke-adjust-1sec.lua | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/karaoke-adjust-1sec.lua b/karaoke-adjust-1sec.lua index b9280e6..cd98d18 100644 --- a/karaoke-adjust-1sec.lua +++ b/karaoke-adjust-1sec.lua @@ -11,6 +11,9 @@ leadinmsec = 1000 --lead in time can be changed here ktag = "\\[kK][fo]?%d+" --pattern used to detect karaoke tags +-- KM template line definition +km_template_effect = "template pre-line all keeptags" +km_templayte_text = '!retime("line",$start < 900 and -$start or -900,200)!{!$start < 900 and "\\\\k" .. ($start/10) or "\\\\k90"!\\fad(!$start < 900 and $start or 300!,200)}' function hasleadin(line)--check if there is an existing lead in (2 consecutive bracket with karaoke tags at the start of the line) return line.text:find("^{[^{}]-" .. ktag .. "[^{}]-}%s*{[^{}]-" .. ktag .. "[^{}]-}") @@ -82,11 +85,19 @@ function remove_tag(line, tag) end +function is_template_line(line) + return (line.class == "dialogue" + and line.effect == km_template_effect + and line.text == km_templayte_text) +end + + function mugenizer(subs) local first = nil local styles_different = false local styles = 0 local i_styles = {} + local template_present = false for i, line in ipairs(subs) do if line.class == "info" then @@ -111,6 +122,11 @@ function mugenizer(subs) styles = styles + 1 end + if is_template_line(line) then + line.comment = true + template_present = true + end + if line.class == "dialogue" and not line.comment then if first == nil then first = i @@ -140,14 +156,16 @@ function mugenizer(subs) end end - -- add mugen's magic line - line = subs[first] - line.comment = true - line.start_time = 0 - line.end_time = 0 - line.effect = "template pre-line all keeptags" - line.text = '!retime("line",$start < 900 and -$start or -900,200)!{!$start < 900 and "\\\\k" .. ($start/10) or "\\\\k90"!\\fad(!$start < 900 and $start or 300!,200)}' - subs.insert(first, line) + if not template_present then + -- add mugen's magic line + line = subs[first] + line.comment = true + line.start_time = 0 + line.end_time = 0 + line.effect = km_template_effect + line.text = km_templayte_text + subs.insert(first, line) + end end aegisub.register_macro(script_name, script_description, adjust_1sec)