2021-06-13 14:00:29 +00:00
|
|
|
script_name="CR Restyler"
|
|
|
|
script_description="become a fansubber with a click of a button"
|
|
|
|
script_author = "garret"
|
2021-08-15 22:33:55 +00:00
|
|
|
script_version = "2.0.0-dev"
|
2021-06-13 14:00:29 +00:00
|
|
|
|
2021-08-15 22:33:55 +00:00
|
|
|
include("karaskel.lua")
|
2021-06-13 14:08:28 +00:00
|
|
|
include("cleantags.lua")
|
2021-06-13 14:00:29 +00:00
|
|
|
|
2021-08-15 22:33:55 +00:00
|
|
|
-- TODO: detect already existing tags
|
|
|
|
-- probably need some kind of ass parsing, or a hack with match()
|
|
|
|
|
|
|
|
function add_tags(txt, italic, align) -- everything except txt is boolean. nil = don't change, !nil = change to this value
|
|
|
|
|
|
|
|
--[[not quite happy with this, it overwrites the alignment - ie line is "{\an4} blah blah" and style is an8, it just changes it to an8
|
|
|
|
realisticly this _probably_ won't be a problem, but still would like to try and stop it at some point to be safe
|
|
|
|
italics is fine, it just does {\i1\i0}, which is jank and bad but works fine so i won't worry about it too much]]
|
|
|
|
if italic == true then
|
2021-06-13 14:08:28 +00:00
|
|
|
txt="{\\i1}"..txt
|
2021-08-15 22:33:55 +00:00
|
|
|
elseif italics == false then
|
|
|
|
txt="{\\i0}"..txt
|
2021-06-13 14:08:28 +00:00
|
|
|
end
|
2021-08-15 22:33:55 +00:00
|
|
|
if align ~= nil then
|
|
|
|
txt="{\\an"..align.."}"..txt
|
2021-06-13 14:00:29 +00:00
|
|
|
end
|
2021-08-15 22:33:55 +00:00
|
|
|
txt = cleantags(txt)
|
|
|
|
return txt
|
2021-06-13 14:00:29 +00:00
|
|
|
end
|
|
|
|
|
2021-08-15 22:33:55 +00:00
|
|
|
function get_new(old, new)
|
|
|
|
local i = nil
|
|
|
|
if old ~= new then
|
|
|
|
i = old
|
2021-06-13 14:00:29 +00:00
|
|
|
end
|
2021-08-15 22:33:55 +00:00
|
|
|
return i
|
2021-06-13 14:00:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function main(sub, sel)
|
2021-08-15 22:33:55 +00:00
|
|
|
local _, styles = karaskel.collect_head(sub) -- i'd like to not have it log if possible
|
|
|
|
local new_style_name = "Default" -- the one we'll be changing stuff to - TODO: configurable
|
|
|
|
local new_style = styles[new_style_name]
|
2021-06-13 14:00:29 +00:00
|
|
|
for h, i in ipairs(sel) do
|
2021-08-15 22:33:55 +00:00
|
|
|
-- maybe don't do if the style has "sign" in the name?
|
|
|
|
-- need proper list of stuff cr uses
|
2021-06-13 14:00:29 +00:00
|
|
|
local line = sub[i]
|
2021-08-15 22:33:55 +00:00
|
|
|
local old_style = styles[line.style]
|
|
|
|
local italic = get_new(old_style.italic, new_style.italic)
|
|
|
|
local align = get_new(old_style.align, new_style.align)
|
|
|
|
line.style = new_style_name
|
|
|
|
line.text = add_tags(line.text, italic, align)
|
2021-06-13 14:00:29 +00:00
|
|
|
sub[i] = line
|
|
|
|
end
|
|
|
|
aegisub.set_undo_point(script_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
aegisub.register_macro(script_name, script_description, main)
|