首页 > 其他分享 >1. 注册Aegisub插件

1. 注册Aegisub插件

时间:2022-10-25 17:22:24浏览次数:39  
标签:脚本 插件 name script tags 1.3 注册 aegisub Aegisub

1 注册 Register

注:本系列不包括lua基础,您需要掌握基础的Aegisub模板编写能力以及掌握基础的Lua知识后进行学习

1.1 注册

aegisub.register_macro(name, description, main_function[, checked_fucntion])

将这行代码敲在一个lua文件中,放在[aegisub\automation\autoload]目录下就注册一个自动化插件。


1.2 参数解释

  • name: 脚本名,在aegisub的自动化显示的名称
  • description:脚本简介,将鼠标浮动在自动化上就会在左下角输出这个简介,通常用来对脚本的用处进行简单的介绍。
  • main_function:运行这个脚本后会调用的主函数,手册上讲这个函数必须是一个宏处理函数(macro processing function),这个下一节会进行解释。
  • check_function:很少用到的一个可选参数,你只可以在 kara-templater.lua 这个文件,也就是卡拉ok模板执行器主体脚本中看到它使用了这个参数。这个参数的作用是进行一个逻辑判断判断脚本是否运行:当返回结果是false时,这个脚本将不会被执行。

1.3 注册拓展

#例1.3-1: kara-templater的注册模块
local tr = aegisub.gettext

script_name = tr"Karaoke Templater"
script_description = tr"Macro and export filter to apply karaoke effects using the template language"
script_author = "Niels Martin Hansen"
script_version = "2.1.7"

--------------------------------------------

--[[
<主函数体>
--]]

--------------------------------------------
aegisub.register_macro(tr"Apply karaoke template", tr"Applies karaoke effects from templates", macro_apply_templates, macro_can_template)

通常来说,像例1.3-1一样的注册模块才是我们写的注册模块,开头注明脚本信息,结尾进行注册。当然,kara-templater不是很具体,我们再看另一个例:

#例1.3-2: strip-tags的主体模块
local tr = aegisub.gettext

script_name = tr("Strip tags")
script_description = tr("Remove all override tags from selected lines")
script_author = "Thomas Goyne"
script_version = "1.0.0"

--[[  主函数体
function strip_tags(subs, sel)
    for _, i in ipairs(sel) do
        local line = subs[i]
        line.text = line.text:gsub("{[^}]+}", "")
        subs[i] = line
    end
    aegisub.set_undo_point(tr"strip tags")
end
--]]

aegisub.register_macro(script_name, script_description, strip_tags)

例1.3-2-[strip-tags.lua]同样是aegisub内置的一个脚本,我把主函数体注释起来的,和例1.3.1是同样的结构。

1.3.1 strip_tags注册模块参数解释

aegisub.gettext

aegisub.gettext是aegisub内置的一个翻译api函数,虽然一般我们写脚本也会加上这个,但是这个函数是没用的,因为它只会调用aegisub内置词典中的词进行本地化翻译,属于可写可不写的参数。

#例1.3-3:aegisub.gettext的输出
aegisub.gettext("Strip tags")
--> Strip tags - 删除特效标签
aegisub.gettext("Remove all override tags from selected lines")
--> 从所选行中移除所有特效标签

aegisub.gettext("Delete tags")
--> Delete tags

如例1.3-3,前面两个字符串是aegisub内置的脚本所以内置了词典会输出中文翻译,而后面的"Delete tags"不属于里面的内容所以只会输出原来的值。


脚本信息

  • script_name:脚本名
  • script_description:脚本简介
  • script_author:脚本作者
  • script_version:脚本当前版本

这4个脚本信息写在lua文件的最开头,方便后来检查和修改。当然,这4个就是最简单的变量声明而已,没有别的其它特殊含义,如果想要添加比如脚本日期script_date什么的也都可以。


注册函数

回到了最开头的aegisub.register_macro()函数,从上例中可以看出,可以使用script_namescript_description进行脚本名和简介的调用(例1.3-2),也可以像kara-templater一样直接使用字符串输入(例1.3-1)。


1.3.2 在Aegisub中调用aegisub api

template line, !_G.aegisub.gettext("Strip tags")!

在Aegisub中使用函数需要添加上全局变量_G才能调用。


1.4 script_name拓展

#例1.4-1:通过文件树路径方式调用多个函数#1
script_name = "Save lines"

aegisub.register_macro(script_name.."/save", script_description, save_lines)
aegisub.register_macro(script_name.."/load", script_description, load_lines)

script_name拓展

图1.4-1: 例1.4-1实际显示

我们可以向script_name后面和类似文件路径一样添加斜杠,这样调用自动化的时候就会有子选项出现。因为是变量连接字符串,所以我们需要字符串连接符 .. 进行连接,例1.4-1等同于例1.4-2:

#例1.4-2:通过文件树路径方式调用多个函数#2

aegisub.register_macro("Save lines/save", script_description, save_lines)
aegisub.register_macro("Save lines/load", script_description, load_lines)

1.5 思考

  1. Aegisub中使用aegisub.gettext()函数,查看"Karaoke Templater"和"Apply karaoke template"会输出什么.
  2. 虽然现在还无法输出效果,但是我们已经能在Aegisub的自动化注册一个脚本了,尝试一下.(在autoload目录下新建一个lua文件,进行注册.)

标签:脚本,插件,name,script,tags,1.3,注册,aegisub,Aegisub
From: https://www.cnblogs.com/Yiero/p/16825569.html

相关文章

  • idea插件PlantUML简介-类图
    1、安装PlantUML2、安装GraphvizbrewinstallGraphviz3、uml类图用法4、文档下载@startumltitleuml类图用法/'+表示public-表示privat......
  • 常用git插件
    Chinese(Simplified)(简体中文)LanguagePackforVisualStudioCodeGitHistoryGitLensImagepreviewNGA-MoFishPowerModeQQTailwindCSSIntelliSenseuni-......
  • jquery简单步骤插件
    <html><head><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"><title>jquery简单步骤</title><linkrel="stylesheet"type="text/......
  • Win10仅修改部分文本大小|Win10注册表修改文字大小
    Win10在早期的版本中,可以在控制面板修改文本大小,不修改系统整体的缩放,但是在后期的版本更新中,取消了相关的功能。这篇文章是本站给大家带来的Win10注册表修改文字大小方法......
  • 构建 Flutter 应用程序的10个最佳 VSCode 插件
    构建Flutter应用程序的10个最佳VSCode插件在本文中,我们将分享使用VisualStudio代码(VSCode)IDE的经验。我们的开发团队更喜欢使用某些插件,这里我们将解释原因......
  • Webpack中的plugin插件机制
    大家有没有遇到过这些问题:webpack打包之后的文件没有压缩静态文件要手动拷贝到输出目录代码中写了很多环境判断的多余代码上一篇「webpack核心特性」loader说到......
  • k8s安装nfs插件
    1、创建rbac权限vimrbac.yamlkind:ClusterRoleapiVersion:rbac.authorization.k8s.io/v1metadata:name:nfs-provisioner-runnerrules:-apiGroups:[""]......
  • idea插件
    1.Translation插件google下使用会提示TKK的错误可以更换搜索引擎为百度到百度翻译中申请id跟密钥:百度翻译开放平台(baidu.com)1.选择个人开发者,名字、邮箱可以随机填......
  • vim 个人简单定制化(不含插件)
    .vimrc简单定制化"Jzheng"===setnocompatiblefiletypeonfiletypeindentonfiletypepluginonfiletypepluginindentonsetmouse=asetencoding=utf-8s......
  • fcpx插件:Stupid raisins show pop for Mac(20个标题展示模板)
    mac哪款fcpx标题展示插件好用呢?StupidrAIsinsshowpopforMac是一款运行在MacOS平台,搭配FinalCutPro x软件一起使用的标题展示模板。StupidrAIsinsshowpop有20个......