-
Notifications
You must be signed in to change notification settings - Fork 3
/
cpscalc.lua
98 lines (82 loc) · 2.07 KB
/
cpscalc.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
script_name = "CPS Calculator"
script_description = "Calculates characters per second for lines."
script_author = "Daiz"
script_version = "1.1.0"
-- warning character
local c = "*"
function pad(n,p)
n = ""..n
while n:len() < p do
n = "0"..n
end
return n
end
function repeat_text(text, times)
local res = ""
if times > 10 then times = 10 end
for i = 1, times do
res = res .. text
end
return res
end
function cps(subs, sel)
for i = 1, #subs do
if subs[i].class == "dialogue" then
local l = subs[i]
local t = l.text
local s = l.style
local proceed = false
if s:match("Default") then proceed = true end
if s:match("Alternative") then proceed = true end
if s:match("Overlap") then proceed = true end
if proceed then
-- clean up the line so only characters remain
t = t
:gsub("\\N","")
:gsub("\\n","")
:gsub("\\h","")
:gsub("[%.,%?!—–]","")
:gsub("{[^}]-}","")
:gsub(" ","")
local chars = t:len()
local seconds = (l.end_time - l.start_time) / 1000
local cps = math.floor((chars / seconds) + 0.5)
local res = "("..pad(cps,2)..")"
if cps > 18 then
res = res .. " (" .. repeat_text(c, cps - 18) .. ")"
end
l.effect = res
subs[i] = l
end
end
end
aegisub.set_undo_point("CPS Calculator")
end
function cleancps(subs, sel)
for i = 1, #subs do
if subs[i].class == "dialogue" then
local l = subs[i]
local t = l.text
local s = l.style
local proceed = false
if s:match("Default") then proceed = true end
if s:match("Alternative") then proceed = true end
if s:match("Overlap") then proceed = true end
if proceed then
l.effect = ""
subs[i] = l
end
end
end
aegisub.set_undo_point("Clean effect field")
end
aegisub.register_macro(
script_name,
script_description,
cps
)
aegisub.register_macro(
"Clean effect field",
"Cleans the effect field used by CPS Calculator.",
cleancps
)