mirror of
https://github.com/rydesun/dotfiles.git
synced 2026-07-16 22:16:11 +08:00
Update mpv script
This commit is contained in:
parent
dac950385c
commit
43565bb2ae
1 changed files with 8 additions and 7 deletions
|
|
@ -18,7 +18,7 @@ local function get_parent_dir(filepath)
|
|||
mp.get_property("working-directory"), filepath))
|
||||
end
|
||||
|
||||
local function add_subtitles(dir, prefix)
|
||||
local function add_subtitles(dir, prefix_unified)
|
||||
local cmd = {'find', dir, '-maxdepth', tostring(user_opts.dir_depth),
|
||||
'-regextype', 'posix-egrep', '-regex', ".*\\."..user_opts.subtitle_ext_pattern}
|
||||
if user_opts.another_dir ~= "" then
|
||||
|
|
@ -27,12 +27,12 @@ local function add_subtitles(dir, prefix)
|
|||
end
|
||||
local res = utils.subprocess({args=cmd})
|
||||
|
||||
local prefix_lower = prefix:lower()
|
||||
local selected = false
|
||||
for subtitle_path in res.stdout:gmatch("[^\r\n]+") do
|
||||
local _, subtitle_name = utils.split_path(subtitle_path)
|
||||
if subtitle_name:lower():find(user_opts.subtitle_pattern) or
|
||||
subtitle_name:lower():find(prefix_lower, 1, true) == 1 then
|
||||
local subtitle_name_unified = subtitle_name:lower():gsub(" ", ".")
|
||||
if subtitle_name_unified:find(user_opts.subtitle_pattern) or
|
||||
subtitle_name_unified:find(prefix_unified, 1, true) == 1 then
|
||||
if selected then
|
||||
mp.commandv('sub-add', subtitle_path, 'auto')
|
||||
else
|
||||
|
|
@ -52,9 +52,10 @@ local function add_current_subs()
|
|||
if #filename < user_opts.min_length then
|
||||
return
|
||||
end
|
||||
local prefix = filename:match("(.+%.[12][0-9][0-9][0-9])%..+") or
|
||||
filename:match("(.+)%.[0-9]+p%..+") or
|
||||
filename:match("(.+)%..+")
|
||||
local filename_unified = filename:lower():gsub(" ", ".")
|
||||
local prefix = filename_unified:match("(.+%.[12][0-9][0-9][0-9])%..+") or
|
||||
filename_unified:match("(.+)%.[0-9]+p%..+") or
|
||||
filename_unified:match("(.+)%..+")
|
||||
local dir = get_parent_dir(filepath)
|
||||
add_subtitles(dir, prefix)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue