From 472fc5337dc41abc9545256720f3265f466f9b16 Mon Sep 17 00:00:00 2001 From: garret Date: Sat, 9 Oct 2021 15:20:50 +0100 Subject: add depctrl thing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no feed yet, will get round to it eventually™ --- macros/a-b.lua | 34 ------------ macros/append-comment.lua | 35 ------------- macros/audio-clipper.lua | 36 ++++++------- macros/become-fansubber.lua | 54 ------------------- macros/chapters.lua | 80 ---------------------------- macros/dupe-and-comment.lua | 33 ------------ macros/garret.a-b.lua | 45 ++++++++++++++++ macros/garret.append-comment.lua | 47 +++++++++++++++++ macros/garret.chapters.lua | 103 +++++++++++++++++++++++++++++++++++++ macros/garret.dupe-and-comment.lua | 55 ++++++++++++++++++++ macros/garret.karaoke2alpha.lua | 70 +++++++++++++++++++++++++ macros/garret.restyler.lua | 74 ++++++++++++++++++++++++++ macros/garret.select-comments.lua | 33 ++++++++++++ macros/karaoke2alpha.lua | 68 ------------------------ macros/select-comments.lua | 18 ------- 15 files changed, 444 insertions(+), 341 deletions(-) delete mode 100644 macros/a-b.lua delete mode 100644 macros/append-comment.lua delete mode 100644 macros/become-fansubber.lua delete mode 100644 macros/chapters.lua delete mode 100644 macros/dupe-and-comment.lua create mode 100644 macros/garret.a-b.lua create mode 100644 macros/garret.append-comment.lua create mode 100644 macros/garret.chapters.lua create mode 100644 macros/garret.dupe-and-comment.lua create mode 100644 macros/garret.karaoke2alpha.lua create mode 100644 macros/garret.restyler.lua create mode 100644 macros/garret.select-comments.lua delete mode 100644 macros/karaoke2alpha.lua delete mode 100644 macros/select-comments.lua diff --git a/macros/a-b.lua b/macros/a-b.lua deleted file mode 100644 index 994361f..0000000 --- a/macros/a-b.lua +++ /dev/null @@ -1,34 +0,0 @@ -script_name = "A-B" -script_description = "makes checking pre-timing possible." -script_author = "garret" -script_version = "2021-07-10" - -function switch_number(i) - if i == "a" then - return "b" - elseif i == "b" then - return "a" - end -end - -function main(sub, sel) - local i = "a" - for si,li in ipairs(sel) do - line = sub[li] - if line.actor == "" then - indicator = i - else - indicator = line.actor.." "..i - end - if line.text == "" then - line.text = indicator - elseif line.text:gsub("{[^}]-}","") == "" then - line.text = indicator.." "..line.text - end - sub[li] = line - i = switch_number(i) - end - aegisub.set_undo_point(script_name) -end - -aegisub.register_macro(script_name, script_description, main) diff --git a/macros/append-comment.lua b/macros/append-comment.lua deleted file mode 100644 index 47d3feb..0000000 --- a/macros/append-comment.lua +++ /dev/null @@ -1,35 +0,0 @@ -script_name = "Append Comment" -script_description = "{ts do all the work pls kthxbye}" -script_author = "garret" -script_version = "1.1.2" - -function main(sub, sel) - dialog_config= - { - { - class="label", - x=0,y=0,width=1,height=1, - label="Comment:" - }, - { - class="edit",name="msg", - x=0,y=1,width=1,height=2, - value="" - } - } - if #sel == 1 then - table.insert(dialog_config, {class="label",x=0,y=3,width=1,height=1,label="if you're not using this for multiple lines \nyou may as well just type it out yourself"}) - end - button, results = aegisub.dialog.display(dialog_config) - if button ~= false then - for _, i in ipairs(sel) do - local line = sub[i] - line.text = line.text.." {"..results.msg.."}" - sub[i] = line - end - else - aegisub.cancel() - end -end - -aegisub.register_macro(script_name, script_description, main) diff --git a/macros/audio-clipper.lua b/macros/audio-clipper.lua index 99f2b9f..8576688 100644 --- a/macros/audio-clipper.lua +++ b/macros/audio-clipper.lua @@ -1,18 +1,16 @@ script_name = "Audio Clipper" script_description = "Extracts audio from the selected line(s).\nNeeds ffmpeg." script_author = "garret" -script_version = "1.1.2" - -aegi = aegisub +script_version = "1.1.3" function err(msg) - aegi.dialog.display({{class = "label", label = msg}}, {"OK"}, {close = "OK"}) - aegi.cancel() + aegisub.dialog.display({{class = "label", label = msg}}, {"OK"}, {close = "OK"}) + aegisub.cancel() end function get_vid_dir() - local aud_dir = aegi.decode_path("?audio") - local vid_dir = aegi.decode_path("?video") + local aud_dir = aegisub.decode_path("?audio") + local vid_dir = aegisub.decode_path("?video") if aud_dir ~= "?audio" then return aud_dir elseif vid_dir ~= "?video" then -- if there is not, in fact, a video @@ -23,8 +21,8 @@ function get_vid_dir() end function get_vid() - local aud = aegi.project_properties().audio_file -- try get the audio first, if it's loaded separately - local vid = aegi.project_properties().video_file + local aud = aegisub.project_properties().audio_file -- try get the audio first, if it's loaded separately + local vid = aegisub.project_properties().video_file if aud ~= "" then return aud elseif vid ~= "" then @@ -71,22 +69,22 @@ function extract_audio(in_path, start_time, end_time, out_path, name, extension, end function loop(subs, sel, in_path, out_path, extension, copy, delay) - aegi.progress.title("Extracting Audio") + aegisub.progress.title("Extracting Audio") local progress = 0 local progress_increment = 100 / #sel -- increment by this for every line, and the bar will eventually reach 100 for x, i in ipairs(sel) do -- x is the position of the line in our selection, i is the position in the whole sub file - if aegi.progress.is_cancelled() then -- if you press the cancel button - aegi.cancel() -- it stops (mind-blowing, i know) + if aegisub.progress.is_cancelled() then -- if you press the cancel button + aegisub.cancel() -- it stops (mind-blowing, i know) end - aegi.progress.set(progress) + aegisub.progress.set(progress) local line = subs[i] local start_time = line.start_time + delay local end_time = line.end_time + delay - aegi.progress.task("Extracting line "..x) + aegisub.progress.task("Extracting line "..x) extract_audio(in_path, start_time, end_time, out_path, x, extension, copy) progress = progress + progress_increment end - aegi.progress.set(100) -- in case it didn't reach 100 on its own + aegisub.progress.set(100) -- in case it didn't reach 100 on its own end @@ -101,10 +99,10 @@ function gui(subs, sel) end local get_input={{class="label",x=0,y=0,label="Input's audio format:"},{class="dropdown",name="format",x=0,y=1,width=2,height=1,items={"AAC","Opus","FLAC","Custom"},value="Audio Format",hint="If you don't know, you should probably press \"Just make it FLAC\", or use mka."},{class="label",x=0,y=2,label="Custom Extension:"},{class="edit",name="custom",x=1,y=2,value="mka",hint="You'll probably be fine with mka, because matroska can contain pretty much anything"},{class="label",x=0,y=3,label="Delay (ms):"},{class="intedit",name="delay",x=1,y=3,value=0,hint="to prevent timing fuckery with weird raws"},{class="label",x=0,y=4,label="Input path:"},{class="edit",name="in_path",x=0,y=5,width=2,height=1,value=in_path,hint="where the audio comes from"},{class="label",x=0,y=6,label="Output path (will be created if it doesn't already exist):"},{class="edit",name="out_path",x=0,y=7,width=2,height=1,value=out_path,hint="where the audio goes"}} - local pressed, results = aegi.dialog.display(get_input, {"Cancel", "OK", "Just make it FLAC"}) + local pressed, results = aegisub.dialog.display(get_input, {"Cancel", "OK", "Just make it FLAC"}) -- there's probably something that can detect the format automatically, but I do not know what it is. if pressed == "Cancel" then - aegi.cancel() + aegisub.cancel() elseif pressed == "OK" then do_copy = true elseif pressed == "Just make it FLAC" then @@ -127,5 +125,5 @@ function non_gui(subs, sel) -- no gui, so you can bind it to a hotkey -- sets sane defaults (takes the audio from the video file, and outputs to /the/video/dir/audioclipper_output/. transcodes to flac. no delay) end -aegi.register_macro(script_name, script_description, gui) -aegi.register_macro(": Non-GUI macros :/"..script_name..": Just make it FLAC", script_description, non_gui) -- same section as unanimated's scripts +aegisub.register_macro(script_name, script_description, gui) +aegisub.register_macro(": Non-GUI macros :/"..script_name..": Just make it FLAC", script_description, non_gui) -- same section as unanimated's scripts diff --git a/macros/become-fansubber.lua b/macros/become-fansubber.lua deleted file mode 100644 index 1dfdb43..0000000 --- a/macros/become-fansubber.lua +++ /dev/null @@ -1,54 +0,0 @@ -script_name="Restyler" -script_description="become a fansubber with a click of a button" -script_author = "garret" -script_version = "2.0.0" - -include("karaskel.lua") -include("cleantags.lua") - --- TODO: detect pre-existing inline 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 align ~= nil then - txt="{\\an"..align.."}"..txt - end - txt = cleantags(txt) - return txt -end - -function get_new(old, new) - local i = nil - if old ~= new then - i = old - end - return i -end - -function main(sub, sel) - local _, styles = karaskel.collect_head(sub, false) - 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 - -- TODO: automatically exclude styles (also configurable) - local line = sub[i] - local old_style = styles[line.style] -- reinventing the wheel a bit here, since karaskel can do this with preproc_line_size (line.styleref), but it also adds loads of other crap we don't care about for the same functionality in the end, so ¯\_(ツ)_/¯ - 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) -end - -aegisub.register_macro(script_name, script_description, main) diff --git a/macros/chapters.lua b/macros/chapters.lua deleted file mode 100644 index 0dab8bd..0000000 --- a/macros/chapters.lua +++ /dev/null @@ -1,80 +0,0 @@ -script_name = "Chapter Generator" -script_description = "Makes XML chapters for matroska." -script_author = "garret" -script_version = "2.0.0" - -language = "eng" -language_ietf = "en" - -function ms_to_human(start) -- From Significance - local timecode=math.floor(start/1000) - local tc1=math.floor(timecode/60) - local tc2=timecode%60 - local tc3=start%1000 - local tc4="00" - if tc2==60 then tc2=0 tc1=tc1+1 end - if tc1>119 then tc1=tc1-120 tc4="02" end - if tc1>59 then tc1=tc1-60 tc4="01" end - if tc1<10 then tc1="0"..tc1 end - if tc2<10 then tc2="0"..tc2 end - if tc3<100 then tc3="0"..tc3 end - linetime=tc4..":"..tc1..":"..tc2.."."..tc3 - if linetime=="00:00:00.00" then linetime="00:00:00.033" end - return linetime -end - -function get_sane_path() - script_path = aegisub.decode_path("?script") - audio_path = aegisub.decode_path("?audio") - video_path = aegisub.decode_path("?video") - if script_path ~= "?script" then - return script_path - elseif video_path ~= "?video" then - return video_path - elseif audio_path ~= "?audio" then - return audio_path - else - return "" - end -end - -function get_user_path(default_dir) - local path = aegisub.dialog.save("Save Chapter File", default_dir, "chapters.xml", "XML files|*.xml|All Files|*", false) - return path -end - -function main(sub) - local times = {} - local names = {} - for i=1,#sub do - local line = sub[i] - if line.class == "dialogue" then - local fx = line.effect - if fx:match("[Cc]hapter") or fx:match("[Cc]hptr") or fx:match("[Cc]hap") then - line.comment = true - table.insert(times, line.start_time) - table.insert(names, line.text) - sub[i] = line - end - end - end - aegisub.set_undo_point(script_name) - local chapters = "\n\n\n \n" - for j, k in ipairs(times) do - local humantime = ms_to_human(k) - local name = names[j] - chapters = chapters.." \n "..humantime.."\n \n "..name.."\n "..language_ietf.."\n "..language.."\n \n \n" - end - chapters = chapters.." \n" - sane_path = get_sane_path() - path = get_user_path(sane_path) - if path ~= nil then - local chapfile = io.open(path, "w") - chapfile:write(chapters) - chapfile:close() - else - aegisub.cancel() - end -end - -aegisub.register_macro(script_name, script_description, main) diff --git a/macros/dupe-and-comment.lua b/macros/dupe-and-comment.lua deleted file mode 100644 index 97b71dd..0000000 --- a/macros/dupe-and-comment.lua +++ /dev/null @@ -1,33 +0,0 @@ -script_name="Dupe and Comment" -script_description="Copies a line and comments out the original." -script_author = "garret" -script_version = "2021-04-11" -include("utils.lua") --- i like seeing the original while editing, and being able to go back to it easily - -function comment(subs, sel) - for i=#sel,1,-1 do - local line=subs[sel[i]] - local dupe = util.copy(line) - line.comment = false -- going to edit it, so we probably want to see it on the video - dupe.comment = true -- this is the actual original one - subs.insert(sel[i]+1,dupe) -- putting it on the next line so i don't have to change line - end - aegisub.set_undo_point(script_name) -end - -function undo(subs, sel) - for i=#sel,1,-1 do - local edit=subs[sel[i]] - local original=subs[sel[i]+1] - if edit.comment == false and original.comment == true then - original.comment = false - subs[sel[i]+1] = original - subs.delete(sel[i]) - end - end - aegisub.set_undo_point("Undo "..script_name) -end - -aegisub.register_macro(script_name.."/Do", script_description, comment) -aegisub.register_macro(script_name.."/Undo", "Deletes selected line and restores the original", undo) diff --git a/macros/garret.a-b.lua b/macros/garret.a-b.lua new file mode 100644 index 0000000..aa0ccd9 --- /dev/null +++ b/macros/garret.a-b.lua @@ -0,0 +1,45 @@ +script_name = "A-B" +script_description = "makes checking pre-timing possible." +script_author = "garret" +script_version = "2.1.0" + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + } +end + +function switch_number(i) + if i == "a" then + return "b" + elseif i == "b" then + return "a" + end +end + +function main(sub, sel) + local i = "a" + for si,li in ipairs(sel) do + line = sub[li] + if line.actor == "" then + indicator = i + else + indicator = line.actor.." "..i + end + if line.text == "" then + line.text = indicator + elseif line.text:gsub("{[^}]-}","") == "" then + line.text = indicator.." "..line.text + end + sub[li] = line + i = switch_number(i) + end + aegisub.set_undo_point(script_name) +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/garret.append-comment.lua b/macros/garret.append-comment.lua new file mode 100644 index 0000000..9f3ec79 --- /dev/null +++ b/macros/garret.append-comment.lua @@ -0,0 +1,47 @@ +script_name = "Append Comment" +script_description = "{ts do all the work pls kthxbye}" +script_author = "garret" +script_version = "1.2.0" +script_namespace = "garret.append-comment" + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + } +end + +local function main(sub, sel) + dialog_config= + { + { + class="label", + x=0,y=0,width=1,height=1, + label="Comment:" + }, + { + class="edit",name="msg", + x=0,y=1,width=3,height=2, + value="" + } + } + if #sel == 1 then + table.insert(dialog_config, {class="label",x=0,y=3,width=1,height=1,label="if you're not using this for multiple lines \nyou may as well just type it out yourself"}) + end + button, results = aegisub.dialog.display(dialog_config) + if button ~= false then + for _, i in ipairs(sel) do + local line = sub[i] + line.text = line.text.." {"..results.msg.."}" + sub[i] = line + end + else + aegisub.cancel() + end +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/garret.chapters.lua b/macros/garret.chapters.lua new file mode 100644 index 0000000..826ca93 --- /dev/null +++ b/macros/garret.chapters.lua @@ -0,0 +1,103 @@ +script_name = "Chapter Generator" +script_description = "Makes XML chapters for matroska." +script_author = "garret" +script_version = "2.1.0" +script_namespace = "garret.chapters" + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +local simpleconf, config_dir + +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + { + {"garret.simpleconf", url="https://github.com/garret1317/aegisub-scripts",} + --feed="TODO"}, + } + } + simpleconf = depctrl:requireModules() + config_dir = depctrl.configDir +else + simpleconf = require 'garret.simpleconf' + config_dir = "?user/config" +end + +local config = simpleconf.get_config(aegisub.decode_path(config_dir.."/"..script_namespace..".conf"), {language = "eng", language_ietf = "en"}) + +function ms_to_human(start) -- From Significance + local timecode=math.floor(start/1000) + local tc1=math.floor(timecode/60) + local tc2=timecode%60 + local tc3=start%1000 + local tc4="00" + if tc2==60 then tc2=0 tc1=tc1+1 end + if tc1>119 then tc1=tc1-120 tc4="02" end + if tc1>59 then tc1=tc1-60 tc4="01" end + if tc1<10 then tc1="0"..tc1 end + if tc2<10 then tc2="0"..tc2 end + if tc3<100 then tc3="0"..tc3 end + linetime=tc4..":"..tc1..":"..tc2.."."..tc3 + if linetime=="00:00:00.00" then linetime="00:00:00.033" end + return linetime +end + +function get_sane_path() + script_path = aegisub.decode_path("?script") + audio_path = aegisub.decode_path("?audio") + video_path = aegisub.decode_path("?video") + if script_path ~= "?script" then + return script_path + elseif video_path ~= "?video" then + return video_path + elseif audio_path ~= "?audio" then + return audio_path + else + return "" + end +end + +function get_user_path(default_dir) + local path = aegisub.dialog.save("Save Chapter File", default_dir, "chapters.xml", "XML files|*.xml|All Files|*", false) + return path +end + +function main(sub) + aegisub.log(config_dir) + local times = {} + local names = {} + for i=1,#sub do + local line = sub[i] + if line.class == "dialogue" then + local fx = line.effect + if fx:match("[Cc]hapter") or fx:match("[Cc]hptr") or fx:match("[Cc]hap") then + line.comment = true + table.insert(times, line.start_time) + table.insert(names, line.text) + sub[i] = line + end + end + end + aegisub.set_undo_point(script_name) + local chapters = "\n\n\n \n" + for j, k in ipairs(times) do + local humantime = ms_to_human(k) + local name = names[j] + chapters = chapters.." \n "..humantime.."\n \n "..name.."\n "..config.language_ietf.."\n "..config.language.."\n \n \n" + end + chapters = chapters.." \n" + sane_path = get_sane_path() + path = get_user_path(sane_path) + if path ~= nil then + local chapfile = io.open(path, "w") + chapfile:write(chapters) + chapfile:close() + else + aegisub.cancel() + end +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua new file mode 100644 index 0000000..c74d6c6 --- /dev/null +++ b/macros/garret.dupe-and-comment.lua @@ -0,0 +1,55 @@ +script_name="Dupe and Comment" +script_description="Copies a line and comments out the original.\nbecause i like seeing the original while editing, and being able to go back to it easily" +script_author = "garret" +script_version = "2.1.0" +script_namespace = "garret.dupe-and-comment" + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +local util +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + {"aegisub.util"} + } + util = depctrl:requireModules() +else + util = require 'aegisub.util' +end + +function comment(subs, sel) + for i=#sel,1,-1 do + local line=subs[sel[i]] + local dupe = util.copy(line) + line.comment = false -- going to edit it, so we probably want to see it on the video + dupe.comment = true -- this is the actual original one + subs.insert(sel[i]+1,dupe) -- putting it on the next line so i don't have to change line + end + aegisub.set_undo_point(script_name) +end + +function undo(subs, sel) + for i=#sel,1,-1 do + local edit=subs[sel[i]] + local original=subs[sel[i]+1] + if edit.comment == false and original.comment == true then + original.comment = false + subs[sel[i]+1] = original + subs.delete(sel[i]) + end + end + aegisub.set_undo_point("Undo "..script_name) +end + +local macros = { + {"Do", script_description, comment}, + {"Undo","Deletes selected line and restores the original", undo} +} +if haveDepCtrl then + depctrl:registerMacros(macros) +else + for _,macro in ipairs(macros) do + local name, desc, fun = unpack(macro) + aegisub.register_macro(script_name .. '/' .. name, desc, fun) + end +end +-- i trust what petzku from the cartel has to say on adding multiple macros with depctrl diff --git a/macros/garret.karaoke2alpha.lua b/macros/garret.karaoke2alpha.lua new file mode 100644 index 0000000..51ff0c5 --- /dev/null +++ b/macros/garret.karaoke2alpha.lua @@ -0,0 +1,70 @@ +script_name = "K-Timing -> Alpha Timing" +script_description = "makes doing alpha timing significantly easier by getting rid of the part where you do alpha timing." +script_author = "garret" +script_version = "1.1.0" +script_namespace = "garret.karaoke2alpha" + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +local util +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + {"aegisub.util"} + } + util = depctrl:requireModules() +else + util = require 'aegisub.util' +end + +function get_visible(parsed_line, index) + local res = "" + for i=1,index do -- for every syl up to the current one + res = res..parsed_line[i].text -- add to the result + end + return res +end + +function get_invisible(parsed_line, index) + local res = "" + for i=index+1,#parsed_line do -- for every syl from the next one to the end + res = res..parsed_line[i].text -- add to result + end + return res +end + +function main(sub, sel) + for x=#sel,1,-1 do + local line=sub[sel[x]] + local parsed = aegisub.parse_karaoke_data(line) -- magic function that gets all the stuff about the karaoke + for i=1,#parsed do -- for every syl in the karaoke + visible = get_visible(parsed, i) + invisible = get_invisible(parsed, i) + if invisible ~= "" then -- if there's still invisible stuff left + text = visible.."{\\alpha&HFF&}"..invisible -- add an alpha tag and slap the invisible stuff on the end + else -- if it's all visible + text = visible -- don't need the alpha any more + end + local syl = parsed[i] + local new = util.copy(line) + new.text = text -- make a new line for this syl + -- set line start time + new.start_time = syl.start_time + line.start_time -- just the syl on its own returns the offset from the line + -- set line end time + if i ~= #parsed then -- if there's still invisible stuff left + new.end_time = syl.end_time + line.start_time -- end time is the syl's + else + new.end_time = line.end_time -- end time is the whole line's (i don't think this actually makes a difference but may as well) + end + sub.insert(sel[x] + i,new) -- add new lines (+1 line for first syl, +2 for 2nd syl, etc) + end + line.comment = true -- don't want to see the karaoke any more + sub[sel[x]]=line + end + aegisub.set_undo_point(script_name) +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/garret.restyler.lua b/macros/garret.restyler.lua new file mode 100644 index 0000000..1c5dc9f --- /dev/null +++ b/macros/garret.restyler.lua @@ -0,0 +1,74 @@ +script_name="Restyler" +script_description="become a fansubber with a click of a button" +script_author = "garret" +script_version = "2.1.0" +script_namespace = "garret.restyler" + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +local simpleconf +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + {"karaskel", "cleantags", {"garret.simpleconf", url="https://github.com/garret1317/aegisub-scripts"}, } + } + kara, clean, simpleconf = depctrl:requireModules() + config_dir = depctrl.configDir +else + include("karaskel.lua") + include("cleantags.lua") + simpleconf = require 'garret.simpleconf' + config_dir = "?user/config" +end + +local config = simpleconf.get_config(aegisub.decode_path(config_dir.."/"..script_namespace..".conf"), {new_style = "Default"}) + +-- TODO: detect pre-existing inline 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 align ~= nil then + txt="{\\an"..align.."}"..txt + end + txt = cleantags(txt) + return txt +end + +function get_new(old, new) + local i = nil + if old ~= new then + i = old + end + return i +end + +function main(sub, sel) + local _, styles = karaskel.collect_head(sub, false) + --local config.new_style = "Default" -- the one we'll be changing stuff to - TODO: configurable + local new_style = styles[config.new_style] + for h, i in ipairs(sel) do + -- TODO: automatically exclude styles (also configurable) + local line = sub[i] + local old_style = styles[line.style] -- reinventing the wheel a bit here, since karaskel can do this with preproc_line_size (line.styleref), but it also adds loads of other crap we don't care about for the same functionality in the end, so ¯\_(ツ)_/¯ + local italic = get_new(old_style.italic, new_style.italic) + local align = get_new(old_style.align, new_style.align) + line.style = config.new_style + line.text = add_tags(line.text, italic, align) + sub[i] = line + end + aegisub.set_undo_point(script_name) +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/garret.select-comments.lua b/macros/garret.select-comments.lua new file mode 100644 index 0000000..6f0cf81 --- /dev/null +++ b/macros/garret.select-comments.lua @@ -0,0 +1,33 @@ +script_name = "Select comments" +script_description = "Select all commented lines" +script_author = "garret" +script_version = "1.1.0" +script_namespace = "garret.select-comments" +-- faster than doing Subtitle -> Select Lines etc (at least in terms of button-presses) + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + } +end +-- this does not need depctrl at all lol +-- just for consistency's sake really + +function main(sub) + sel = {} + for i=1,#sub do + line=sub[i] + if line.comment == true then + table.insert(sel, i) + end + end + aegisub.set_undo_point(script_name) + return sel +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/karaoke2alpha.lua b/macros/karaoke2alpha.lua deleted file mode 100644 index 1f34da0..0000000 --- a/macros/karaoke2alpha.lua +++ /dev/null @@ -1,68 +0,0 @@ -script_name="K-Timing -> Alpha Timing" -script_description="makes doing alpha timing significantly easier by getting rid of the part where you do alpha timing." -script_author = "garret" -script_version = "1.0.1" -include("utils.lua") - --- logging stuff, for testing ---[[inspect = require 'inspect' -- luarocks install inspect -function log(level, msg) - if type(level) ~= "number" then -- if no actual level provided - msg = level -- set the non-level as the message - level = 4 -- set log level - i'm using this for debugging, so 4 is relatively sane imo - end - if type(msg) == "table" then - msg = inspect(msg) -- actually see what's in the table - end - aegisub.log(level, tostring(msg) .. "\n") -end]] --- i should really put this stuff in a separate file or something but cba - -function get_visible(parsed_line, index) - local res = "" - for i=1,index do -- for every syl up to the current one - res = res..parsed_line[i].text -- add to the result - end - return res -end - -function get_invisible(parsed_line, index) - local res = "" - for i=index+1,#parsed_line do -- for every syl from the next one to the end - res = res..parsed_line[i].text -- add to result - end - return res -end - -function main(sub, sel) - for x=#sel,1,-1 do - local line=sub[sel[x]] - local parsed = aegisub.parse_karaoke_data(line) -- magic function that gets all the stuff about the karaoke - for i=1,#parsed do -- for every syl in the karaoke - visible = get_visible(parsed, i) - invisible = get_invisible(parsed, i) - if invisible ~= "" then -- if there's still invisible stuff left - text = visible.."{\\alpha&HFF&}"..invisible -- add an alpha tag and slap the invisible stuff on the end - else -- if it's all visible - text = visible -- don't need the alpha any more - end - local syl = parsed[i] - local new = util.copy(line) - new.text = text -- make a new line for this syl - -- set line start time - new.start_time = syl.start_time + line.start_time -- just the syl on its own returns the offset from the line - -- set line end time - if i ~= #parsed then -- if there's still invisible stuff left - new.end_time = syl.end_time + line.start_time -- end time is the syl's - else - new.end_time = line.end_time -- end time is the whole line's (i don't think this actually makes a difference but may as well) - end - sub.insert(sel[x] + i,new) -- add new lines (+1 line for first syl, +2 for 2nd syl, etc) - end - line.comment = true -- don't want to see the karaoke any more - sub[sel[x]]=line - end - aegisub.set_undo_point(script_name) -end - -aegisub.register_macro(script_name, script_description, main) diff --git a/macros/select-comments.lua b/macros/select-comments.lua deleted file mode 100644 index c0c281d..0000000 --- a/macros/select-comments.lua +++ /dev/null @@ -1,18 +0,0 @@ -script_name = "Select Comments" -script_description = "Selects all commented lines" -script_author = "garret" -script_version = "1.0.1" - -function main(sub, sel) - sel = {} - for i=1,#sub do - line=sub[i] - if line.comment == true then - table.insert(sel, i) - end - end - aegisub.set_undo_point(script_name) - return sel -end - -aegisub.register_macro(script_name, script_description, main) -- cgit v1.2.3-70-g09d2