Decouple initialization from script invokation
This commit is contained in:
parent
80d23f99cd
commit
457836399c
|
@ -37,7 +37,8 @@ function fixsub(path)
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_down_dir(ddir)
|
function set_down_dir(options)
|
||||||
|
ddir = options.down_dir
|
||||||
if ddir == "" then
|
if ddir == "" then
|
||||||
if mp.get_property_native("path", ""):find("://") ~= nil then
|
if mp.get_property_native("path", ""):find("://") ~= nil then
|
||||||
if ops == "win" then
|
if ops == "win" then
|
||||||
|
@ -58,37 +59,40 @@ function set_down_dir(ddir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ddir
|
options.down_dir = ddir
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_python_binary()
|
function get_python_binary()
|
||||||
python = nil
|
python = nil
|
||||||
|
python_error = ""
|
||||||
python_version = utils.subprocess({ args = { "python", "--version" }})
|
python_version = utils.subprocess({ args = { "python", "--version" }})
|
||||||
if python_version.status < 0 then
|
if python_version.status < 0 then
|
||||||
mp.osd_message("python not found")
|
python_error = "python not found"
|
||||||
else
|
else
|
||||||
if python_version.stdout:find("3%.") ~= nil then
|
if python_version.stdout:find("3%.") ~= nil then
|
||||||
python = "python"
|
python = "python"
|
||||||
else
|
else
|
||||||
python_version = utils.subprocess({ args = { "python3", "--version" }})
|
python_version = utils.subprocess({ args = { "python3", "--version" }})
|
||||||
if python_version.status < 0 then
|
if python_version.status < 0 then
|
||||||
mp.osd_message("python3 not installed")
|
python_error = "python3 not installed"
|
||||||
else
|
else
|
||||||
python = "python3"
|
python = "python3"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return python
|
return python, python_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
python, python_error = get_python_binary()
|
||||||
|
read_options(options)
|
||||||
|
set_down_dir(options)
|
||||||
|
|
||||||
function search_subs()
|
function search_subs()
|
||||||
read_options(options)
|
|
||||||
ddir = set_down_dir(options.down_dir)
|
|
||||||
video = mp.get_property_native("media-title", "")
|
video = mp.get_property_native("media-title", "")
|
||||||
python = get_python_binary()
|
|
||||||
if python ~= nil then
|
if python ~= nil then
|
||||||
ret = utils.subprocess({ args = { python, options.subselect_path, video, ddir, options.sub_language }})
|
ret = utils.subprocess({ args = { python, options.subselect_path, video, options.down_dir, options.sub_language }})
|
||||||
else
|
else
|
||||||
|
mp.osd_message(python_error)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if string.find(ret.stdout, ".") ~= nil then
|
if string.find(ret.stdout, ".") ~= nil then
|
||||||
|
@ -96,8 +100,6 @@ function search_subs()
|
||||||
subtitle_path = utils.join_path(ddir, ret.stdout)
|
subtitle_path = utils.join_path(ddir, ret.stdout)
|
||||||
fixsub(subtitle_path)
|
fixsub(subtitle_path)
|
||||||
mp.commandv("sub-add", subtitle_path)
|
mp.commandv("sub-add", subtitle_path)
|
||||||
else
|
|
||||||
mp.osd_message("No subtitles found")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue