diff options
| author | trainytrain <trainytrain@rape.lol> | 2021-05-09 01:29:07 -0700 |
|---|---|---|
| committer | trainytrain <trainytrain@rape.lol> | 2021-05-09 01:29:07 -0700 |
| commit | c765e68f05bfe9f0d2e4990bdc8dfabf11cdbc87 (patch) | |
| tree | 1dd446298beeb5d1a411d5516689dee8c2ee26ee /mpv/scripts/autosubsync.lua | |
init
Diffstat (limited to 'mpv/scripts/autosubsync.lua')
| -rw-r--r-- | mpv/scripts/autosubsync.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/mpv/scripts/autosubsync.lua b/mpv/scripts/autosubsync.lua new file mode 100644 index 0000000..fb3a6c3 --- /dev/null +++ b/mpv/scripts/autosubsync.lua @@ -0,0 +1,44 @@ +-- default keybinding: n +-- add the following to your input.conf to change the default keybinding: +-- keyname script_binding auto_sync_subs +local utils = require 'mp.utils' + +function display_error() + mp.msg.warn("Subtitle synchronization failed: ") + mp.osd_message("Subtitle synchronization failed") +end + +-- Courtesy of https://stackoverflow.com/questions/4990990/check-if-a-file-exists-with-lua +function file_exists(filepath) + local f=io.open(filepath,"r") + if f~=nil then io.close(f) return true else return false end +end + +function sync_sub_fn() + path = mp.get_property("path") + srt_path = string.gsub(path, "%.%w+$", ".srt") + if file_exists(srt_path)==false then + mp.msg.warn("Couldn't find",srt_path) + display_error() + do return end + end + subsync = "/home/user/.local/bin/ffsubsync" -- use 'which ffsubsync' to find the path + t = {} + t.args = {subsync, path, "-i",srt_path,"-o",srt_path} + + mp.osd_message("Sync subtitle...") + mp.msg.info("Starting ffsubsync...") + res = utils.subprocess(t) + if res.error == nil then + if mp.commandv("sub_add", srt_path) then + mp.msg.info("Subtitle updated") + mp.osd_message("Subtitle at'" .. srt_path .. "' synchronized") + else + display_error() + end + else + display_error() + end +end + +mp.add_key_binding("n", "auto_sync_subs", sync_sub_fn) |
