fix tab width (sigh) and update readme
This commit is contained in:
parent
348749e6ce
commit
80d23f99cd
|
@ -33,6 +33,7 @@ Right now it only lists subtitles from OpenSubtitles, but has the ability to sea
|
||||||
Copy subselect.lua and subselect.py into your script folder
|
Copy subselect.lua and subselect.py into your script folder
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
Changing the configuration is optional. Options:
|
||||||
* *down_dir*: set the download path for the subtitles
|
* *down_dir*: set the download path for the subtitles
|
||||||
* *subselect_path*: set the subselect.py path
|
* *subselect_path*: set the subselect.py path
|
||||||
* *sub_language*: set language for subtitles [default english]; value is a 3-letter ISO-639-3 language code
|
* *sub_language*: set language for subtitles [default english]; value is a 3-letter ISO-639-3 language code
|
||||||
|
@ -40,7 +41,7 @@ Copy subselect.lua and subselect.py into your script folder
|
||||||
Per default the script tries to download the subtitles into the folder from where the video is being played. Is that not possible it downloads them into your HOME folder, or in Windows into your Downloads folder. You may have to set the subselect.py path manually if the script guesses the wrong mpv configuration directory. If the script is somehow not working as expected, it is recommended to set both *down_dir* and *subselect_path* and make sure they are absolute paths and do exist.
|
Per default the script tries to download the subtitles into the folder from where the video is being played. Is that not possible it downloads them into your HOME folder, or in Windows into your Downloads folder. You may have to set the subselect.py path manually if the script guesses the wrong mpv configuration directory. If the script is somehow not working as expected, it is recommended to set both *down_dir* and *subselect_path* and make sure they are absolute paths and do exist.
|
||||||
|
|
||||||
The option to be changed can be put inside a `subselect.conf` file in the lua-settings folder. Create them if they don't exist.
|
The option to be changed can be put inside a `subselect.conf` file in the lua-settings folder. Create them if they don't exist.
|
||||||
Sample `subselect.conf` if you want to change both options:
|
Sample `subselect.conf` if you want to change all options:
|
||||||
```
|
```
|
||||||
down_dir=C:\Users\<me>\subtitles
|
down_dir=C:\Users\<me>\subtitles
|
||||||
subselect_path=C:\Users\<me>\python_scripts\subselect.py
|
subselect_path=C:\Users\<me>\python_scripts\subselect.py
|
||||||
|
|
160
subselect.lua
160
subselect.lua
|
@ -6,99 +6,99 @@ options.down_dir = ""
|
||||||
options.sub_language = "eng"
|
options.sub_language = "eng"
|
||||||
|
|
||||||
if package.config:sub(1,1) == "/" then
|
if package.config:sub(1,1) == "/" then
|
||||||
options.subselect_path = utils.join_path(os.getenv("HOME"), ".config/mpv/scripts/subselect.py")
|
options.subselect_path = utils.join_path(os.getenv("HOME"), ".config/mpv/scripts/subselect.py")
|
||||||
ops = "unix"
|
ops = "unix"
|
||||||
else
|
else
|
||||||
options.subselect_path = utils.join_path(os.getenv("APPDATA"), "mpv\\scripts\\subselect.py")
|
options.subselect_path = utils.join_path(os.getenv("APPDATA"), "mpv\\scripts\\subselect.py")
|
||||||
ops = "win"
|
ops = "win"
|
||||||
end
|
end
|
||||||
|
|
||||||
function fixsub(path)
|
function fixsub(path)
|
||||||
f = io.open(path, "r")
|
f = io.open(path, "r")
|
||||||
if f == nil then
|
if f == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
content = f:read("*all")
|
content = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
write = false
|
write = false
|
||||||
content = content:gsub("%s*%-%->%s*",
|
content = content:gsub("%s*%-%->%s*",
|
||||||
function(w)
|
function(w)
|
||||||
if w:len() < 5 then
|
if w:len() < 5 then
|
||||||
write = true
|
write = true
|
||||||
return " --> "
|
return " --> "
|
||||||
end
|
end
|
||||||
end, 1)
|
end, 1)
|
||||||
if not write then
|
if not write then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
f = io.open(path, "w")
|
f = io.open(path, "w")
|
||||||
f:write(content)
|
f:write(content)
|
||||||
f:flush()
|
f:flush()
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_down_dir(ddir)
|
function set_down_dir(ddir)
|
||||||
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
|
||||||
ddir = utils.join_path(os.getenv("USERPROFILE"), "Downloads")
|
ddir = utils.join_path(os.getenv("USERPROFILE"), "Downloads")
|
||||||
else
|
else
|
||||||
ddir = os.getenv("HOME")
|
ddir = os.getenv("HOME")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ddir = utils.split_path(mp.get_property_native("path", ""))
|
ddir = utils.split_path(mp.get_property_native("path", ""))
|
||||||
if ops == "win" then
|
if ops == "win" then
|
||||||
if ddir:find("^%a:") == nil then
|
if ddir:find("^%a:") == nil then
|
||||||
ddir = utils.join_path(os.getenv("USERPROFILE"), "Downloads")
|
ddir = utils.join_path(os.getenv("USERPROFILE"), "Downloads")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if ddir:find("^/") == nil then
|
if ddir:find("^/") == nil then
|
||||||
ddir = os.getenv("HOME")
|
ddir = os.getenv("HOME")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ddir
|
return ddir
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_python_binary()
|
function get_python_binary()
|
||||||
python = nil
|
python = nil
|
||||||
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")
|
mp.osd_message("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")
|
mp.osd_message("python3 not installed")
|
||||||
else
|
else
|
||||||
python = "python3"
|
python = "python3"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return python
|
return python
|
||||||
end
|
end
|
||||||
|
|
||||||
function search_subs()
|
function search_subs()
|
||||||
read_options(options)
|
read_options(options)
|
||||||
ddir = set_down_dir(options.down_dir)
|
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()
|
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, ddir, options.sub_language }})
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if string.find(ret.stdout, ".") ~= nil then
|
if string.find(ret.stdout, ".") ~= nil then
|
||||||
mp.osd_message("loading subtitle: "..ret.stdout)
|
mp.osd_message("loading subtitle: "..ret.stdout)
|
||||||
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
|
else
|
||||||
mp.osd_message("No subtitles found")
|
mp.osd_message("No subtitles found")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mp.add_key_binding("alt+u", "subselect", search_subs)
|
mp.add_key_binding("alt+u", "subselect", search_subs)
|
Loading…
Reference in New Issue