Fix mpv autoload_subtitles

This commit is contained in:
rydesun 2025-04-23 07:54:07 +08:00
parent f5bbe779b7
commit 1e422bad4e

View file

@ -13,7 +13,7 @@ local user_opts = {
local script_name = mp.get_script_name() local script_name = mp.get_script_name()
opt.read_options(user_opts, script_name) opt.read_options(user_opts, script_name)
local function get_parrent_dir(filepath) local function get_parent_dir(filepath)
return utils.split_path(utils.join_path( return utils.split_path(utils.join_path(
mp.get_property("working-directory"), filepath)) mp.get_property("working-directory"), filepath))
end end
@ -22,7 +22,7 @@ local function add_subtitles(dir, prefix)
local cmd = {'find', dir, '-maxdepth', tostring(user_opts.dir_depth), local cmd = {'find', dir, '-maxdepth', tostring(user_opts.dir_depth),
'-regextype', 'posix-egrep', '-regex', ".*\\."..user_opts.subtitle_ext_pattern} '-regextype', 'posix-egrep', '-regex', ".*\\."..user_opts.subtitle_ext_pattern}
if user_opts.another_dir ~= "" then if user_opts.another_dir ~= "" then
local another_dir = user_opts.another_dir:gsub('^~/', os.getenv("HOME")) local another_dir = user_opts.another_dir:gsub('^~', os.getenv("HOME"))
table.insert(cmd, 2, another_dir) table.insert(cmd, 2, another_dir)
end end
local res = utils.subprocess({args=cmd}) local res = utils.subprocess({args=cmd})
@ -55,7 +55,7 @@ local function add_current_subs()
local prefix = filename:match("(.+%.[12][0-9][0-9][0-9])%..+") or local prefix = filename:match("(.+%.[12][0-9][0-9][0-9])%..+") or
filename:match("(.+)%.[0-9]+p%..+") or filename:match("(.+)%.[0-9]+p%..+") or
filename:match("(.+)%..+") filename:match("(.+)%..+")
local dir = get_parrent_dir(filepath) local dir = get_parent_dir(filepath)
add_subtitles(dir, prefix) add_subtitles(dir, prefix)
end end