initial commit

This commit is contained in:
garret 2021-04-05 16:03:24 +01:00
commit 9c2c5b5424
6 changed files with 277 additions and 0 deletions

44
README.md Normal file
View File

@ -0,0 +1,44 @@
# garret's shitty aegisub scripts
Aegisub automation scripts I've written.
Probably only useful to me.
----
## Script List
### A-B
Makes checking pre-timing possible by putting some text in the lines (the actor name, and `a` or `b` (hence the name))
**Caution: Overwrites every selected line!**
### Audio Clipper
Extracts audio from the selected line(s), like the create audio clip button.
Unlike the create audio clip button, it can copy the audio stream.
Also, if you select multiple lines, it'll make separate clips for each, not one long one.
**Needs ffmpeg. Can be slow.**
### Blur Fade
Makes fade with blur.
Blurs out lines with the effect `blurout`, and blurs in lines with the effect `blurin`.
For fancy fade effects. (i.e, when the whole scene blurs out until it's invisible, as a transition)
### Dupe and Comment
Duplicates a line and comments out the original.
I like seeing the original line while editing, and being able to go back to it easily if my edit was crap.
### Em-dash
Appends an Em-dash (`—`) to the selected line(s).
Replaces `--` with `—`.
I do not have an em-dash key on my keyboard.

21
a-b.lua Normal file
View File

@ -0,0 +1,21 @@
script_name = "A-B"
script_description = "makes checking pre-timing possible.\nCAUTION: Overwrites every selected line!"
script_author = "garret"
script_version = "2021-04-03"
function main(sub, sel)
local i = 0
for si,li in ipairs(sel) do
line = sub[li]
if i == 0 then
line.text = line.actor.." a"
i = 1
elseif i == 1 then
line.text = line.actor.." b"
i = 0
end
sub[li] = line
end
aegisub.set_undo_point(script_name)
return sel
end
aegisub.register_macro(script_name, script_description, main)

122
audio-clipper.lua Normal file
View File

@ -0,0 +1,122 @@
script_name = "Audio Clipper"
script_description = "Extracts audio from the selected line(s).\nNeeds ffmpeg."
script_author = "garret"
script_version = "2021-04-04"
a = aegisub
ok = {"OK"}, {close = "OK"} -- just an "OK" button, for error messages.
function get_vid_dir()
local dir = a.decode_path("?video")
if dir == "?video" then -- if there is not, in fact, a video
return nil
else
return dir
end
end
function get_vid()
local vid = a.project_properties().video_file
if vid == "" then
return nil
else
return vid
end
end
function get_format(copy, format, custom)
if copy == true then -- if we do want to copy
if format == "" then -- format is the thing from the dropdown
a.dialog.display({{class = "label", label = "Need a format!"}}, ok)
a.cancel()
elseif format == "AAC" then -- these are the most common audio formats i've seen
return "m4a"
elseif format == "Opus" then
return "opus"
elseif format == "FLAC" then
return "flac" elseif format == "Custom" then -- but I am not all-knowing, so you can put your own
return custom
end
else -- if we don't want to copy (i.e. we've pressed "Just make it FLAC")
return "flac"
end
end
function make_out_path(out_path)
if out_path == "" then
a.dialog.display({{class = "label", label = "Need an output path!"}}, ok)
a.cancel()
end
os.execute('mkdir "'..out_path..'"') -- if it doesn't exist, it makes it, and if it does, it errors.
return out_path -- either way, the path now exists. (probably)
end -- I imagine there's a mkdir thing in lua that's better, but this works fine, so unless it breaks, i'll keep it like this.
function extract_audio(in_path, start_time, end_time, out_path, name, extension, copy)
if copy == true then
os.execute('ffmpeg -i "'..in_path..'" -codec copy -vn -ss '..start_time..'ms -to '..end_time..'ms "'..out_path..name..'.'..extension..'" -y')
-- takes the video as input, copies the streams, but doesn't include video. sets it to start at the start of the selection, and end at the end of it. outputs to our chosen out path with our chosen name and extension. overwrites anything with the same name.
else
os.execute('ffmpeg -i "'..in_path..'" -vn -ss '..start_time..'ms -to '..end_time..'ms "'..out_path..name..'.'..extension..'" -y')
-- same as above, but doesn't copy the stream (transcodes to flac)
end
end
function loop(subs, sel, in_path, out_path, extension, copy, delay)
a.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 a.progress.is_cancelled() then -- if you press the cancel button
a.cancel() -- it stops (mind-blowing, i know)
end
a.progress.set(progress)
local line = subs[i]
local start_time = line.start_time + delay
local end_time = line.end_time + delay
a.progress.task("Extracting line "..x)
extract_audio(in_path, start_time, end_time, out_path, x, extension, copy)
progress = progress + progress_increment
end
a.progress.set(100) -- in case it didn't reach 100 on its own
end
function gui(subs, sel)
local in_path = get_vid()
local out_path = get_vid_dir()
if in_path == nil or out_path == nil then -- if no video is loaded
in_path = "No video loaded. Specify a path."
out_path = in_path -- both the same error message
else
out_path = out_path.."/audioclipper_output/" -- make the out path the one we actually want
end
local get_input={{class="label",x=0,y=0,label="Video'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\""},{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 = a.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
a.cancel()
elseif pressed == "OK" then
local do_copy = true
elseif pressed == "Just make it FLAC" then
local do_copy = false
end
local extension = get_format(do_copy, results.format, results.custom) -- gets file extension
local delay = results.delay
in_path = results.in_path
out_path = make_out_path(results.out_path)
loop(subs, sel, in_path, out_path, extension, copy, delay)
end
function non_gui(subs, sel) -- no gui, so you can bind it to a hotkey
local vid = get_vid()
if vid == nil then
a.dialog.display({{class = "label", label = "Need a video!\nSpecify one in the GUI, or load one in aegisub."}}, ok)
else
loop(subs, sel, get_vid(), make_out_path(get_vid_dir().."/audioclipper_output/"), 'flac', false, 0)
end
-- sets sane defaults (takes the audio from the video file, and outputs to /the/video/dir/audioclipper_output/. transcodes to flac. no delay)
end
a.register_macro(script_name, script_description, gui)
a.register_macro(": Non-GUI macros :/"..script_name..": Just make it FLAC", script_description, non_gui) -- same section as unanimated's scripts

44
blur-fade.lua Normal file
View File

@ -0,0 +1,44 @@
script_name="Blur Fade"
script_description="Makes fade with blur."
script_author="garret"
script_version="2021-04-05"
include("utils.lua")
-- TODO: add proper fade as well
function l(i)
aegisub.log(i)
aegisub.log("\n")
end -- for debugging
function make_lines(sub, sel, i, fill, bord, shad)
local line=sub[sel[i]]
line.effect = ""
local text = line.text
local fill_layer = util.copy(line) -- copy
local bord_layer = util.copy(line) -- the
local shad_layer = util.copy(line) -- line
fill_layer.layer=2 -- set
bord_layer.layer=1 -- correct
shad_layer.layer=0 -- layers
fill_layer.text = fill..fill_layer.text.." {fill}" -- add
bord_layer.text = bord..bord_layer.text.." {bord}" -- the
shad_layer.text = shad..shad_layer.text.." {shad}" -- tags
sub[sel[i]] = fill_layer -- put
sub.insert(sel[i]+1,bord_layer) -- in
sub.insert(sel[i]+2,shad_layer) -- script
end
function main(sub, sel) -- TODO: make code less shit
for i=#sel,1,-1 do
local line=sub[sel[i]]
if line.effect == "blurin" then
-- make_lines(sub, sel, i, "in fill ", "in bord ", "in shad ")
make_lines(sub, sel, i, "{\\blur100\\bord0\\shad0\\t(\\blur0)}", "{\\blur100\\t(\\blur0)\\1a&FF&\\3a&FF&\\shad0.01}", "{\\blur100\\shad1.5\\1aFF\\bord0\\t(\\blur0)}")
elseif line.effect == "blurout" then
-- make_lines(sub, sel, i, "out fill ", "out bord ", "out shad ")
make_lines(sub, sel, i, "{\\bord0\\shad0\\t(\\blur100)}", "{\\t(\\blur100)\\1a&FF&\\3a&FF&\\shad0.01}", "{\\shad1.5\\1aFF\\bord0\\t(\\blur100)}")
end
end
end
aegisub.register_macro(script_name, script_description, main)

19
dupe-and-comment.lua Normal file
View File

@ -0,0 +1,19 @@
script_name="Dupe and Comment"
script_description="Copies a line and comments out the original."
script_author = "garret"
script_version = "2021-04-05"
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
aegisub.register_macro(script_name, script_description, comment)

27
em-dash.lua Normal file
View File

@ -0,0 +1,27 @@
script_name = "Em-dash"
script_description = "I do not have an em-dash key on my keyboard"
script_author = "garret"
script_version = "2021-04-05"
em = ""
function append(sub, sel)
for si, li in ipairs(sel) do
local line = sub[li]
line.text = line.text..em
sub[li] = line
end
aegisub.set_undo_point(script_name)
end
function replace(sub, sel)
for si, li in ipairs(sel) do
local line = sub[li]
local text = sub[li].text
text = text:gsub("%-%-",em)
line.text=text
sub[li] = line
end
aegisub.set_undo_point(script_name)
end
aegisub.register_macro(script_name.."/Append", "Appends an Em-dash to the selected line(s)", append)
aegisub.register_macro(script_name.."/Replace", "Replaces -- with "..em, replace)