From f5bc664a4ed48c2a33aa6db651cb4ad4e5f33fb4 Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 15 Aug 2021 23:33:55 +0100 Subject: cr restyler v2 original made lots of assumptions about the default style (and cr's styles, to some extent) v2 copies the values from the styles themselves, and only tags if the value is actually different. works with _all_ styles, not just the 4 i put in v1. still can't help if the cr script doesn't use styles properly. not quite done yet, still need to sort out the handling of inline tags, but very much usable --- become-fansubber.lua | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/become-fansubber.lua b/become-fansubber.lua index 376a630..9f5ac32 100644 --- a/become-fansubber.lua +++ b/become-fansubber.lua @@ -1,40 +1,52 @@ script_name="CR Restyler" script_description="become a fansubber with a click of a button" script_author = "garret" -script_version = "2021-06-15" +script_version = "2.0.0-dev" +include("karaskel.lua") include("cleantags.lua") --- Main -> Default --- Top -> an8 --- italics -> i1 --- flashback -> default -function add_tags(line) - local txt = line.text - local style = line.style - if style:match("Italics") then +-- 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 txt="{\\i1}"..txt + elseif italics == false then + txt="{\\i0}"..txt end - if style:match("Top") then - txt="{\\an8}"..txt + if align ~= nil then + txt="{\\an"..align.."}"..txt end - line.text = cleantags(txt) - return line + txt = cleantags(txt) + return txt end -function change_styles(line) - local style = line.style - if style:match("Top") or style:match("Italics") or style:match("Main") or style:match("Flashback") then - line.style="Default" +function get_new(old, new) + local i = nil + if old ~= new then + i = old end - return line + return i end function main(sub, sel) + 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] for h, i in ipairs(sel) do + -- maybe don't do if the style has "sign" in the name? + -- need proper list of stuff cr uses local line = sub[i] - line = add_tags(line) - line = change_styles(line) + 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) sub[i] = line end aegisub.set_undo_point(script_name) -- cgit v1.2.3-70-g09d2