Created
July 28, 2018 10:58
-
-
Save 0rbadvent/b6540465d11a2400fcc8d07686cfdb71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- default keybinding: b | |
-- add the following to your input.conf to change the default keybinding: | |
-- keyname script_binding auto_load_subs | |
local utils = require 'mp.utils' | |
function display_error() | |
mp.msg.warn("Subtitle download failed: ") | |
mp.osd_message("Subtitle download failed") | |
end | |
function load_sub_fn() | |
path = mp.get_property("path") | |
srt_path = string.gsub(path, "%.%w+$", ".srt") | |
t = { args = { "subliminal", "download", "-s", "-f", "-l", "en", path } } | |
mp.osd_message("Searching subtitle") | |
res = utils.subprocess(t) | |
if res.error == nil then | |
if mp.commandv("sub_add", srt_path) then | |
mp.msg.warn("Subtitle download succeeded") | |
mp.osd_message("Subtitle '" .. srt_path .. "' download succeeded") | |
else | |
display_error() | |
end | |
else | |
display_error() | |
end | |
end | |
mp.add_key_binding("b", "auto_load_subs", load_sub_fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment