-
-
Save fullmetalsheep/28c397b200a7348027d983f31a7eddfa to your computer and use it in GitHub Desktop.
Automatically download subtitles in mpv using subliminal.
This file contains 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
-- requires subliminal, version 1.0 or newer | |
-- default keybinding: b | |
local utils = require 'mp.utils' | |
--sleep function, so that subs aren't downloaded the instant a file is loaded | |
--taken from:http://lua-users.org/wiki/SleepFunction | |
function sleep(s) | |
local ntime = os.time() + s | |
repeat until os.time() > ntime | |
end | |
--original function, pressing b will trigger this and download the subtitle manually | |
function load_sub_fn() | |
subl = "/usr/local/bin/subliminal" -- use 'which subliminal' to find the path | |
mp.msg.info("Searching subtitle") | |
mp.osd_message("Searching subtitle") | |
t = {} | |
t.args = {subl, "download", "-s", "-f", "-l", "en", mp.get_property("path")} | |
res = utils.subprocess(t) | |
if res.status == 0 then | |
mp.commandv("rescan_external_files", "reselect") | |
mp.msg.info("Subtitle download succeeded") | |
mp.osd_message("Subtitle download succeeded") | |
else | |
mp.msg.warn("Subtitle download failed") | |
mp.osd_message("Subtitle download failed") | |
end | |
end | |
--added function, auto search for subs and download if not present, the way god intended :P | |
function autosubs() | |
sleep(10) | |
subl = "/usr/local/bin/subliminal" -- use 'which subliminal' to find the path | |
mp.msg.info("Searching subtitle") | |
mp.osd_message("Searching subtitle") | |
t = {} | |
t.args = {subl, "download", "-s", "-l", "en", mp.get_property("path")} | |
res = utils.subprocess(t) | |
if res.status == 0 then | |
mp.commandv("rescan_external_files", "reselect") | |
mp.msg.info("Subtitle download succeeded") | |
mp.osd_message("Subtitle download succeeded") | |
else | |
mp.msg.warn("Subtitle download failed") | |
mp.osd_message("Subtitle download failed") | |
end | |
end | |
mp.add_key_binding("b", "auto_load_subs", load_sub_fn) | |
mp.register_event("file-loaded", autosubs) |
I have now pushed this script to a separate repo where i'll maintain it. please refer here if you have more queries, suggestions, fixes: https://github.com/fullmetalsheep/mpv-iina-scripts
thanks!
I have made an improved version that does not download subs for short videos or movies that already have subs.
You might find it interesting: https://github.com/davidde/mpv-autosub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extremely sorry about the late reply, i don't check my gists page often. And I'm glad, I'll update the mpv script wiki to say that it does. Thanks 👍
I have added a timer function to the script and a default wait of 10 second before searching for subs. You can customize the script to wait any number of seconds you want :)