forked from darkstar901/Aegisub-automation-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerspective shortcut.lua
62 lines (55 loc) · 1.78 KB
/
Perspective shortcut.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
script_name = "Perspective.py shortcut"
script_description = "Pulls data through perspective.py from Zeght https://github.com/TypesettingTools/Perspective"
script_author = "dark_star90"
script_version = "1.1"
submenu="_darkis crappy scripts"
function Perspective_GUI(subs,sel,act)
GUI={
{x=0,y=0,class="label",label=script_name.." v"..script_version},
}
P,res=aegisub.dialog.display(GUI,{"Apply first","Apply second","Kill Perspective","Cancel"},{ok='Apply first',cancel='Cancel'})
if P == "Apply first" then
kill_perspective()
read_output()
tags=lines[3]
end
if P == "Apply second" then
kill_perspective()
read_output()
tags=lines[6]
end
if P == "Kill Perspective" then
kill_perspective()
tags=""
end
line.text=line.text:gsub("\\i?clip%b()","\\clip%(m "..clip.."%)"..tags)
return sel
end
function killtag(tag,t) t=t:gsub("\\"..tag.."[%d%.%-]*([\\}])","%1") return t end
function kill_perspective()
line.text=killtag("frz",line.text)
line.text=killtag("frx",line.text)
line.text=killtag("fry",line.text)
line.text=line.text:gsub("\\org%b()","")
end
function read_output()
konf=io.open(f_out)
lines = {}
for line in konf:lines() do
table.insert(lines, line)
end
io.close(konf)
end
function perspective_clip(subs,sel)
f=aegisub.decode_path("?user").."\\automation\\autoload\\perspective.py"
f_out=aegisub.decode_path("?user").."\\Aegisub_perspective.conf"
--f_out=aegisub.decode_path("?script").."\\Aegisub_perspective.conf"
for z,i in ipairs(sel) do
line=subs[i]
clip=line.text:match("clip%(m ([%d%.%a%s%-]+)")
os.execute("py ".."\""..f.."\" \""..clip.."\">\""..f_out.."\"")
Perspective_GUI()
subs[i]=line
end
end
aegisub.register_macro(submenu.."/"..script_name,script_description,perspective_clip)