-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
脚本: 新增 auto_sub_fonts_dir.lua 动态切换字幕字体目录
auto_load_fonts 脚本的B计划
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--[[ | ||
自动临时加载字体 | ||
检测当前播放目录下是否存在 fonts 文件夹,动态修改 --sub-fonts-dir | ||
]] | ||
|
||
|
||
local utils = require("mp.utils") | ||
|
||
local fonts_dir_init = mp.get_property_native("sub-fonts-dir") | ||
local fonts_dir_cur = fonts_dir_init | ||
function update_fonts_dir() | ||
local path = mp.get_property_native("path") | ||
local fonts_dir = path:match("(.*[/\\])") .. "fonts" | ||
if fonts_dir == fonts_dir_cur or fonts_dir == fonts_dir_init then | ||
return | ||
end | ||
local read_success = utils.readdir(fonts_dir) | ||
if not read_success then | ||
mp.set_property("sub-fonts-dir", fonts_dir_init) | ||
fonts_dir_cur = fonts_dir_init | ||
mp.msg.info("回退 --sub-fonts-dir 至初始值") | ||
else | ||
mp.set_property("sub-fonts-dir", fonts_dir) | ||
fonts_dir_cur = fonts_dir | ||
mp.msg.info("设定 --sub-fonts-dir 至新值【" .. fonts_dir .. "】") | ||
end | ||
end | ||
|
||
mp.register_event("start-file", update_fonts_dir) |