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/a-b.lua b/macros/garret.a-b.lua similarity index 69% rename from macros/a-b.lua rename to macros/garret.a-b.lua index 994361f..aa0ccd9 100644 --- a/macros/a-b.lua +++ b/macros/garret.a-b.lua @@ -1,7 +1,14 @@ script_name = "A-B" script_description = "makes checking pre-timing possible." script_author = "garret" -script_version = "2021-07-10" +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 @@ -31,4 +38,8 @@ function main(sub, sel) aegisub.set_undo_point(script_name) end -aegisub.register_macro(script_name, script_description, main) +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/append-comment.lua b/macros/garret.append-comment.lua similarity index 65% rename from macros/append-comment.lua rename to macros/garret.append-comment.lua index 47d3feb..9f3ec79 100644 --- a/macros/append-comment.lua +++ b/macros/garret.append-comment.lua @@ -1,9 +1,17 @@ script_name = "Append Comment" script_description = "{ts do all the work pls kthxbye}" script_author = "garret" -script_version = "1.1.2" +script_version = "1.2.0" +script_namespace = "garret.append-comment" -function main(sub, sel) +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +if haveDepCtrl then + depctrl = DependencyControl { + --feed="TODO", + } +end + +local function main(sub, sel) dialog_config= { { @@ -13,7 +21,7 @@ function main(sub, sel) }, { class="edit",name="msg", - x=0,y=1,width=1,height=2, + x=0,y=1,width=3,height=2, value="" } } @@ -32,4 +40,8 @@ function main(sub, sel) end end -aegisub.register_macro(script_name, script_description, main) +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/chapters.lua b/macros/garret.chapters.lua similarity index 70% rename from macros/chapters.lua rename to macros/garret.chapters.lua index 0dab8bd..826ca93 100644 --- a/macros/chapters.lua +++ b/macros/garret.chapters.lua @@ -1,10 +1,28 @@ script_name = "Chapter Generator" script_description = "Makes XML chapters for matroska." script_author = "garret" -script_version = "2.0.0" +script_version = "2.1.0" +script_namespace = "garret.chapters" -language = "eng" -language_ietf = "en" +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) @@ -44,6 +62,7 @@ function get_user_path(default_dir) end function main(sub) + aegisub.log(config_dir) local times = {} local names = {} for i=1,#sub do @@ -63,7 +82,7 @@ function main(sub) 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" + 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() @@ -77,4 +96,8 @@ function main(sub) end end -aegisub.register_macro(script_name, script_description, main) +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua similarity index 50% rename from macros/dupe-and-comment.lua rename to macros/garret.dupe-and-comment.lua index 97b71dd..c74d6c6 100644 --- a/macros/dupe-and-comment.lua +++ b/macros/garret.dupe-and-comment.lua @@ -1,9 +1,20 @@ script_name="Dupe and Comment" -script_description="Copies a line and comments out the original." +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 = "2021-04-11" -include("utils.lua") --- i like seeing the original while editing, and being able to go back to it easily +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 @@ -29,5 +40,16 @@ function undo(subs, sel) 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) +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/karaoke2alpha.lua b/macros/garret.karaoke2alpha.lua similarity index 70% rename from macros/karaoke2alpha.lua rename to macros/garret.karaoke2alpha.lua index 1f34da0..51ff0c5 100644 --- a/macros/karaoke2alpha.lua +++ b/macros/garret.karaoke2alpha.lua @@ -1,22 +1,20 @@ -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_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") +script_version = "1.1.0" +script_namespace = "garret.karaoke2alpha" --- 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 +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 = "" @@ -65,4 +63,8 @@ function main(sub, sel) aegisub.set_undo_point(script_name) end -aegisub.register_macro(script_name, script_description, main) +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/macros/become-fansubber.lua b/macros/garret.restyler.lua similarity index 63% rename from macros/become-fansubber.lua rename to macros/garret.restyler.lua index 1dfdb43..1c5dc9f 100644 --- a/macros/become-fansubber.lua +++ b/macros/garret.restyler.lua @@ -1,10 +1,26 @@ script_name="Restyler" script_description="become a fansubber with a click of a button" script_author = "garret" -script_version = "2.0.0" +script_version = "2.1.0" +script_namespace = "garret.restyler" -include("karaskel.lua") -include("cleantags.lua") +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() @@ -36,19 +52,23 @@ 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] + --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 = new_style_name + line.style = config.new_style 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) +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/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)