-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzmsub.lyric_sort_by_lang.lua
More file actions
40 lines (36 loc) · 1.19 KB
/
zmsub.lyric_sort_by_lang.lua
File metadata and controls
40 lines (36 loc) · 1.19 KB
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
local tr = aegisub.gettext
script_name = tr("织梦.歌词排序.按语言拆分")
script_description = tr("选中按时间交错排序的双字台词,会把台词按语言拆为两块")
script_author = "谢耳朵w"
script_version = "0.1"
function table.slice(tbl, first, last, step)
local sliced = {}
for i = first or 1, last or #tbl, step or 1 do
sliced[#sliced+1] = tbl[i]
end
return sliced
end
function sort_by_lang(subs, sels, active)
if #sels % 2 ~= 0 then
aegisub.debug.out("选中行数应为偶数!")
return
end
-- 注意下标从1开始,第一行为奇数行
-- odd_inds = table.slice(sels, 1, #sels, 2)
even_inds = table.slice(sels, 2, #sels, 2)
even_lines = {}
-- store even lines then remove them from subs
for i, ind in ipairs(even_inds) do
table.insert(even_lines, subs[ind])
end
subs.delete(even_inds)
-- append them at last
for i = 1, #sels/2 do
aegisub.progress.set(i * 100 / #sels/2)
newind = sels[#sels/2] + i
subs.insert(newind, even_lines[i])
end
aegisub.set_undo_point(script_name)
return
end
aegisub.register_macro(script_name, script_description, sort_by_lang)