mirror of https://github.com/odrling/Aegisub
[automation] add amoegisub scripts
This commit is contained in:
parent
5ed4838d00
commit
03d5ff6980
|
@ -0,0 +1,177 @@
|
|||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"Duetto Meika"
|
||||
script_description = tr"The ultimate tool for karaoke duets"
|
||||
script_author = "amoethyst"
|
||||
|
||||
include("utils.lua")
|
||||
|
||||
|
||||
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 = {}
|
||||
|
||||
-- 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
|
||||
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 = ""
|
||||
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
|
||||
line.text = replace_style(line, style_name, style_string)
|
||||
current_style = style
|
||||
else
|
||||
-- remove marker to not break everything
|
||||
line.text = replace_style(line, style_name, "")
|
||||
end
|
||||
end
|
||||
subs[i] = line
|
||||
end
|
||||
|
||||
aegisub.set_undo_point(script_name)
|
||||
end
|
||||
|
||||
|
||||
function test_colors(c1, c2)
|
||||
return color_from_style(c1) == color_from_style(c2)
|
||||
end
|
||||
|
||||
|
||||
function get_script_style(style, styles)
|
||||
for key, script_style in pairs(styles) do
|
||||
if (test_colors(style.color1, script_style.color1)
|
||||
and test_colors(style.color2, script_style.color2)
|
||||
and test_colors(style.color3, script_style.color3)
|
||||
and test_colors(style.color4, script_style.color4)
|
||||
and tonumber(style.fontsize) == tonumber(script_style.fontsize)
|
||||
and style.fontname == script_style.fontname) then
|
||||
return script_style
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
function deduetto_meika(subs, sel)
|
||||
local styles = {}
|
||||
local last_style = -1
|
||||
|
||||
-- create the style map
|
||||
for i, line in ipairs(subs) do
|
||||
if line.class == "style" then
|
||||
styles[line.name] = line
|
||||
last_style = i
|
||||
end
|
||||
end
|
||||
|
||||
local new_styles = {}
|
||||
|
||||
for _, i in ipairs(sel) do
|
||||
local line = subs[i]
|
||||
local current_style = table.copy(styles[line.style])
|
||||
|
||||
local search_index = 1
|
||||
while search_index < #line.text do
|
||||
local match_start, match_end = line.text:find("{[^}]*}", search_index)
|
||||
if match_start == nil then
|
||||
break
|
||||
end
|
||||
|
||||
local bracketed = line.text:sub(match_start, match_end)
|
||||
local new_style = false
|
||||
|
||||
-- change style's colors
|
||||
for tag, value in bracketed:gmatch("\\([1-4]?c)([^}\\]*)") do
|
||||
new_style = true
|
||||
if tag == "c" or tag == "1c" then
|
||||
current_style.color1 = value
|
||||
elseif tag == "2c" then
|
||||
current_style.color2 = value
|
||||
elseif tag == "3c" then
|
||||
current_style.color3 = value
|
||||
elseif tag == "4c" then
|
||||
current_style.color4 = value
|
||||
end
|
||||
end
|
||||
|
||||
-- change style's font
|
||||
for tag, value in bracketed:gmatch("\\(f[sn])([^}\\]*)") do
|
||||
new_style = true
|
||||
if tag == "fs" then
|
||||
current_style.fontsize = value
|
||||
elseif tag == "fn" then
|
||||
current_style.fontname = value
|
||||
end
|
||||
end
|
||||
|
||||
if new_style then
|
||||
local script_style = get_script_style(current_style, styles)
|
||||
if script_style == nil then
|
||||
if get_script_style(current_style, new_styles) == nil then
|
||||
new_styles[#new_styles+1] = table.copy(current_style)
|
||||
end
|
||||
else
|
||||
-- remove inline colors
|
||||
bracketed = bracketed:gsub("\\[1-4]?c[^\\}]*", "")
|
||||
bracketed = bracketed:gsub("\\[1-4]?a[^\\}]*", "")
|
||||
-- remove inline fonts
|
||||
bracketed = bracketed:gsub("\\f[sn][^\\}]*", "")
|
||||
|
||||
-- add style marker
|
||||
if line.style ~= script_style.name then
|
||||
bracketed = "{s:" .. script_style.name .. bracketed:sub(2, #bracketed)
|
||||
end
|
||||
line.text = line.text:sub(1, match_start-1) .. bracketed .. line.text:sub(match_end + 1, #line.text)
|
||||
end
|
||||
end
|
||||
|
||||
search_index = match_start + 1
|
||||
end
|
||||
|
||||
subs[i] = line
|
||||
end
|
||||
|
||||
if #new_styles > 0 then
|
||||
for i, new_style in ipairs(new_styles) do
|
||||
new_style.name = "Deduetto style " .. i
|
||||
subs.insert(last_style, new_style)
|
||||
last_style = last_style + 1
|
||||
aegisub.log("Created new style: " .. new_style.name .. "\n")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
aegisub.register_macro(script_name, script_description, duetto)
|
||||
aegisub.register_macro(tr"Deduetto Meika", tr"Create styles from inline color tags", deduetto_meika)
|
|
@ -0,0 +1,172 @@
|
|||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"Karaoke 1sec adjust lead-in"
|
||||
script_description = tr"Adjust karaoke leadin to 1sec"
|
||||
script_author = "Flore"
|
||||
script_version = "1.00"
|
||||
|
||||
include("cleantags.lua")
|
||||
|
||||
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 .. "[^{}]-}")
|
||||
end
|
||||
|
||||
|
||||
function removeleadin(line)
|
||||
if not hasleadin(line) then
|
||||
return line
|
||||
end
|
||||
|
||||
leadin = tonumber( line.text:match("^{[^{}]-\\[kK][fo]?(%d+)[^{}]-}%s*{[^{}]-" .. ktag .. "[^{}]-}") ) --read lead-in value
|
||||
line.text = line.text:gsub("^({[^{}]-)\\[kK][fo]?%d+(.-}%s*{[^{}]-" .. ktag .. ".-})","%1%2") --remove lead in
|
||||
|
||||
line.text = cleantags(line.text) --clean tags
|
||||
|
||||
line.start_time = line.start_time + leadin*10 --adjust start time
|
||||
|
||||
--aegisub.log(line.text)
|
||||
|
||||
return line
|
||||
end
|
||||
|
||||
|
||||
function adjust_1sec(subs, sel)
|
||||
|
||||
for _, i in ipairs(sel) do
|
||||
local line = subs[i]
|
||||
|
||||
line.text = cleantags(line.text)
|
||||
|
||||
if( line.text:find(ktag)) then--don't do anything if there is no ktags in this line
|
||||
|
||||
--start by removing existing lead-in
|
||||
while hasleadin(line) do
|
||||
if aegisub.progress.is_cancelled() then return end
|
||||
line = removeleadin(line)
|
||||
end
|
||||
|
||||
--then add our lead in
|
||||
|
||||
if line.start_time >= leadinmsec then
|
||||
line.text = string.format("{\\k%d}%s",leadinmsec/10, line.text)
|
||||
line.start_time = line.start_time - leadinmsec
|
||||
|
||||
else --if line starts too early to put the needed lead in, make the line start at time 0 and fill with appropriate lead in
|
||||
line.text = string.format("{\\k%d}%s",line.start_time/10, line.text)
|
||||
line.start_time = 0
|
||||
end
|
||||
|
||||
subs[i] = line
|
||||
end
|
||||
end
|
||||
|
||||
aegisub.set_undo_point(tr"1sec adjust lead-in")
|
||||
end
|
||||
|
||||
|
||||
function remove_tag(line, tag)
|
||||
local expr = "^(.-{[^}]*)\\" .. tag .. "[^\\}]*(.*)"
|
||||
while true do
|
||||
before, after = line.text:match(expr)
|
||||
if before == nil then
|
||||
return line
|
||||
else
|
||||
line.text = cleantags(before .. after)
|
||||
end
|
||||
end
|
||||
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
|
||||
if line.key == "PlayResX" or line.key == "PlayResY" then
|
||||
line.value = "0"
|
||||
end
|
||||
end
|
||||
|
||||
if line.class == "style" then
|
||||
line.fontname = "Arial"
|
||||
line.fontsize = "24"
|
||||
line.outline = "1.5"
|
||||
line.margin_l = "15"
|
||||
line.margin_r = "15"
|
||||
line.margin_t = "20"
|
||||
line.margin_b = "20"
|
||||
|
||||
i_styles[styles] = i
|
||||
if styles > 0 then
|
||||
styles_different = styles_different or line.color1 ~= subs[i_styles[styles-1]].color1 or line.color2 ~= subs[i_styles[styles-1]].color2 or line.color3 ~= subs[i_styles[styles-1]].color3 or line.color4 ~= subs[i_styles[styles-1]].color4
|
||||
end
|
||||
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 and line.effect ~= "fx" then
|
||||
if first == nil then
|
||||
first = i
|
||||
end
|
||||
|
||||
line.text = cleantags(line.text)
|
||||
|
||||
while hasleadin(line) do
|
||||
if aegisub.progress.is_cancelled() then return end
|
||||
line = removeleadin(line)
|
||||
end
|
||||
|
||||
line = remove_tag(line, "fad")
|
||||
end
|
||||
|
||||
subs[i] = line
|
||||
end
|
||||
|
||||
if not styles_different then
|
||||
for i = 0, styles-1, 1 do
|
||||
line = subs[i_styles[i]]
|
||||
line.color1 = "&H008AFF"
|
||||
line.color2 = "&HFFFFFF"
|
||||
line.color3 = "&H000000"
|
||||
line.color4 = "&H000000"
|
||||
subs[i_styles[i]] = line
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
aegisub.register_macro(tr"Mugenizer", tr"Mugenize your subs", mugenizer)
|
|
@ -0,0 +1,48 @@
|
|||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"Split karaoke line"
|
||||
script_description = tr"Split line at {split} 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]
|
||||
|
||||
split_expr = "(.-)%s*{split}%s*(.*)"
|
||||
line1.text, line2.text = line1.text:match(split_expr)
|
||||
|
||||
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_expr)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
aegisub.set_undo_point(tr"Karaoke split")
|
||||
end
|
||||
|
||||
aegisub.register_macro(script_name, script_description, split_line)
|
|
@ -0,0 +1,523 @@
|
|||
--[[ "Blur / Layers" creates layers with blur. Supports 2 borders, xbord, ybord, xshad, and yshad. Basic support for transforms and \r.
|
||||
"Blur + Glow" - Same as above but with an extra layer for glow. Set blur amount and alpha for the glow.
|
||||
The "double border" option additionally lets you change the size and colour of the 2nd border.
|
||||
If blur is missing, default blur is added.
|
||||
"Bottom blur" allows you to use different blur for the lowest non-glow layer than for top layer(s).
|
||||
"fix \\1a for layers with border and fade" - Uses \1a&HFF& for the duration of a fade on layers with border.
|
||||
"transition" - for \fad(500,0) with transition 80ms you get \1a&HFF&\t(420,500,\1a&H00&).
|
||||
"only add glow" - will add glow to a line with a border, without messing with the primary / border. (Blur + Glow)
|
||||
"only add 2nd border" - will add 2nd border, without messing with the primary / first border. (Blur / Layers)
|
||||
"Fix fades" - Recalculates those \1a fades mentioned above.
|
||||
Use this when you shift something like an episode title to a new episode and the duration of the sign is different.
|
||||
"Change layer" - raises or lowers layer for all selected lines by the same amount. [This is separate from the other functions.]
|
||||
|
||||
Full manual: http://unanimated.xtreemhost.com/ts/scripts-manuals.htm#blurglow
|
||||
]]
|
||||
|
||||
script_name="Blur and Glow"
|
||||
script_description="Add blur and/or glow to signs"
|
||||
script_author="unanimated"
|
||||
script_url="http://unanimated.xtreemhost.com/ts/blur-and-glow.lua"
|
||||
script_version="2.5"
|
||||
script_namespace="ua.BlurAndGlow"
|
||||
|
||||
local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl")
|
||||
if haveDepCtrl then
|
||||
script_version="2.5.0"
|
||||
depRec=DependencyControl{feed="https://raw.githubusercontent.com/TypesettingTools/unanimated-Aegisub-Scripts/master/DependencyControl.json"}
|
||||
end
|
||||
|
||||
|
||||
function glow(subs,sel)
|
||||
if not res.rep then al=res.alfa bl=res.blur end
|
||||
if res.glowcol then glowc=res.glc:gsub("#(%x%x)(%x%x)(%x%x)","&H%3%2%1&") end
|
||||
if res.autod then if res.clr or res.bsize then res.double=true end end
|
||||
for z=#sel,1,-1 do
|
||||
i=sel[z]
|
||||
progress("Glowing line: "..(#sel-z+1).."/"..#sel)
|
||||
line=subs[i]
|
||||
text=line.text
|
||||
if defaref and line.style=="Default" then sr=defaref
|
||||
elseif lastref and laststyle==line.style then sr=lastref
|
||||
else sr=stylechk(line.style) end
|
||||
lastref=sr laststyle=line.style
|
||||
duration=line.end_time-line.start_time
|
||||
|
||||
-- get colors, border, shadow from style
|
||||
stylinfo(text)
|
||||
text=preprocess(text)
|
||||
line.text=text
|
||||
|
||||
if border~="0" or text:match("\\[xy]bord") then
|
||||
|
||||
-- WITH TWO BORDERS
|
||||
if res.double then
|
||||
|
||||
-- second border
|
||||
line1=line
|
||||
line1.text=text
|
||||
line1.text=borderline2(line1.text)
|
||||
line1.layer=line1.layer+1
|
||||
subs.insert(i+1,line1)
|
||||
|
||||
-- first border
|
||||
line2=line
|
||||
line2.text=text
|
||||
line2.text=borderline(line2.text)
|
||||
if shadow~="0" then line2.text=line2.text:gsub("^({\\[^}]+)}","%1\\shad"..shadow.."}") end
|
||||
if not res.s_mid then line2.text=line2.text:gsub("^({\\[^}]-)}","%1\\4a&HFF&}") end
|
||||
line2.layer=line2.layer+1
|
||||
subs.insert(i+2,line2)
|
||||
|
||||
-- top line
|
||||
line3=line
|
||||
line3.text=text
|
||||
line3.text=topline(line3.text)
|
||||
line3.layer=line3.layer+1
|
||||
subs.insert(i+3,line3)
|
||||
|
||||
-- bottom / glow
|
||||
text=borderline2(text)
|
||||
text=glowlayer(text,"3c","3")
|
||||
if res.botalpha and line.text:match("\\fad%(") then text=botalfa(text) end
|
||||
line.layer=line.layer-3
|
||||
line.text=text
|
||||
sls=3
|
||||
|
||||
else
|
||||
-- WITH ONE BORDER
|
||||
|
||||
-- border
|
||||
line2=line
|
||||
if not res.onlyg then
|
||||
line2.text=text
|
||||
line2.text=borderline(line2.text)
|
||||
end
|
||||
line2.layer=line2.layer+1
|
||||
subs.insert(i+1,line2)
|
||||
|
||||
-- top line
|
||||
line3=line
|
||||
line3.layer=line3.layer+1
|
||||
if not res.onlyg then
|
||||
line3.text=text
|
||||
line3.text=topline(line3.text)
|
||||
subs.insert(i+2,line3)
|
||||
end
|
||||
|
||||
-- bottom / glow
|
||||
text=glowlayer(text,"3c","3")
|
||||
if res.botalpha and line.text:match("\\fad%(") then text=botalfa(text) end
|
||||
line.layer=line.layer-2
|
||||
line.text=text
|
||||
sls=2
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
-- WITHOUT BORDER
|
||||
|
||||
line2=line
|
||||
line2.layer=line2.layer+1
|
||||
subs.insert(i+1,line2)
|
||||
text=glowlayer(text,"c","1")
|
||||
line.layer=line.layer-1
|
||||
line.text=text
|
||||
sls=1
|
||||
|
||||
end
|
||||
subs[i]=line
|
||||
for s=z,#sel do sel[s]=sel[s]+sls end
|
||||
end
|
||||
progress("Blur & Glow: DONE")
|
||||
return sel
|
||||
end
|
||||
|
||||
function layerblur(subs,sel)
|
||||
if res.autod then if res.clr or res.bsize then res.double=true end end
|
||||
for z=#sel,1,-1 do
|
||||
i=sel[z]
|
||||
progress("Blurring line: "..(#sel-z+1).."/"..#sel)
|
||||
line=subs[i]
|
||||
text=line.text
|
||||
if defaref~=nil and line.style=="Default" then sr=defaref
|
||||
elseif lastref~=nil and laststyle==line.style then sr=lastref
|
||||
else sr=stylechk(line.style) end
|
||||
lastref=sr laststyle=line.style
|
||||
duration=line.end_time-line.start_time
|
||||
|
||||
-- get colors, border, shadow from style
|
||||
stylinfo(text)
|
||||
text=preprocess(text)
|
||||
line.text=text
|
||||
|
||||
-- TWO BORDERS
|
||||
if res.double then
|
||||
|
||||
-- first border
|
||||
line2=line
|
||||
if not res.onlyb then
|
||||
line2.text=text
|
||||
line2.text=borderline(line2.text)
|
||||
if not res.s_mid then line2.text=line2.text:gsub("^({\\[^}]-)}","%1\\4a&HFF&}") end
|
||||
end
|
||||
line2.layer=line2.layer+1
|
||||
subs.insert(i+1,line2)
|
||||
|
||||
-- top line
|
||||
line3=line
|
||||
line3.layer=line3.layer+1
|
||||
if not res.onlyb then
|
||||
line3.text=text
|
||||
line3.text=topline(line3.text)
|
||||
subs.insert(i+2,line3)
|
||||
end
|
||||
|
||||
-- second border
|
||||
text=borderline2(text)
|
||||
line.layer=line.layer-2
|
||||
line.text=text
|
||||
sls=2
|
||||
|
||||
-- ONE BORDER
|
||||
else
|
||||
|
||||
-- top line
|
||||
line3=line
|
||||
line3.text=text
|
||||
line3.text=topline(line3.text)
|
||||
line3.layer=line3.layer+1
|
||||
subs.insert(i+1,line3)
|
||||
|
||||
-- bottom line
|
||||
text=borderline(text)
|
||||
line.layer=line.layer-1
|
||||
line.text=text
|
||||
sls=1
|
||||
end
|
||||
|
||||
subs[i]=line
|
||||
for s=z,#sel do sel[s]=sel[s]+sls end
|
||||
end
|
||||
progress("Blur: DONE")
|
||||
end
|
||||
|
||||
function topline(txt)
|
||||
txt=txt
|
||||
:gsub("(\\t%([^%)]*)\\bord[%d%.]+","%1")
|
||||
:gsub("(\\t%([^%)]*)\\shad[%d%.]+","%1")
|
||||
:gsub("\\t%([^\\]*%)","")
|
||||
if not txt:match("^{[^}]-\\bord") then txt=txt:gsub("^{\\","{\\bord0\\") end
|
||||
txt=txt
|
||||
:gsub("\\bord[%d%.]+","\\bord0")
|
||||
:gsub("(\\r[^}]-)}","%1\\bord0}")
|
||||
txt=txt:gsub("(\\[xy]bord)[%d%.]+","") :gsub("\\3c&H%x+&","")
|
||||
if shadow~="0" then txt=txt:gsub("^({\\[^}]+)}","%1\\shad"..shadow.."}") end
|
||||
txt=txt
|
||||
:gsub("^({\\[^}]-)}","%1\\4a&HFF&}")
|
||||
:gsub("(\\r[^}]-)}","%1\\shad"..shadow.."\\4a&HFF&}")
|
||||
:gsub("\\bord[%d%.%-]+([^}]-)(\\bord[%d%.%-]+)","%1%2")
|
||||
:gsub("\\shad[%d%.%-]+([^}]-)(\\shad[%d%.%-]+)","%1%2")
|
||||
if res.s_top then txt=txt:gsub("\\4a&HFF&","") end
|
||||
txt=txt:gsub("{}","")
|
||||
return txt
|
||||
end
|
||||
|
||||
function borderline(txt)
|
||||
txt=txt:gsub("\\c&H%x+&","")
|
||||
-- transform check
|
||||
if txt:match("^{[^}]-\\t%([^%)]-\\3c") then
|
||||
pretrans=text:match("^{(\\[^}]-)\\t")
|
||||
if not pretrans:match("^{[^}]-\\3c") then txt=txt:gsub("^{\\","{\\c"..soutline.."\\") end
|
||||
end
|
||||
if not txt:match("^{[^}]-\\3c&[^}]-}") then
|
||||
txt=txt:gsub("^({\\[^}]+)}","%1\\c"..soutline.."}")
|
||||
:gsub("(\\r[^}]-)}","%1\\c"..routline.."}")
|
||||
end
|
||||
txt=txt:gsub("(\\3c)(&H%x+&)","%1%2\\c%2")
|
||||
:gsub("(\\r[^}]-)}","%1\\c"..routline.."}")
|
||||
:gsub("(\\r[^}]-\\3c)(&H%x+&)([^}]-)}","%1%2\\c%2%3")
|
||||
:gsub("\\c&H%x+&([^}]-)(\\c&H%x+&)",function(a,b) if not a:match("\\t") then return a..b end end)
|
||||
:gsub("{%*?}","")
|
||||
if res.bbl and not res.double then txt=txt:gsub("\\blur[%d%.]+","\\blur"..res.bblur) end
|
||||
if res.botalpha and txt:match("\\fad%(") then txt=botalfa(txt) end
|
||||
return txt
|
||||
end
|
||||
|
||||
function borderline2(txt)
|
||||
outlinetwo=primary
|
||||
if res.clr then col3=res.c3:gsub("#(%x%x)(%x%x)(%x%x)","&H%3%2%1&") outlinetwo=col3 rimary=col3 end
|
||||
bordertwo=border
|
||||
if res.bsize then bordertwo=res.secbord end
|
||||
-- transform check
|
||||
if txt:match("^{[^}]-\\t%([^%)]-\\bord") then
|
||||
pretrans=text:match("^{(\\[^}]-)\\t")
|
||||
if not pretrans:match("^{[^}]-\\bord") then txt=txt:gsub("^{\\","{\\bord"..border.."\\") end
|
||||
end
|
||||
if not txt:match("^{[^}]-\\bord") then txt=txt:gsub("^{\\","{\\bord"..border.."\\") end
|
||||
txt=txt:gsub("(\\r[^\\}]-)([\\}])","%1\\bord"..rbord.."%2")
|
||||
:gsub("(\\r[^\\}]-)\\bord[%d%.%-]+([^}]-)(\\bord[%d%.%-]+)","%1%2%3")
|
||||
:gsub("(\\bord)([%d%.]+)",function(a,b) if res.bsize then brd=bordertwo else brd=b end return a..b+brd end)
|
||||
:gsub("(\\[xy]bord)([%d%.]+)",function(a,b) return a..b+b end)
|
||||
:gsub("\\3c&H%x+&","")
|
||||
:gsub("^({\\[^}]+)}","%1\\3c"..outlinetwo.."}")
|
||||
:gsub("(\\3c)(&H%x+&)","%1"..outlinetwo)
|
||||
if res.clr then txt=txt:gsub("\\c&H%x+&([^}]-)}","\\c"..rimary.."\\3c"..outlinetwo.."%1}")
|
||||
else txt=txt:gsub("(\\c)(&H%x+&)([^}]-)}","%1%2%3\\3c%2}") end
|
||||
txt=txt:gsub("(\\r[^}]+)}","%1\\3c"..rimary.."}")
|
||||
:gsub("\\c&H%x+&([^}]-)(\\c&H%x+&)",function(a,b) if not a:match("\\t") then return a..b end end)
|
||||
:gsub("\\3c&H%x+&([^}]-)(\\3c&H%x+&)",function(a,b) if not a:match("\\t") then return a..b end end)
|
||||
:gsub("{%*?}","")
|
||||
if res.bbl and res.double then txt=txt:gsub("\\blur[%d%.]+","\\blur"..res.bblur) end
|
||||
if res.botalpha and txt:match("\\fad%(") then txt=botalfa(txt) end
|
||||
return txt
|
||||
end
|
||||
|
||||
function glowlayer(txt,kol,alf)
|
||||
txt=txt:gsub("\\alpha&H(%x%x)&",function(a) if a>al then return "\\alpha&H"..a.."&" else return "\\alpha&H"..al.."&" end end)
|
||||
:gsub("\\"..alf.."a&H(%x%x)&",function(a) if a>al then return "\\"..alf.."a&H"..a.."&" else return "\\"..alf.."a&H"..al.."&" end end)
|
||||
:gsub("(\\blur)[%d%.]*([\\}])","%1"..bl.."%2")
|
||||
:gsub("(\\r[^}]-)}","%1\\alpha&H"..al.."&}")
|
||||
if not txt:match("^{[^}]-\\alpha") then txt=txt:gsub("^({\\[^}]-)}","%1\\alpha&H"..al.."&}") end
|
||||
if res.alfa=="00" then txt=txt:gsub("^({\\[^}]-)\\alpha&H00&","%1") end
|
||||
txt=txt:gsub("{%*?}","")
|
||||
if res.glowcol then
|
||||
if txt:match("^{\\[^}]-\\"..kol.."&") then txt=txt:gsub("\\"..kol.."&H%x+&","\\"..kol..glowc)
|
||||
else txt=txt:gsub("\\"..kol.."&H%x+&","\\"..kol..glowc) txt=txt:gsub("^({\\[^}]-)}","%1\\"..kol..glowc.."}")
|
||||
end
|
||||
end
|
||||
return txt
|
||||
end
|
||||
|
||||
function botalfa(txt)
|
||||
fadin,fadout=txt:match("\\fad%((%d+)%,(%d+)")
|
||||
alfadin=res.alphade alfadout=res.alphade
|
||||
if res.alphade=="max" then alfadin=fadin alfadout=fadout end
|
||||
if fadin==nil or fadout==nil then aegisub.log("\n ERROR: Failed to capture fade times from line:\n "..text) end
|
||||
if fadin~="0" then
|
||||
txt=txt:gsub("^({\\[^}]-)}","%1\\1a&HFF&\\t("..fadin-alfadin..","..fadin..",\\1a&H00&)}")
|
||||
end
|
||||
if fadout~="0" then
|
||||
txt=txt:gsub("^({\\[^}]-)}","%1\\t("..duration-fadout..","..duration-fadout+alfadout..",\\1a&HFF&)}")
|
||||
end
|
||||
return txt
|
||||
end
|
||||
|
||||
function stylinfo(text)
|
||||
startags=text:match("^{\\[^}]-}") or ""
|
||||
startags=startags:gsub("\\t%b()","")
|
||||
|
||||
primary=startags:match("^{[^}]-\\c(&H%x+&)") or sr.color1:gsub("H%x%x","H")
|
||||
soutline=sr.color3:gsub("H%x%x","H")
|
||||
outline=startags:match("^{[^}]-\\3c(&H%x+&)") or soutline
|
||||
border=startags:match("^{[^}]-\\bord([%d%.]+)") or tostring(sr.outline)
|
||||
shadow=startags:match("^{[^}]-\\shad([%d%.]+)") or tostring(sr.shadow)
|
||||
|
||||
if text:match("\\r%a") then
|
||||
rstyle=text:match("\\r([^\\}]+)")
|
||||
reref=stylechk(rstyle)
|
||||
rimary=reref.color1:gsub("H%x%x","H")
|
||||
routline=reref.color3:gsub("H%x%x","H")
|
||||
rbord=tostring(reref.outline)
|
||||
else routline=soutline rimary=primary rbord=border
|
||||
end
|
||||
end
|
||||
|
||||
function preprocess(text)
|
||||
if not text:match("^{\\") then text="{\\blur"..bdef.."}"..text -- default blur if no tags
|
||||
text=text:gsub("(\\r[^}]-)}","%1\\blur"..bdef.."}")
|
||||
end
|
||||
if not text:match("\\blur") then text=text:gsub("^{\\","{\\blur"..bdef.."\\") -- default blur if missing in tags
|
||||
text=text:gsub("(\\r[^}]-)}","%1\\blur"..bdef.."}")
|
||||
end
|
||||
if text:match("\\blur") and not text:match("^{[^}]*blur[^}]*}") then -- add blur if missing in first tag block
|
||||
text=text:gsub("^{\\","{\\blur"..bdef.."\\")
|
||||
end
|
||||
if text:match("^{[^}]-\\t[^}]-}") and not text:match("^{[^}]-\\3c[^}]-\\t") then -- \t workaround
|
||||
text=text:gsub("^{\\","{\\3c"..soutline.."\\")
|
||||
end
|
||||
text=text:gsub("\\1c","\\c")
|
||||
return text
|
||||
end
|
||||
|
||||
function fixfade(subs,sel)
|
||||
for z=#sel,1,-1 do
|
||||
i=sel[z]
|
||||
line=subs[i]
|
||||
text=line.text
|
||||
sr=stylechk(line.style)
|
||||
duration=line.end_time-line.start_time
|
||||
border=tostring(sr.outline)
|
||||
bord=text:match("^{[^}]-\\bord([%d%.]+)")
|
||||
if bord then border=bord end
|
||||
|
||||
if border~="0" and line.text:match("\\fad%(") then
|
||||
text=text:gsub("\\1a&H%x+&","") :gsub("\\t%([^\\%(%)]-%)","")
|
||||
text=botalfa(text)
|
||||
end
|
||||
line.text=text
|
||||
subs[i]=line
|
||||
end
|
||||
end
|
||||
|
||||
function layeraise(subs,sel)
|
||||
for z=#sel,1,-1 do
|
||||
i=sel[z]
|
||||
line=subs[i]
|
||||
if line.layer+res["layer"]>=0 then line.layer=line.layer+res["layer"] else t_error("You're dumb. Layers can't go below 0.",1) end
|
||||
subs[i]=line
|
||||
end
|
||||
end
|
||||
|
||||
function styleget(subs)
|
||||
styles={}
|
||||
for i=1,#subs do
|
||||
if subs[i].class=="style" then
|
||||
table.insert(styles,subs[i])
|
||||
end
|
||||
if subs[i].class=="dialogue" then break end
|
||||
end
|
||||
end
|
||||
|
||||
function stylechk(sn)
|
||||
for s=1,#styles do
|
||||
if sn==styles[s].name then
|
||||
sr=styles[s]
|
||||
if styles[s].name=="Default" then defaref=styles[s] end
|
||||
end
|
||||
end
|
||||
if sr==nil then t_error("Style '"..sn.."' doesn't exist.",1) end
|
||||
return sr
|
||||
end
|
||||
|
||||
function saveconfig()
|
||||
bgconf="Blur & Glow config\n\n"
|
||||
for key,val in ipairs(GUI) do
|
||||
if val.class=="floatedit" or val.class=="dropdown" or val.class=="color" then
|
||||
bgconf=bgconf..val.name..":"..res[val.name].."\n"
|
||||
end
|
||||
if val.class=="checkbox" and val.name~="save" then
|
||||
bgconf=bgconf..val.name..":"..tf(res[val.name]).."\n"
|
||||
end
|
||||
end
|
||||
blurkonfig=ADP("?user").."\\blurandglow.conf"
|
||||
file=io.open(blurkonfig,"w")
|
||||
file:write(bgconf)
|
||||
file:close()
|
||||
ADD({{class="label",label="Config saved to:\n"..blurkonfig}},{"OK"},{close='OK'})
|
||||
end
|
||||
|
||||
function loadconfig()
|
||||
blurkonfig=ADP("?user").."\\blurandglow.conf"
|
||||
file=io.open(blurkonfig)
|
||||
if file~=nil then
|
||||
konf=file:read("*all")
|
||||
io.close(file)
|
||||
for key,val in ipairs(GUI) do
|
||||
if val.class=="floatedit" or val.class=="checkbox" or val.class=="dropdown" or val.class=="color" then
|
||||
if konf:match(val.name) then val.value=detf(konf:match(val.name..":(.-)\n")) end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function tf(val)
|
||||
if val==true then ret="true"
|
||||
elseif val==false then ret="false"
|
||||
else ret=val end
|
||||
return ret
|
||||
end
|
||||
|
||||
function detf(txt)
|
||||
if txt=="true" then ret=true
|
||||
elseif txt=="false" then ret=false
|
||||
else ret=txt end
|
||||
return ret
|
||||
end
|
||||
|
||||
function logg(m) m=tf(m) or "nil" aegisub.log("\n "..m) end
|
||||
|
||||
function progress(msg)
|
||||
if aegisub.progress.is_cancelled() then ak() end
|
||||
aegisub.progress.title(msg)
|
||||
end
|
||||
|
||||
function t_error(message,cancel)
|
||||
ADD({{class="label",label=message}},{"OK"},{close='OK'})
|
||||
if cancel then ak() end
|
||||
end
|
||||
|
||||
function blurandglow(subs,sel)
|
||||
ADD=aegisub.dialog.display
|
||||
ADP=aegisub.decode_path
|
||||
ak=aegisub.cancel
|
||||
GUI={
|
||||
--left
|
||||
{x=0,y=0,width=2,class="label",label=" = Blur and Glow version "..script_version.." ="},
|
||||
{x=0,y=1,class="label",label="Glow blur:"},
|
||||
{x=0,y=2,class="label",label="Glow alpha:"},
|
||||
|
||||
{x=1,y=1,width=2,class="floatedit",name="blur",value=3},
|
||||
{x=1,y=2,width=2,class="dropdown",name="alfa",items={"00","20","30","40","50","60","70","80","90","A0","B0","C0","D0","F0"},value="80"},
|
||||
|
||||
{x=0,y=3,class="checkbox",name="glowcol",label="glow c.:",hint="glow colour"},
|
||||
{x=1,y=3,width=2,class="color",name="glc"},
|
||||
|
||||
{x=0,y=4,width=2,class="checkbox",name="s_top",label="keep shadow on top layer"},
|
||||
|
||||
{x=0,y=5,width=5,class="checkbox",name="botalpha",label="fix \\1a for layers with border and fade --> transition:",value=true,
|
||||
hint="uses \\1a&HFF& for bottom layer during fade"},
|
||||
{x=5,y=5,class="dropdown",name="alphade",items={0,45,80,120,160,200,"max"},value=45},
|
||||
{x=6,y=5,width=2,class="label",label="ms"},
|
||||
|
||||
{x=0,y=6,width=4,class="checkbox",name="onlyg",label="only add glow (layers w/ border)"},
|
||||
|
||||
-- right
|
||||
{x=4,y=0,class="checkbox",name="double",label="double border"},
|
||||
{x=5,y=0,width=2,class="checkbox",name="onlyb",label="only add 2nd border"},
|
||||
|
||||
{x=4,y=1,class="checkbox",name="bbl",label="bottom blur:",
|
||||
hint="Blur for bottom layer \n[not the glow layer] \nif different from top layer."},
|
||||
{x=5,y=1,width=2,class="floatedit",name="bblur",value=1},
|
||||
|
||||
{x=4,y=2,class="checkbox",name="bsize",label="2nd b. size:",
|
||||
hint="Size for 2nd border \n[counts from first border out] \nif different from the current border."},
|
||||
{x=5,y=2,width=2,class="floatedit",name="secbord",value=2},
|
||||
|
||||
{x=4,y=3,class="checkbox",name="clr",label="2nd b. colour:",hint="Colour for 2nd border \nif different from primary."},
|
||||
{x=5,y=3,width=2,class="color",name="c3"},
|
||||
|
||||
{x=4,y=4,width=4,class="checkbox",name="s_mid",label="keep shadow on middle layer"},
|
||||
|
||||
{x=4,y=6,class="label",label=" Change layer:"},
|
||||
{x=5,y=6,class="dropdown",name="layer",items={"-5","-4","-3","-2","-1","+1","+2","+3","+4","+5"},value="+1"},
|
||||
|
||||
|
||||
{x=0,y=7,width=2,class="checkbox",name="rep",label="repeat with last settings"},
|
||||
{x=4,y=7,class="checkbox",name="autod",label="auto double",value=true,
|
||||
hint="automatically use double border\nif 2nd colour or 2nd border size is checked"},
|
||||
{x=6,y=6,class="dropdown",name="def",items={"0.3","0.4","0.5","0.6","0.7","0.8","0.9","1"},value="0.6",hint="config: default blur"},
|
||||
{x=5,y=7,width=2,class="checkbox",name="save",label="save configuration"},
|
||||
}
|
||||
loadconfig()
|
||||
buttons={"Blur / Layers","Blur + Glow","Fix fades","Change layer","cancel"}
|
||||
pressed,res=ADD(GUI,buttons,{ok='Blur / Layers',close='cancel'})
|
||||
if pressed=="cancel" then ak() end
|
||||
bdef=res.def
|
||||
if res.onlyg then res.double=false end
|
||||
if res.onlyb then res.double=true end
|
||||
if res.save then saveconfig()
|
||||
else
|
||||
if res.rep then res=lastres end
|
||||
styleget(subs)
|
||||
if pressed=="Blur / Layers" then layerblur(subs,sel) end
|
||||
if pressed=="Blur + Glow" then sel=glow(subs,sel) end
|
||||
if pressed=="Fix fades" then fixfade(subs,sel) end
|
||||
if pressed=="Change layer" then layeraise(subs,sel) end
|
||||
end
|
||||
if res.rep==false then lastres=res end
|
||||
aegisub.set_undo_point(script_name)
|
||||
return sel
|
||||
end
|
||||
|
||||
if haveDepCtrl then depRec:registerMacro(blurandglow) else aegisub.register_macro(script_name,script_description,blurandglow) end
|
|
@ -0,0 +1,148 @@
|
|||
script_name="Change Case"
|
||||
script_description="Capitalises text or makes it lowercase / uppercase"
|
||||
script_author="unanimated"
|
||||
script_version="3.0"
|
||||
script_namespace="ua.ChangeCase"
|
||||
|
||||
local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl")
|
||||
if haveDepCtrl then
|
||||
script_version="3.0.0"
|
||||
depRec=DependencyControl{feed="https://raw.githubusercontent.com/TypesettingTools/unanimated-Aegisub-Scripts/master/DependencyControl.json"}
|
||||
end
|
||||
|
||||
re=require'aegisub.re'
|
||||
unicode=require'aegisub.unicode'
|
||||
|
||||
function case(subs,sel)
|
||||
for z,i in ipairs(sel) do
|
||||
line=subs[i]
|
||||
t=line.text
|
||||
if P=="lowercase" then t=lowercase(t) end
|
||||
if P=="UPPERCASE" then t=uppercase(t) end
|
||||
if P=="Lines" then t=capitalines(t) end
|
||||
if P=="Sentences" then
|
||||
if res.mod then res.mod=false t=lowercase(t) res.mod=true end
|
||||
t=sentences(t)
|
||||
end
|
||||
if P=="Words" then
|
||||
if not res.mod then t=lowercase(t) end
|
||||
t=capitalise(t)
|
||||
end
|
||||
line.text=t
|
||||
subs[i]=line
|
||||
end
|
||||
end
|
||||
|
||||
function lowercase(t)
|
||||
t=t
|
||||
:gsub("\\[Nnh]","{%1}")
|
||||
:gsub("^([^{]*)",function(l)
|
||||
if res.mod then l=re.sub(l,[[\b(\u\u+'?\u*)]],function(u) return ulower(u) end) return l
|
||||
else return ulower(l) end end)
|
||||
:gsub("}([^{]*)",function(l)
|
||||
if res.mod then l=re.sub(l,[[\b(\u\u+'?\u*)]],function(u) return ulower(u) end) return "}"..l
|
||||
else return "}"..ulower(l) end end)
|
||||
:gsub("{(\\[Nnh])}","%1")
|
||||
return t
|
||||
end
|
||||
|
||||
function uppercase(t)
|
||||
t=t
|
||||
:gsub("\\[Nnh]","{%1}")
|
||||
:gsub("^([^{]*)",function(u) return uupper(u) end)
|
||||
:gsub("}([^{]*)",function(u) return "}"..uupper(u) end)
|
||||
:gsub("{(\\[Nnh])}","%1")
|
||||
return t
|
||||
end
|
||||
|
||||
function capitalines(t)
|
||||
t=re.sub(t,[[^(["']?\l)]],function(l) return uupper(l) end)
|
||||
t=re.sub(t,[[^\{[^}]*\}(["']?\l)]],function(l) return uupper(l) end)
|
||||
if not res.mod then
|
||||
t=t:gsub(" i([' %?!%.,])"," I%1"):gsub("\\Ni([' ])","\\NI%1")
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function sentences(t)
|
||||
somewords={"English","Japanese","American","British","German","French","Spanish","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","January","February","April","June","July","August","September","October","November","December"}
|
||||
hnrfx={"%-san","%-kun","%-chan","%-sama","%-dono","%-se[nm]pai","%-on%a+an"}
|
||||
t=re.sub(t,[[^(["']?\l)]],function(l) return uupper(l) end)
|
||||
t=re.sub(t,[[^\{[^}]*\}(["']?\l)]],function(l) return uupper(l) end)
|
||||
t=re.sub(t,[[[\.\?!](\s|\s\\N|\\N)["']?(\l)]],function(l) return uupper(l) end)
|
||||
t=t
|
||||
:gsub(" i([' %?!%.,])"," I%1")
|
||||
:gsub("\\Ni([' ])","\\NI%1")
|
||||
:gsub(" m(arch %d)"," M%1")
|
||||
:gsub(" a(pril %d)"," A%1")
|
||||
for l=1,#somewords do t=t:gsub(somewords[l]:lower(),somewords[l]) end
|
||||
for h=1,#hnrfx do
|
||||
t=t:gsub("([ %p]%l)(%l*"..hnrfx[h]..")",function(h,f) return h:upper()..f end)
|
||||
t=t:gsub("(\\N%l)(%l*"..hnrfx[h]..")",function(h,f) return h:upper()..f end)
|
||||
end
|
||||
t=re.sub(t,"\\b(of|in|from|\\d+st|\\d+nd|\\d+rd|\\d+th) m(arch|ay)\\b","\\1 M\\2")
|
||||
t=re.sub(t,"\\bm(r|rs|s)\\.","M\\1.")
|
||||
t=re.sub(t,"\\bdr\\.","Dr.")
|
||||
return t
|
||||
end
|
||||
|
||||
function capitalise(txt)
|
||||
word={"A","About","Above","Across","After","Against","Along","Among","Amongst","An","And","Around","As","At","Before","Behind","Below","Beneath","Beside","Between","Beyond","But","By","Despite","During","Except","For","From","In","Inside","Into","Near","Nor","Of","On","Onto","Or","Over","Per","Sans","Since","Than","The","Through","Throughout","Till","To","Toward","Towards","Under","Underneath","Unlike","Until","Unto","Upon","Versus","Via","With","Within","Without","According to","Ahead of","Apart from","Aside from","Because of","Inside of","Instead of","Next to","Owing to","Prior to","Rather than","Regardless of","Such as","Thanks to","Up to","and Yet"}
|
||||
onore={"%-San","%-Kun","%-Chan","%-Sama","%-Dono","%-Se[nm]pai","%-On%a+an"}
|
||||
nokom={"^( ?)([^{]*)","(})([^{]*)"}
|
||||
for n=1,2 do
|
||||
txt=txt:gsub(nokom[n],function(no_t,t)
|
||||
t=t:gsub("\\[Nnh]","{%1}")
|
||||
t=re.sub(t,[[\b\l]],function(l) return uupper(l) end)
|
||||
t=re.sub(t,[[[I\l]'(\u)]],function(l) return ulower(l) end)
|
||||
|
||||
for r=1,#word do w=word[r]
|
||||
t=t
|
||||
:gsub("^ "..w.." "," "..w:lower().." ")
|
||||
:gsub("([^%.:%?!]) "..w.." ","%1 "..w:lower().." ")
|
||||
:gsub("([^%.:%?!]) (%b{})"..w.." ","%1 %2"..w:lower().." ")
|
||||
:gsub("([^%.:%?!]) (%*Large_break%* ?)"..w.." ","%1 %2"..w:lower().." ")
|
||||
end
|
||||
|
||||
-- Roman numbers (this may mismatch some legit words - sometimes there just are 2 options and it's a guess)
|
||||
t=t
|
||||
:gsub("$","#")
|
||||
:gsub("(%s?)([IVXLCDM])([ivxlcdm]+)([%s%p#])",function(s,r,m,e) return s..r..m:upper()..e end)
|
||||
:gsub("([DLM])ID","%1id")
|
||||
:gsub("DIM","Dim")
|
||||
:gsub("MIX","Mix")
|
||||
:gsub("Ok([%s%p#])","OK%1")
|
||||
for h=1,#onore do
|
||||
t=t:gsub(onore[h].."([%s%p#])",onore[h]:lower().."%1")
|
||||
end
|
||||
t=t
|
||||
:gsub("#$","")
|
||||
:gsub("{(\\[Nnh])}","%1")
|
||||
return no_t..t end)
|
||||
end
|
||||
return txt
|
||||
end
|
||||
|
||||
ulower=unicode.to_lower_case
|
||||
uupper=unicode.to_upper_case
|
||||
|
||||
function logg(m) m=m or "nil" aegisub.log("\n "..m) end
|
||||
|
||||
function capital(subs,sel)
|
||||
GUI={
|
||||
{x=1,y=0,class="label",label="Words - Capitalise Words Like in Titles"},
|
||||
{x=1,y=1,class="label",label=" Lines - Capitalise first word in selected lines"},
|
||||
{x=1,y=2,class="label",label=" Sentences - Capitalise first word in each sentence"},
|
||||
{x=1,y=3,class="label",label=" Lowercase - make text in selected lines lowercase"},
|
||||
{x=1,y=4,class="label",label=" Uppercase - MAKE TEXT IN SELECTED LINES UPPERCASE"},
|
||||
{x=2,y=5,class="label",label=script_name.." v "..script_version},
|
||||
{x=1,y=5,class="checkbox",name="mod",label="mod",hint="Words - leave uppercase words\nLines - don't capitalize 'i'\nSentences - run lowercase first\nlowercase - only for uppercase words"},
|
||||
}
|
||||
P,res=aegisub.dialog.display(GUI,{"Words","Lines","Sentences","lowercase","UPPERCASE","Cancel"},{ok='Words',close='Cancel'})
|
||||
if P=="Cancel" then aegisub.cancel() end
|
||||
case(subs,sel)
|
||||
aegisub.set_undo_point(script_name)
|
||||
return sel
|
||||
end
|
||||
|
||||
if haveDepCtrl then depRec:registerMacro(capital) else aegisub.register_macro(script_name,script_description,capital) end
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,116 @@
|
|||
-- Manual: http://unanimated.hostfree.pw/ts/scripts-manuals.htm#cycle
|
||||
|
||||
script_name="Cycles"
|
||||
script_description="Cycles blur, border, shadow, alpha, alignment, font spacing"
|
||||
script_author="unanimated"
|
||||
script_version="2.0"
|
||||
script_namespace="ua.Cycles"
|
||||
|
||||
local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl")
|
||||
if haveDepCtrl then
|
||||
script_version="2.0.0"
|
||||
depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"}
|
||||
end
|
||||
|
||||
-- SETTINGS - You can change these sequences
|
||||
blur_sequence={"0.6","0.8","1","1.2","1.5","2","2.5","3","4","5","6","8","10","0.4","0.5"}
|
||||
bord_sequence={"0","1","1.5","2","2.5","3","4","5","6","7","8","9","10","11","12","15","20"}
|
||||
shad_sequence={"0","1","1.5","2","2.5","3","4","5","6","7","8","9","10","11","12"}
|
||||
alpha_sequence={"FF","00","10","30","60","80","A0","C0","E0"}
|
||||
align_sequence={"1","2","3","4","5","6","7","8","9"}
|
||||
fsp_sequence={"0","1","2","3","4","5","6","7","8","10","12","15","20","30"}
|
||||
|
||||
--[[ Adding more tags
|
||||
You could make this also work for the following tags: frz, frx, fry, fax, fay, fs, fscx, fscy, be, xbord, xshad, ybord, yshad
|
||||
by doing 3 things:
|
||||
1. add a new sequence to the settings above for the tag you want to add
|
||||
2. add a function below here based on what the others look like (it's adjusted for negative values too)
|
||||
3. add "aegisub.register_macro("Cycles/YOUR_SCRIPT_NAME","Cycles WHATEVER_YOU_CHOOSE",FUNCTION_NAME_HERE)" at the end of the script
|
||||
If you at least roughly understand the basics, this should be easy. The main cycle function remains the same for all tags.
|
||||
Should you want to add other tags with different value patterns, check the existing exceptions for alpha in the cycle function.]]
|
||||
|
||||
function blur(subs,sel) cycle(subs,sel,"blur",blur_sequence) end
|
||||
function bord(subs,sel) cycle(subs,sel,"bord",bord_sequence) end
|
||||
function shad(subs,sel) cycle(subs,sel,"shad",shad_sequence) end
|
||||
function alph(subs,sel) cycle(subs,sel,"alpha",alpha_sequence) end
|
||||
function algn(subs,sel) cycle(subs,sel,"an",align_sequence) end
|
||||
function fsp(subs,sel) cycle(subs,sel,"fsp",fsp_sequence) end
|
||||
|
||||
function cycle(subs,sel,tag,sequence)
|
||||
if tag=="alpha" then base=16 else base=10 end
|
||||
for z,i in ipairs(sel) do
|
||||
line=subs[i]
|
||||
text=line.text
|
||||
local back
|
||||
if line.comment or text:match'{switch}$' then back=true end
|
||||
text=text:gsub("\\t(%b())",function(t) return "\\t"..t:gsub("\\","|") end)
|
||||
|
||||
if tag=="alpha" then val1=text:match("^{[^}]-\\alpha&H(%x%x)&") else val1=text:match("^{[^}]-\\"..tag.."(%-?[%d%.]+)") end
|
||||
if val1 then
|
||||
for n=1,#sequence do
|
||||
N=n+1
|
||||
if back then N=n-1 end
|
||||
if N==0 then N=#sequence end
|
||||
if val1==sequence[n] then val2=sequence[N] or sequence[1] break end
|
||||
end
|
||||
if val2==nil then
|
||||
for n=1,#sequence do
|
||||
if n>1 or sequence[1]~="FF" then
|
||||
local N=n
|
||||
if back then N=n-1 end
|
||||
if N==0 then N=#sequence end
|
||||
if tonumber(val1,base)<tonumber(sequence[n],base) then val2=sequence[N] break end
|
||||
end
|
||||
end
|
||||
end
|
||||
if val2==nil then if back then val2=sequence[#sequence] else val2=sequence[1] end end
|
||||
if tag=="alpha" then
|
||||
text=text:gsub("^({[^}]-\\alpha&H)%x%x","%1"..val2)
|
||||
else
|
||||
text=text:gsub("^({[^}]-\\"..tag..")%-?[%d%.]+","%1"..val2)
|
||||
end
|
||||
val2=nil
|
||||
else
|
||||
text="{\\"..tag..sequence[1].."}"..text
|
||||
text=text:gsub("alpha(%x%x)}","alpha&H%1&}")
|
||||
:gsub("{(\\.-)}{\\","{%1\\")
|
||||
end
|
||||
|
||||
text=text:gsub("{\\[^}]-}",function(t) return t:gsub("|","\\") end)
|
||||
line.text=text
|
||||
subs[i]=line
|
||||
end
|
||||
end
|
||||
|
||||
function switch(subs,sel)
|
||||
for z,i in ipairs(sel) do
|
||||
l=subs[i]
|
||||
t=l.text
|
||||
t=t.."{switch}"
|
||||
t=t:gsub("{switch}{switch}$","")
|
||||
l.text=t
|
||||
subs[i]=l
|
||||
end
|
||||
end
|
||||
|
||||
function logg(m) m=m or "nil" aegisub.log("\n "..m) end
|
||||
|
||||
if haveDepCtrl then
|
||||
depRec:registerMacros({
|
||||
{"Cycles/Blur Cycle","Cycles Blur",blur},
|
||||
{"Cycles/Border Cycle","Cycles Border",bord},
|
||||
{"Cycles/Shadow Cycle","Cycles Shadow",shad},
|
||||
{"Cycles/Alpha Cycle","Cycles Alpha",alph},
|
||||
{"Cycles/Alignment Cycle","Cycles Alignment",algn},
|
||||
{"Cycles/FontSpacing Cycle","Cycles Font Spacing",fsp},
|
||||
{"Cycles/Switch","Switches sequence direction",switch},
|
||||
},false)
|
||||
else
|
||||
aegisub.register_macro("Cycles/Blur Cycle","Cycles Blur",blur)
|
||||
aegisub.register_macro("Cycles/Border Cycle","Cycles Border",bord)
|
||||
aegisub.register_macro("Cycles/Shadow Cycle","Cycles Shadow",shad)
|
||||
aegisub.register_macro("Cycles/Alpha Cycle","Cycles Alpha",alph)
|
||||
aegisub.register_macro("Cycles/Alignment Cycle","Cycles Alignment",algn)
|
||||
aegisub.register_macro("Cycles/FontSpacing Cycle","Cycles Font Spacing",fsp)
|
||||
aegisub.register_macro("Cycles/Switch","Switches sequence direction",switch)
|
||||
end
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,758 @@
|
|||
-- Disclaimer: RTFM! - http://unanimated.hostfree.pw/ts/scripts-manuals.htm#cleanup
|
||||
|
||||
script_name="Script Cleanup"
|
||||
script_description="Garbage disposal and elimination of incriminating evidence"
|
||||
script_author="unanimated"
|
||||
script_version="5.0"
|
||||
script_namespace="ua.ScriptCleanup"
|
||||
|
||||
local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl")
|
||||
if haveDepCtrl then
|
||||
script_version="5.0.0"
|
||||
depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"}
|
||||
end
|
||||
|
||||
dont_delete_empty_tags=false -- option to not delete {}
|
||||
|
||||
re=require'aegisub.re'
|
||||
|
||||
function cleanlines(subs,sel)
|
||||
if res.all then
|
||||
for k,v in ipairs(GUI) do
|
||||
if v.x==0 then res[v.name]=true end
|
||||
end
|
||||
end
|
||||
for z,i in ipairs(sel) do
|
||||
progress("Processing line: "..z.."/"..#sel)
|
||||
prog=math.floor(z/#sel*100)
|
||||
aegisub.progress.set(prog)
|
||||
line=subs[i]
|
||||
text=line.text
|
||||
stl=line.style
|
||||
|
||||
if res.nots and not res.nocom then text=text:gsub("{TS[^}]*} *","") end
|
||||
|
||||
if res.nocom then
|
||||
text=text:gsub("{[^\\}]-}","")
|
||||
:gsub("{[^\\}]-\\N[^\\}]-}","")
|
||||
:gsub("^({[^}]-}) *","%1")
|
||||
:gsub(" *$","")
|
||||
end
|
||||
|
||||
if res.clear_a then line.actor="" end
|
||||
if res.clear_e then line.effect="" end
|
||||
|
||||
if res.layers and line.layer<5 then
|
||||
if stl:match("Defa") or stl:match("Alt") or stl:match("Main") then line.layer=line.layer+5 end
|
||||
end
|
||||
|
||||
if res.cleantag and text:match("{[*>]?\\") then
|
||||
txt2=text
|
||||
text=text:gsub("{\\\\k0}",""):gsub(">\\","\\"):gsub("{(\\[^}]-)} *\\N *{(\\[^}]-)}","\\N{%1%2}")
|
||||
repeat text,r=text:gsub("{(\\[^}]-)}{(\\[^}]-)}","{%1%2}") until r==0
|
||||
text=text:gsub("({\\[^}]-){(\\[^}]-})","%1%2"):gsub("{.-\\r","{\\r"):gsub("^{\\r([\\}])","{%1")
|
||||
:gsub("\\fad%(0,0%)",""):gsub(ATAG.."$",""):gsub("^({\\[^}]-)\\frx0\\fry0","%1"):gsub("\\%a+%(%)","")
|
||||
text=text:gsub(ATAG,function(tgs)
|
||||
tgs2=tgs
|
||||
:gsub("\\+([\\}])","%1")
|
||||
:gsub("(\\[^\\})]+)",function(a) if not a:match'clip' and not a:match'\\fn' and not a:match'\\r' then a=a:gsub(' ','') end return a end)
|
||||
:gsub("(\\%a+)([%d%-]+%.%d+)",function(a,b) if not a:match("\\fn") then b=rnd2dec(b) end return a..b end)
|
||||
:gsub("(\\%a+)%(([%d%.%-]+),([%d%.%-]+)%)",function(a,b,c) b=rnd2dec(b) c=rnd2dec(c) return a.."("..b..","..c..")" end)
|
||||
:gsub("(\\%a+)%(([%d%.%-]+),([%d%.%-]+),([%d%.%-]+),([%d%.%-]+)",function(a,b,c,d,e)
|
||||
return a.."("..rnd2dec(b)..","..rnd2dec(c)..","..rnd2dec(d)..","..rnd2dec(e) end)
|
||||
tgs2=duplikill(tgs2)
|
||||
tgs2=extrakill(tgs2)
|
||||
return tgs2
|
||||
end)
|
||||
if txt2~=text then kleen=kleen+1 end
|
||||
end
|
||||
|
||||
if res.overlap then
|
||||
if line.comment==false and stl:match("Defa") then
|
||||
start=line.start_time
|
||||
endt=line.end_time
|
||||
if i<#subs then nextline=subs[i+1] nextart=nextline.start_time end
|
||||
prevline=subs[i-1]
|
||||
prevstart=prevline.start_time
|
||||
prevend=prevline.end_time
|
||||
dur=line.end_time-line.start_time
|
||||
ms2fr=aegisub.frame_from_ms
|
||||
fr2ms=aegisub.ms_from_frame
|
||||
keyframes=aegisub.keyframes()
|
||||
startf=ms2fr(start)
|
||||
endf=ms2fr(endt)
|
||||
prevendf=ms2fr(prevend)
|
||||
nextartf=ms2fr(nextart)
|
||||
|
||||
-- start gaps/overlaps
|
||||
if prevline.class=="dialogue" and prevline.style:match("Defa") and dur>50 then
|
||||
-- get keyframes
|
||||
kfst=0 kfprev=0
|
||||
for k,kf in ipairs(keyframes) do
|
||||
if kf==startf then kfst=1 end
|
||||
if kf==prevendf then kfprev=1 end
|
||||
end
|
||||
-- start overlap
|
||||
if start<prevend and prevend-start<=50 then
|
||||
if kfst==0 or kfprev==1 then nstart=prevend end
|
||||
end
|
||||
-- start gap
|
||||
if start>prevend and start-prevend<=50 then
|
||||
if kfst==0 and kfprev==1 then nstart=prevend end
|
||||
end
|
||||
end
|
||||
-- end gaps/overlaps
|
||||
if i<#subs and nextline.style:match("Defa") and dur>50 then
|
||||
--get keyframes
|
||||
kfend=0 kfnext=0
|
||||
for k,kf in ipairs(keyframes) do
|
||||
if kf==endf then kfend=1 end
|
||||
if kf==nextartf then kfnext=1 end
|
||||
end
|
||||
-- end overlap
|
||||
if endt>nextart and endt-nextart<=50 then
|
||||
if kfnext==1 and kfend==0 then nendt=nextart end
|
||||
end
|
||||
-- end gap
|
||||
if endt<nextart and nextart-endt<=50 then
|
||||
if kfend==0 or kfnext==1 then nendt=nextart end
|
||||
end
|
||||
end
|
||||
end
|
||||
if nstart then line.start_time=nstart end
|
||||
if nendt then line.end_time=nendt end
|
||||
nstart=nil nendt=nil
|
||||
end
|
||||
|
||||
if res.spaces then text=text:gsub(" +"," ") :gsub(" *$","") :gsub("^({\\[^}]-}) *","%1") end
|
||||
|
||||
if res.nobreak2 then text=text:gsub("\\[Nn]","")
|
||||
elseif res.nobreak then
|
||||
text=text
|
||||
:gsub(" *{\\i0}\\N{\\i1} *"," ")
|
||||
:gsub("%*","_ast_")
|
||||
:gsub("\\[Nn]","*")
|
||||
:gsub(" *%*+ *"," ")
|
||||
:gsub("_ast_","*")
|
||||
end
|
||||
|
||||
if res.hspace then text=text:gsub("\\h","") end
|
||||
if res.notag then text=text:gsub(ATAG,"") end
|
||||
if res.allcol then text=text:gsub("\\[1234]?c[^\\})]*","") end
|
||||
if res.alpha14 then text=text:gsub("\\[1234]a[^\\})]*","")
|
||||
elseif res.allphas then text=text:gsub("\\[1234]a[^\\})]*","") :gsub("\\alpha[^\\})]*","") end
|
||||
if res.xyshad then text=text:gsub("\\[xy]shad[^\\})]*","")
|
||||
elseif res.allshad then text=text:gsub("\\[xy]?shad[^\\})]*","") end
|
||||
if res.xyrot then text=text:gsub("\\fr[xy][^\\})]*","")
|
||||
elseif res.allrot then text=text:gsub("\\fr[^\\})]*","") end
|
||||
if res.allpers then text=text:gsub("\\f[ar][xyz][^\\})]*","") :gsub("\\org%b()","") end
|
||||
if res.scales then text=text:gsub("\\fsc[xy][^\\})]*","")
|
||||
elseif res.allsize then text=text:gsub("\\fs[%d.]+","") :gsub("\\fs([\\}%)])","%1") :gsub("\\fsc[xy][^\\})]*","") end
|
||||
if res.parent2 then text=text:gsub("(\\%a%a+)(%b())",function(a,b) if a=='\\pos' then return a..b else return "" end end)
|
||||
elseif res.parent then text=text:gsub("\\%a%a+%b()","") end
|
||||
if res.ctrans then text=text:gsub(ATAG,function(tg) return cleantr(tg) end) end
|
||||
if res.inline2 then repeat text,r=text:gsub("(.)"..ATAG.."(.-{%*?\\)","%1%2") until r==0
|
||||
elseif res.inline then text=text:gsub("(.)"..ATAG,"%1") end
|
||||
|
||||
if res.alphacol then
|
||||
text=text
|
||||
:gsub("alpha&(%x%x)&","alpha&H%1&")
|
||||
:gsub("alpha&?H?(%x%x)&?([\\}])","alpha&H%1&%2")
|
||||
:gsub("alpha&H0&","alpha&H00&")
|
||||
:gsub("alpha&H(%x%x)%x*&","alpha&H%1&")
|
||||
:gsub("(\\[1234]a)&(%x%x)&","%1&H%2&")
|
||||
:gsub("(\\[1234]a)(%x%x)([\\}])","%1&H%2&%3")
|
||||
:gsub("(\\[1234]?c&)(%x%x%x%x%x%x)&","%1H%2&")
|
||||
:gsub("(\\[1234]?c&H%x%x%x%x%x%x)([^&])","%1&%2")
|
||||
:gsub("(\\i?clip%([^%)]-) ?([\\}])","%1)%2")
|
||||
:gsub("(\\t%([^%)]-\\i?clip%([^%)]-%))([\\}])","%1)%2")
|
||||
:gsub("(fad%([%d,]+)([\\}])","%1)%2")
|
||||
:gsub("([1234]?[ac])H&(%x+)","%1&H%2")
|
||||
:gsub("([1234]?c&H)00(%x%x%x%x%x%x)","%1%2")
|
||||
end
|
||||
|
||||
text=text:gsub("^ *","") :gsub("\\t%([^\\%)]-%)","") :gsub("{%*}","")
|
||||
if not dont_delete_empty_tags then text=text:gsub("{}","") end
|
||||
if line.text~=text then chng=chng+1 end
|
||||
line.text=text
|
||||
subs[i]=line
|
||||
end
|
||||
if res.info then
|
||||
infotxt="Lines with modified Text field: "..chng
|
||||
if res.cleantag then infotxt=infotxt.."\nChanges from Clean Tags: "..kleen end
|
||||
P,rez=ADD({{class="label",label=infotxt}},{"OK"},{close='OK'})
|
||||
end
|
||||
return sel
|
||||
end
|
||||
|
||||
-- delete commented lines from selected lines
|
||||
function nocom_line(subs,sel)
|
||||
progress("Deleting commented lines")
|
||||
ncl_sel={}
|
||||
for s=#sel,1,-1 do
|
||||
line=subs[sel[s]]
|
||||
if line.comment then
|
||||
for z,i in ipairs(ncl_sel) do ncl_sel[z]=i-1 end
|
||||
subs.delete(sel[s])
|
||||
else
|
||||
table.insert(ncl_sel,sel[s])
|
||||
end
|
||||
end
|
||||
return ncl_sel
|
||||
end
|
||||
|
||||
-- delete empty lines
|
||||
function noempty(subs,sel)
|
||||
progress("Deleting empty lines")
|
||||
noe_sel={}
|
||||
for s=#sel,1,-1 do
|
||||
line=subs[sel[s]]
|
||||
if line.text=="" then
|
||||
for z,i in ipairs(noe_sel) do noe_sel[z]=i-1 end
|
||||
subs.delete(sel[s])
|
||||
else
|
||||
table.insert(noe_sel,sel[s])
|
||||
end
|
||||
end
|
||||
return noe_sel
|
||||
end
|
||||
|
||||
-- delete commented or empty lines
|
||||
function noemptycom(subs,sel)
|
||||
progress("Deleting commented/empty lines")
|
||||
noecom_sel={}
|
||||
for s=#sel,1,-1 do
|
||||
line=subs[sel[s]]
|
||||
if line.comment or line.text=="" then
|
||||
for z,i in ipairs(noecom_sel) do noecom_sel[z]=i-1 end
|
||||
subs.delete(sel[s])
|
||||
else
|
||||
table.insert(noecom_sel,sel[s])
|
||||
end
|
||||
end
|
||||
return noecom_sel
|
||||
end
|
||||
|
||||
-- delete unused styles
|
||||
function nostyle(subs,sel)
|
||||
stylist=",,"
|
||||
for i=#subs,1,-1 do
|
||||
if subs[i].class=="dialogue" then
|
||||
line=subs[i]
|
||||
text=line.text
|
||||
st2=text:match("\\r([^\\}]*)")
|
||||
st=line.style
|
||||
if not stylist:match(","..esc(st)..",") then stylist=stylist..st..",," end
|
||||
if st2 and st2~="" and not stylist:match(","..esc(st2)..",") then stylist=stylist..st2..",," end
|
||||
end
|
||||
if subs[i].class=="style" then
|
||||
style=subs[i]
|
||||
if res.nostyle2 and style.name:match("Defa") or res.nostyle2 and style.name:match("Alt") then nodel=1 else nodel=0 end
|
||||
if not stylist:match(","..esc(style.name)..",") and nodel==0 then
|
||||
subs.delete(i)
|
||||
logg("\n Deleted style: "..style.name)
|
||||
for s=1,#sel do sel[s]=sel[s]-1 end
|
||||
end
|
||||
end
|
||||
end
|
||||
return sel
|
||||
end
|
||||
|
||||
|
||||
-- kill everything
|
||||
function killemall(subs,sel)
|
||||
if res.inverse then
|
||||
for k,v in ipairs(GUI) do
|
||||
if v.x>4 and v.y>0 and v.name~="onlyt" then res[v.name]=not res[v.name] end
|
||||
end
|
||||
end
|
||||
for z,i in ipairs(sel) do
|
||||
progress("Processing line: "..z.."/"..#sel)
|
||||
line=subs[i]
|
||||
text=line.text
|
||||
if res.onlyt then res.trans=false
|
||||
text=text:gsub(ATAG,function(t) return t:gsub("\\","|") end)
|
||||
:gsub("|t(%b())",function(t) return "\\t"..t:gsub("|","\\") end)
|
||||
end
|
||||
tags=text:match(STAG) or ""
|
||||
inline=text:gsub(STAG,"")
|
||||
if res.skill and res.ikill then trgt=text tg=3
|
||||
elseif res.ikill then trgt=inline tg=2
|
||||
else trgt=tags tg=1 end
|
||||
if res.border then trgt=killtag("[xy]?bord",trgt) end
|
||||
if res.shadow then trgt=killtag("shad",trgt) end
|
||||
if res.blur then trgt=killtag("blur",trgt) end
|
||||
if res.bee then trgt=killtag("be",trgt) end
|
||||
if res.fsize then trgt=killtag("fs",trgt) end
|
||||
if res.fspace then trgt=killtag("fsp",trgt) end
|
||||
if res.scalex then trgt=killtag("fscx",trgt) end
|
||||
if res.scaley then trgt=killtag("fscy",trgt) end
|
||||
if res.fade then trgt=trgt:gsub("\\fade?%b()","") end
|
||||
if res.posi then trgt=trgt:gsub("\\pos%b()","") end
|
||||
if res.move then trgt=trgt:gsub("\\move%b()","") end
|
||||
if res.org then trgt=trgt:gsub("\\org%b()","") end
|
||||
if res.color1 then trgt=killctag("1?c",trgt) end
|
||||
if res.color2 then trgt=killctag("2c",trgt) end
|
||||
if res.color3 then trgt=killctag("3c",trgt) end
|
||||
if res.color4 then trgt=killctag("4c",trgt) end
|
||||
if res.alfa1 then trgt=killctag("1a",trgt) end
|
||||
if res.alfa2 then trgt=killctag("2a",trgt) end
|
||||
if res.alfa3 then trgt=killctag("3a",trgt) end
|
||||
if res.alfa4 then trgt=killctag("4a",trgt) end
|
||||
if res.alpha then trgt=killctag("alpha",trgt) end
|
||||
if res.clip then trgt=trgt:gsub("\\i?clip%b()","") end
|
||||
if res.fname then trgt=trgt:gsub("\\fn[^\\}]+","") end
|
||||
if res.frz then trgt=killtag("frz",trgt) end
|
||||
if res.frx then trgt=killtag("frx",trgt) end
|
||||
if res.fry then trgt=killtag("fry",trgt) end
|
||||
if res.fax then trgt=killtag("fax",trgt) end
|
||||
if res.fay then trgt=killtag("fay",trgt) end
|
||||
if res.anna then trgt=killtag("an",trgt) end
|
||||
if res.align then trgt=killtag("a",trgt) end
|
||||
if res.wrap then trgt=killtag("q",trgt) end
|
||||
if res["return"] then trgt=trgt:gsub("\\r.+([\\}])","%1") end
|
||||
if res.kara then trgt=trgt:gsub("\\[Kk][fo]?[%d%.]+([\\}])","%1") end
|
||||
if res.ital then repeat trgt,r=trgt:gsub("\\i[01]?([\\}])","%1") until r==0 end
|
||||
if res.bold then repeat trgt,r=trgt:gsub("\\b[01]?([\\}])","%1") until r==0 end
|
||||
if res.under then repeat trgt,r=trgt:gsub("\\u[01]?([\\}])","%1") until r==0 end
|
||||
if res.stri then repeat trgt,r=trgt:gsub("\\s[01]?([\\}])","%1") until r==0 end
|
||||
if res.trans then trgt=trgt:gsub("\\t%b()","") end
|
||||
trgt=trgt:gsub("\\t%([%d%.,]*%)","") :gsub("{%**}","")
|
||||
if tg==1 then tags=trgt elseif tg==2 then inline=trgt elseif tg==3 then text=trgt end
|
||||
if trgt~=text then text=tags..inline end
|
||||
if res.onlyt then text=text:gsub("{%*?|[^}]-}",function(t) return t:gsub("|","\\") end) end
|
||||
line.text=text
|
||||
subs[i]=line
|
||||
end
|
||||
end
|
||||
|
||||
function killtag(tag,t) repeat t,r=t:gsub("\\"..tag.."[%d%.%-]-([\\}])","%1") until r==0 return t end
|
||||
function killctag(tag,t) t=t:gsub("\\"..tag.."&H%x+&","") repeat t,r=t:gsub("\\"..tag.."([\\}])","%1") until r==0 return t end
|
||||
|
||||
|
||||
-- hide tags
|
||||
function hide_tags(subs,sel)
|
||||
hide=true
|
||||
if res.inverse then hide=nil end
|
||||
local numbers="\\i\\b\\u\\s\\q\\a\\be\\blur\\bord\\fs\\fscx\\fscy\\shad\\an\\frz\\fry\\frx\\fsp\\fax\\fay\\"
|
||||
local alphacol="\\1a\\2a\\3a\\4a\\1c\\2c\\3c\\4c\\alpha\\"
|
||||
local parent="\\fad\\pos\\move\\org\\clip\\"
|
||||
local fontret="\\r\\fn\\"
|
||||
if hide then
|
||||
hidem={}
|
||||
for k,v in ipairs(GUI) do
|
||||
if v.x>4 and v.y>0 and v.name~='onlyt' and v.name~='kara' then
|
||||
nom=v.label:gsub("c, 1c","1c"):gsub("%(i%)","")
|
||||
if res[v.name] then table.insert(hidem,nom) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for x,i in ipairs(sel) do
|
||||
line=subs[i]
|
||||
text=line.text:gsub("\\c&","\\1c&")
|
||||
startg=text:match("^{\\[^}]-}") or ""
|
||||
startg=trem(startg)
|
||||
t2=text:gsub("^{\\[^}]-}","")
|
||||
|
||||
if hide then
|
||||
for t=1,#hidem do
|
||||
local tag='\\'..hidem[t]
|
||||
local htag='//'..hidem[t]
|
||||
local chk=tag..'\\'
|
||||
tg=nil
|
||||
if numbers:match(chk) then
|
||||
tg=startg:match(tag.."([%d.-]+)")
|
||||
if tg then t2=t2.."{"..htag..tg.."}" end
|
||||
startg=startg:gsub(tag.."[%d.-]+","")
|
||||
if not tg and tag=="\\shad" then
|
||||
tg1=startg:match("\\xshad([%d.-]+)")
|
||||
tg2=startg:match("\\yshad([%d.-]+)")
|
||||
if tg1 then t2=t2.."{//xshad"..tg1.."}" end
|
||||
if tg2 then t2=t2.."{//yshad"..tg2.."}" end
|
||||
startg=startg:gsub("\\[xy]shad[%d.-]+","")
|
||||
end
|
||||
elseif alphacol:match(chk) then
|
||||
tg=startg:match(tag.."(&H%x+&)")
|
||||
if tg then t2=t2.."{"..htag..tg.."}" end
|
||||
startg=startg:gsub(tag.."&H%x+&","")
|
||||
elseif parent:match(chk) then
|
||||
tg=startg:match(tag.."(%b())")
|
||||
if not tg and tag=="\\clip" then tg=startg:match("\\iclip(%b())") tag='\\iclip' htag='//iclip' end
|
||||
if not tg and tag=="\\fad" then tg=startg:match("\\fade(%b())") tag='\\fade' htag='//fade' end
|
||||
if tg then t2=t2.."{"..htag..tg.."}" end
|
||||
startg=startg:gsub(tag.."%b()","")
|
||||
elseif fontret:match(chk) then
|
||||
tg=startg:match(tag.."([^\\}]*)")
|
||||
if tg then t2=t2.."{"..htag..tg.."}" end
|
||||
startg=startg:gsub(tag.."[^\\}]*","")
|
||||
elseif tag=='\\t' then
|
||||
t2=t2.."{"..trnsfrm:gsub("\\t","//t").."}"
|
||||
end
|
||||
end
|
||||
if res.hidline then
|
||||
-- hide inline
|
||||
inT=inline_pos(t2)
|
||||
t2=t2:gsub(ATAG,"")
|
||||
for k,v in ipairs(inT) do
|
||||
t2=t2..v.t:gsub("{%*?\\","{"..v.n.."//")
|
||||
end
|
||||
end
|
||||
else
|
||||
local vis1,vis2=t2:gsub("%b{}","")
|
||||
local c=0
|
||||
repeat
|
||||
-- Unhide regular
|
||||
if res.skill then
|
||||
for hidden in t2:gmatch("{(//.-)}") do
|
||||
t2=t2:gsub("{"..esc(hidden).."}","")
|
||||
hidden=hidden:gsub("//","\\")
|
||||
startg=startg.."{"..hidden.."}"
|
||||
end
|
||||
end
|
||||
-- unhide inline
|
||||
if t2:match("{%d+//[^}]+}") and res.ikill then
|
||||
inT={}
|
||||
stT=''
|
||||
for num,tag in t2:gmatch("{(%d+)//([^}]+)}") do
|
||||
table.insert(inT,{n=num,t=tag})
|
||||
end
|
||||
for tag in t2:gmatch("{//[^}]+}") do stT=stT..tag end
|
||||
table.sort(inT,function(a,b) return tonumber(a.n)<tonumber(b.n) end)
|
||||
t2=t2:gsub("{%d+//[^}]+}","")
|
||||
if t2:match"{" then orig=t2 t2=t2:gsub("%b{}","") end
|
||||
t2=inline_ret2(t2,inT)
|
||||
if orig then t2=textmod(orig,t2) orig=nil end
|
||||
t2=t2..stT
|
||||
end
|
||||
vis2=t2:gsub("%b{}","")
|
||||
c=c+1
|
||||
until vis1==vis2 or c==666
|
||||
if vis1~=vis2 then logg('Error:\n '..vis1..'\n> '..vis2) end
|
||||
end
|
||||
|
||||
if not hide or hide and not res.trans then startg=startg.."{"..trnsfrm.."}" end
|
||||
text=duplikill(startg:gsub("}{",""):gsub("\\1c","\\c"))..t2
|
||||
text=text:gsub("{}",""):gsub("\\1c","\\c")
|
||||
if line.text~=text then line.text=text subs[i]=line end
|
||||
end
|
||||
return sel
|
||||
end
|
||||
|
||||
-- save inline tags
|
||||
function inline_pos(t)
|
||||
inTags={}
|
||||
tl=t:len()
|
||||
if tl==0 then return {} end
|
||||
p=0
|
||||
t1=''
|
||||
repeat
|
||||
seg=t:match("^(%b{})") -- try to match tags/comments
|
||||
if seg then
|
||||
if seg:match("{%*?\\") then table.insert(inTags,{n=p,t=seg}) end
|
||||
else
|
||||
seg=t:match("^([^{]+)") -- or match text
|
||||
if not seg then t_error("Error: There appears to be a problem with the brackets here...\n"..t1..t,1) end
|
||||
SL=re.find(seg,".")
|
||||
p=p+#SL -- position of next '{' [or end]
|
||||
end
|
||||
t1=t1..seg
|
||||
t=t:gsub("^"..esc(seg),"")
|
||||
tl=t:len()
|
||||
until tl==0
|
||||
return inTags
|
||||
end
|
||||
|
||||
-- rebuild inline tags
|
||||
function inline_ret2(t,tab)
|
||||
tl=t:len()
|
||||
nt=''
|
||||
kill='_Z#W_' -- this is supposed to never match
|
||||
for k,v in ipairs(tab) do
|
||||
N=tonumber(v.n)
|
||||
if N==0 then nt=nt..v.t
|
||||
else
|
||||
m='.'
|
||||
-- match how many chars at the start
|
||||
m=m:rep(N)
|
||||
RS=re.find(t,m)
|
||||
seg=RS[1].str
|
||||
seg=re.sub(seg,'^'..kill,'')
|
||||
nt=nt..seg..'{\\'..v.t..'}'
|
||||
kill=m -- how many matched in the last round
|
||||
end
|
||||
end
|
||||
-- the rest
|
||||
seg=re.sub(t,'^'..kill,'')
|
||||
nt=nt..seg
|
||||
return nt
|
||||
end
|
||||
|
||||
-- reanimatools -------
|
||||
function esc(str) str=str:gsub("[%%%(%)%[%]%.%-%+%*%?%^%$]","%%%1") return str end
|
||||
function rnd2dec(num) num=math.floor((num*100)+0.5)/100 return num end
|
||||
function logg(m) m=m or "nil" aegisub.log("\n "..m) end
|
||||
function wrap(str) return "{"..str.."}" end
|
||||
function nobra(t) return t:gsub("%b{}","") end
|
||||
function nobrea(t) return t:gsub("%b{}",""):gsub("\\[Nh]","") end
|
||||
function nobrea1(t) return t:gsub("%b{}",""):gsub(" *\\[Nh] *"," ") end
|
||||
function tagmerge(t) repeat t,r=t:gsub("({\\[^}]-)}{(\\[^}]-})","%1%2") until r==0 return t end
|
||||
function progress(msg) if aegisub.progress.is_cancelled() then ak() end aegisub.progress.title(msg) end
|
||||
function t_error(message,cancel) ADD({{class="label",label=message}},{"OK"},{close='OK'}) if cancel then ak() end end
|
||||
|
||||
function duplikill(tagz)
|
||||
local tags1={"blur","be","bord","shad","xbord","xshad","ybord","yshad","fs","fsp","fscx","fscy","frz","frx","fry","fax","fay"}
|
||||
local tags2={"c","2c","3c","4c","1a","2a","3a","4a","alpha"}
|
||||
tagz=tagz:gsub("\\t%b()",function(t) return t:gsub("\\","|") end)
|
||||
for i=1,#tags1 do
|
||||
tag=tags1[i]
|
||||
repeat tagz,c=tagz:gsub("|"..tag.."[%d%.%-]+([^}]-)(\\"..tag.."[%d%.%-]+)","%1%2") until c==0
|
||||
repeat tagz,c=tagz:gsub("\\"..tag.."[%d%.%-]+([^}]-)(\\"..tag.."[%d%.%-]+)","%2%1") until c==0
|
||||
end
|
||||
tagz=tagz:gsub("\\1c&","\\c&")
|
||||
for i=1,#tags2 do
|
||||
tag=tags2[i]
|
||||
repeat tagz,c=tagz:gsub("|"..tag.."&H%x+&([^}]-)(\\"..tag.."&H%x+&)","%1%2") until c==0
|
||||
repeat tagz,c=tagz:gsub("\\"..tag.."&H%x+&([^}]-)(\\"..tag.."&H%x+&)","%2%1") until c==0
|
||||
end
|
||||
repeat tagz,c=tagz:gsub("\\fn[^\\}]+([^}]-)(\\fn[^\\}]+)","%2%1") until c==0
|
||||
repeat tagz,c=tagz:gsub("(\\[ibusq])%d(.-)(%1%d)","%2%3") until c==0
|
||||
repeat tagz,c=tagz:gsub("(\\an)%d(.-)(%1%d)","%3%2") until c==0
|
||||
tagz=tagz:gsub("(|i?clip%(%A-%))(.-)(\\i?clip%(%A-%))","%2%3")
|
||||
:gsub("(\\i?clip%b())(.-)(\\i?clip%b())",function(a,b,c)
|
||||
if a:match("m") and c:match("m") or not a:match("m") and not c:match("m") then return b..c else return a..b..c end end)
|
||||
tagz=tagz:gsub("|","\\"):gsub("\\t%([^\\%)]-%)","")
|
||||
return tagz
|
||||
end
|
||||
|
||||
function extrakill(text,o)
|
||||
local tags3={"pos","move","org","fad"}
|
||||
for i=1,#tags3 do
|
||||
tag=tags3[i]
|
||||
if o==2 then
|
||||
repeat text,c=text:gsub("(\\"..tag.."[^\\}]+)([^}]-)(\\"..tag.."[^\\}]+)","%3%2") until c==0
|
||||
else
|
||||
repeat text,c=text:gsub("(\\"..tag.."[^\\}]+)([^}]-)(\\"..tag.."[^\\}]+)","%1%2") until c==0
|
||||
end
|
||||
end
|
||||
repeat text,c=text:gsub("(\\pos[^\\}]+)([^}]-)(\\move[^\\}]+)","%1%2") until c==0
|
||||
repeat text,c=text:gsub("(\\move[^\\}]+)([^}]-)(\\pos[^\\}]+)","%1%2") until c==0
|
||||
return text
|
||||
end
|
||||
|
||||
function trem(tags)
|
||||
trnsfrm=""
|
||||
for t in tags:gmatch("\\t%b()") do trnsfrm=trnsfrm..t end
|
||||
tags=tags:gsub("\\t%b()","")
|
||||
return tags
|
||||
end
|
||||
|
||||
function cleantr(tags)
|
||||
trnsfrm=""
|
||||
zerotf=""
|
||||
for t in tags:gmatch("\\t%b()") do
|
||||
if t:match("\\t%(\\") then
|
||||
zerotf=zerotf..t:match("\\t%((.*)%)$")
|
||||
else
|
||||
trnsfrm=trnsfrm..t
|
||||
end
|
||||
end
|
||||
zerotf="\\t("..zerotf..")"
|
||||
tags=tags:gsub("\\t%b()",""):gsub("^({[^}]*)}","%1"..zerotf..trnsfrm.."}"):gsub("\\t%(%)","")
|
||||
return tags
|
||||
end
|
||||
|
||||
function retextmod(orig,text)
|
||||
local v1,v2,c,t2
|
||||
v1=nobrea(orig)
|
||||
c=0
|
||||
repeat
|
||||
t2=textmod(orig,text)
|
||||
v2=nobrea(text)
|
||||
c=c+1
|
||||
until v1==v2 or c==666
|
||||
if v1~=v2 then logg("Something went wrong with the text...") logg(v1) logg(v2) end
|
||||
return t2
|
||||
end
|
||||
|
||||
function textmod(orig,text)
|
||||
if text=="" then return orig end
|
||||
tk={}
|
||||
tg={}
|
||||
text=text:gsub("{\\\\k0}","")
|
||||
text=tagmerge(text)
|
||||
vis=nobra(text)
|
||||
ltrmatches=re.find(vis,".")
|
||||
if not ltrmatches then logg("text: "..text..'\nvisible: '..vis)
|
||||
logg("If you're seeing this, something really weird is happening with the re module.\nTry this again or rescan Autoload.")
|
||||
end
|
||||
for l=1,#ltrmatches do
|
||||
table.insert(tk,ltrmatches[l].str)
|
||||
end
|
||||
stags=text:match(STAG) or ""
|
||||
text=text:gsub(STAG,"") :gsub("{[^\\}]-}","")
|
||||
orig=orig:gsub("{([^\\}]+)}",function(c) return wrap("\\\\"..c.."|||") end)
|
||||
count=0
|
||||
for seq in orig:gmatch("[^{]-{%*?\\[^}]-}") do
|
||||
chars,as,tak=seq:match("([^{]-){(%*?)(\\[^}]-)}")
|
||||
pos=re.find(chars,".")
|
||||
if pos==nil then ps=0+count else ps=#pos+count end
|
||||
tgl={p=ps,t=tak,a=as}
|
||||
table.insert(tg,tgl)
|
||||
count=ps
|
||||
end
|
||||
count=0
|
||||
for seq in text:gmatch("[^{]-{%*?\\[^}]-}") do
|
||||
chars,as,tak=seq:match("([^{]-){(%*?)(\\[^}]-)}")
|
||||
pos=re.find(chars,".")
|
||||
if pos==nil then ps=0+count else ps=#pos+count end
|
||||
tgl={p=ps,t=tak,a=as}
|
||||
table.insert(tg,tgl)
|
||||
count=ps
|
||||
end
|
||||
newline=""
|
||||
for i=1,#tk do
|
||||
newline=newline..tk[i]
|
||||
newt=""
|
||||
for n,t in ipairs(tg) do
|
||||
if t.p==i then newt=newt..t.a..t.t end
|
||||
end
|
||||
if newt~="" then newline=newline.."{"..as..newt.."}" end
|
||||
end
|
||||
newtext=stags..newline:gsub("(|||)(\\\\)","%1}{%2"):gsub("({[^}]-)\\\\([^\\}]-)|||","{%2}%1")
|
||||
text=newtext:gsub("{}","")
|
||||
return text
|
||||
end
|
||||
|
||||
|
||||
function cleanup(subs,sel,act)
|
||||
ADD=aegisub.dialog.display
|
||||
ak=aegisub.cancel
|
||||
if #sel==0 then t_error("No selection",1) end
|
||||
ATAG="{[*>]?\\[^}]-}"
|
||||
STAG="^{>?\\[^}]-}"
|
||||
if act==0 then act=sel[1] end
|
||||
chng=0 kleen=0
|
||||
GUI={
|
||||
{x=0,y=0,class="checkbox",name="nots",label="Remove TS timecodes",hint="Removes timecodes like {TS 12:36}"},
|
||||
{x=0,y=1,class="checkbox",name="clear_a",label="Clear Actor field"},
|
||||
{x=0,y=2,class="checkbox",name="clear_e",label="Clear Effect field"},
|
||||
{x=0,y=3,class="checkbox",name="layers",label="Raise dialogue layer by 5"},
|
||||
{x=0,y=4,class="checkbox",name="cleantag",label="Clean up tags",hint="Fixes duplicates, \\\\, \\}, }{, and other garbage"},
|
||||
{x=0,y=5,class="checkbox",name="ctrans",label="Clean up transforms"},
|
||||
{x=0,y=6,class="checkbox",name="overlap",label="Fix 1-frame gaps/overlaps"},
|
||||
{x=0,y=7,class="checkbox",name="nocomline",label="Delete commented lines"},
|
||||
{x=0,y=8,class="checkbox",name="noempty",label="Delete empty lines"},
|
||||
{x=0,y=9,class="checkbox",name="alphacol",label="Try to fix alpha / colour tags"},
|
||||
{x=0,y=10,class="checkbox",name="spaces",label="Fix start/end/double spaces"},
|
||||
{x=0,y=12,class="checkbox",name="info",label="Print info"},
|
||||
{x=0,y=13,class="checkbox",name="all",label="ALL OF THE ABOVE"},
|
||||
|
||||
{x=1,y=0,class="label",label=" "},
|
||||
|
||||
{x=2,y=0,width=2,class="checkbox",name="allcol",label="Remove all colour tags"},
|
||||
{x=2,y=1,class="checkbox",name="allphas",label="Remove all alphas"},
|
||||
{x=3,y=1,class="checkbox",name="alpha14",label="Only 1a-4a"},
|
||||
{x=2,y=2,class="checkbox",name="allrot",label="Remove all rotations",hint="frx, fry, frz"},
|
||||
{x=3,y=2,class="checkbox",name="xyrot",label="Only x, y",hint="remove frx, fry"},
|
||||
{x=2,y=3,class="checkbox",name="allsize",label="Remove size/scaling",hint="fs, fscx, fscy"},
|
||||
{x=3,y=3,class="checkbox",name="scales",label="Only scaling",hint="remove fscx, fscy"},
|
||||
{x=2,y=4,class="checkbox",name="allshad",label="Remove all shadows",hint="shad, xshad, yshad"},
|
||||
{x=3,y=4,class="checkbox",name="xyshad",label="Only x, y",hint="remove xshad, yshad"},
|
||||
{x=2,y=5,class="checkbox",name="parent",label="Remove parentheses",hint="fad(e), (i)clip, pos, move, org\n(but not t)"},
|
||||
{x=3,y=5,class="checkbox",name="parent2",label="Except \\pos",hint="fad(e), (i)clip, move, org\n(but not t or pos)"},
|
||||
{x=2,y=6,width=2,class="checkbox",name="allpers",label="Remove all perspective",hint="frx, fry, frz, fax, fay, org"},
|
||||
|
||||
{x=2,y=7,width=2,class="label",label=" ~ Script Cleanup v"..script_version.." ~"},
|
||||
|
||||
{x=2,y=8,width=2,class="checkbox",name="hspace",label="Remove hard spaces - \\h"},
|
||||
{x=2,y=9,class="checkbox",name="nobreak",label="Remove line breaks"},
|
||||
{x=3,y=9,class="checkbox",name="nobreak2",label="...no space",hint="Remove line breaks, leave no spaces"},
|
||||
{x=2,y=10,class="checkbox",name="nostyle",label="Delete unused styles"},
|
||||
{x=3,y=10,class="checkbox",name="nostyle2",label="Except Def.",hint="Delete unused styles except Default"},
|
||||
{x=2,y=11,class="checkbox",name="inline",label="Remove inline tags"},
|
||||
{x=3,y=11,class="checkbox",name="inline2",label="Except last",hint="Remove inline tags except the last one"},
|
||||
{x=2,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"},
|
||||
{x=2,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"},
|
||||
|
||||
{x=4,y=0,height=14,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"},
|
||||
|
||||
{x=5,y=0,class="checkbox",name="skill",label="[start]",value=true},
|
||||
{x=6,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"},
|
||||
{x=7,y=0,width=2,class="checkbox",name="inverse",label="[inverse/unhide]",hint="kill all except checked ones\n\n'Unhide' for 'Hide Tags'"},
|
||||
{x=7,y=1,width=2,class="checkbox",name="onlyt",label="[from \\t]",hint="remove only from transforms\n\n n/a for 'Hide Tags'"},
|
||||
|
||||
{x=5,y=1,class="checkbox",name="blur",label="blur"},
|
||||
{x=5,y=2,class="checkbox",name="border",label="bord",hint="includes xbord and ybord [not for Hide]"},
|
||||
{x=5,y=3,class="checkbox",name="shadow",label="shad",hint="includes xshad and yshad for Hide"},
|
||||
{x=5,y=4,class="checkbox",name="fsize",label="fs"},
|
||||
{x=5,y=5,class="checkbox",name="fspace",label="fsp"},
|
||||
{x=5,y=6,class="checkbox",name="scalex",label="fscx"},
|
||||
{x=5,y=7,class="checkbox",name="scaley",label="fscy"},
|
||||
{x=5,y=8,class="checkbox",name="fname",label="fn"},
|
||||
{x=5,y=9,class="checkbox",name="ital",label="i"},
|
||||
{x=5,y=10,class="checkbox",name="bold",label="b"},
|
||||
{x=5,y=11,class="checkbox",name="under",label="u"},
|
||||
{x=5,y=12,class="checkbox",name="stri",label="s"},
|
||||
{x=5,y=13,class="checkbox",name="wrap",label="q"},
|
||||
|
||||
{x=6,y=1,class="checkbox",name="bee",label="be"},
|
||||
{x=6,y=2,class="checkbox",name="color1",label="c, 1c"},
|
||||
{x=6,y=3,class="checkbox",name="color2",label="2c"},
|
||||
{x=6,y=4,class="checkbox",name="color3",label="3c"},
|
||||
{x=6,y=5,class="checkbox",name="color4",label="4c"},
|
||||
{x=6,y=6,class="checkbox",name="alpha",label="alpha"},
|
||||
{x=6,y=7,class="checkbox",name="alfa1",label="1a"},
|
||||
{x=6,y=8,class="checkbox",name="alfa2",label="2a"},
|
||||
{x=6,y=9,class="checkbox",name="alfa3",label="3a"},
|
||||
{x=6,y=10,class="checkbox",name="alfa4",label="4a"},
|
||||
{x=6,y=11,class="checkbox",name="align",label="a"},
|
||||
{x=6,y=12,class="checkbox",name="anna",label="an"},
|
||||
{x=6,y=13,class="checkbox",name="clip",label="(i)clip"},
|
||||
|
||||
{x=7,y=2,class="checkbox",name="fade",label="fad"},
|
||||
{x=7,y=3,class="checkbox",name="posi",label="pos"},
|
||||
{x=7,y=4,class="checkbox",name="move",label="move"},
|
||||
{x=7,y=5,class="checkbox",name="org",label="org"},
|
||||
{x=7,y=6,class="checkbox",name="frz",label="frz"},
|
||||
{x=7,y=7,class="checkbox",name="frx",label="frx"},
|
||||
{x=7,y=8,class="checkbox",name="fry",label="fry"},
|
||||
{x=7,y=9,class="checkbox",name="fax",label="fax"},
|
||||
{x=7,y=10,class="checkbox",name="fay",label="fay"},
|
||||
{x=7,y=11,width=2,class="checkbox",name="kara",label="k/kf/ko"},
|
||||
{x=7,y=12,class="checkbox",name="return",label="r"},
|
||||
{x=7,y=13,class="checkbox",name="trans",label="t"},
|
||||
|
||||
{x=8,y=12,height=2,class="checkbox",name="hidline",label="hide\ninline",hint='Hide ALL inline tags'},
|
||||
}
|
||||
P,res=ADD(GUI,
|
||||
{"Run selected","Comments","Tags","Dial 5","Clean Tags","^ Kill Tags","Hide Tags","Cancer"},{ok='Run selected',cancel='Cancer'})
|
||||
if P=="Cancer" then ak() end
|
||||
if P=="^ Kill Tags" then killemall(subs,sel) end
|
||||
if P=="Hide Tags" then hide_tags(subs,sel) end
|
||||
if P=="Comments" then res.nocom=true cleanlines(subs,sel) end
|
||||
if P=="Tags" then res.notag=true cleanlines(subs,sel) end
|
||||
if P=="Dial 5" then res.layers=true cleanlines(subs,sel) end
|
||||
if P=="Clean Tags" then res.cleantag=true cleanlines(subs,sel) end
|
||||
if P=="Run selected" then
|
||||
C=0 for key,v in ipairs(GUI) do if v.x<=3 and res[v.name] then C=1 end end
|
||||
if C==0 then t_error("Run Selected: Error - nothing selected",1) end
|
||||
if res.all then
|
||||
for key,v in ipairs(GUI) do if v.x>0 and v.name then res[v.name]=false end end
|
||||
cleanlines(subs,sel)
|
||||
sel=noemptycom(subs,sel)
|
||||
else cleanlines(subs,sel)
|
||||
if res.nocomline and res.noempty then sel=noemptycom(subs,sel)
|
||||
else
|
||||
if res.nocomline then sel=nocom_line(subs,sel) end
|
||||
if res.noempty then sel=noempty(subs,sel) end
|
||||
end
|
||||
table.sort(sel)
|
||||
if res.nostyle or res.nostyle2 then sel=nostyle(subs,sel) end
|
||||
end
|
||||
end
|
||||
if act>#subs then act=#subs end
|
||||
return sel,act
|
||||
end
|
||||
|
||||
if haveDepCtrl then depRec:registerMacro(cleanup) else aegisub.register_macro(script_name,script_description,cleanup) end
|
|
@ -0,0 +1,43 @@
|
|||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"unkf"
|
||||
script_description = tr"replace kf/ko tags in selected lines by regular k tags"
|
||||
script_author = "amoethyst"
|
||||
script_version = "1.0"
|
||||
|
||||
|
||||
function split_line(subs, sel)
|
||||
local expr_kof = "^(.-{[^}]*\\k)[of](.*)$"
|
||||
local expr_K = "^(.-{[^}]*\\)K(.*)$"
|
||||
local before, after
|
||||
|
||||
for _, i in ipairs(sel) do
|
||||
line = subs[i]
|
||||
|
||||
-- replace ko and kf tags
|
||||
while true do
|
||||
before, after = line.text:match(expr_kof)
|
||||
if before == nil then
|
||||
break
|
||||
else
|
||||
line.text = before .. after
|
||||
end
|
||||
end
|
||||
|
||||
-- replace K tags
|
||||
while true do
|
||||
before, after = line.text:match(expr_K)
|
||||
if before == nil then
|
||||
break
|
||||
else
|
||||
line.text = before .. "k" .. after
|
||||
end
|
||||
end
|
||||
|
||||
subs[i] = line
|
||||
end
|
||||
|
||||
aegisub.set_undo_point(script_name)
|
||||
end
|
||||
|
||||
aegisub.register_macro(script_name, script_description, split_line)
|
Loading…
Reference in New Issue