后知后觉:没想到chatgpt还能写aegi的Lua脚本,写得挺好的
本帖最后由 leonvent 于 2025-8-6 08:49 编辑按照自己喜好改一点字幕,像删除双语字幕中的外语,给样式对应字幕行增加语句,或者删除什么的。
例如想要一个选中样式,自动删除对应的字幕行什么的
之前做这类事情扔给excel/记事本,用正则这一类的处理
不过想想很多年前有看到这类的脚本自动化,跳个对话框更快,但又懒得去找了。
找AI写一个,没想到还真能写
script_name = "选择删除样式及字幕"
script_description = "弹出对话框,选择你想删除的样式,然后自动删除这些样式和对应的字幕行"
script_author = "ChatGPT"
script_version = "1.3"
include("karaskel.lua")
function get_all_styles(subs)
local style_set = {}
for i = 1, #subs do
local line = subs
if line.class == "style" then
table.insert(style_set, line.name)
end
end
return style_set
end
function build_dialog(style_names)
local dialog = {
{class = "label", label = "Select styles to delete (will also remove associated dialogue lines)", x = 0, y = 0, width = 2, height = 1}
}
for i, name in ipairs(style_names) do
table.insert(dialog, {
class = "checkbox",
name = name,
label = name,
value = false,
x = 0,
y = i,
width = 2,
height = 1
})
end
return dialog
end
function delete_selected_styles(subs, sel)
local all_styles = get_all_styles(subs)
if #all_styles == 0 then
aegisub.dialog.display({{class = "label", label = "No styles found.", x = 0, y = 0}}, {"OK"})
return
end
local dialog = build_dialog(all_styles)
local buttons, result = aegisub.dialog.display(dialog, {"Delete", "Cancel"})
if buttons ~= "Delete" then return end
local to_delete = {}
for _, name in ipairs(all_styles) do
if result then
to_delete = true
end
end
local i = #subs
while i > 0 do
local line = subs
if line.class == "style" and to_delete then
subs:delete(i)
elseif line.class == "dialogue" and to_delete then
subs:delete(i)
end
i = i - 1
end
end
aegisub.register_macro("选择删除样式及字幕", "选择样式并删除样式及其字幕行", delete_selected_styles)
其实 Aegisub 自带根据样式选择所有行的功能( 本帖最后由 leonvent 于 2025-8-6 08:45 编辑
op200 发表于 2025-8-6 04:06
其实 Aegisub 自带根据样式选择所有行的功能(
我太懒了,剪贴板里重复按了几遍,正则又忘了想不起来,找AI回忆,但想想弄个多选框好像可以做更多复杂的事情,没想到AI能写lua 可惜现阶段gemini和gpt都写不出卡拉ok模板 感觉aeg里面的写法ai死活都理解不了
页:
[1]