Skip to content

Commit

Permalink
脚本: 新增 auto_sub_fonts_dir.lua 动态切换字幕字体目录
Browse files Browse the repository at this point in the history
auto_load_fonts 脚本的B计划
  • Loading branch information
hooke007 committed Apr 2, 2023
1 parent 14d3acf commit acd7743
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions portable_config/scripts/auto_sub_fonts_dir.lua
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)

0 comments on commit acd7743

Please sign in to comment.