Create a gist now

Instantly share code, notes, and snippets.

@selsta /autosub.lua
Last active Dec 26, 2017

What would you like to do?
Automatically download subtitles in mpv using subliminal.
-- requires subliminal, version 1.0 or newer
-- 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 load_sub_fn()
subl = "/usr/local/bin/subliminal" -- use 'which subliminal' to find the path"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")"Subtitle download succeeded")
mp.osd_message("Subtitle download succeeded")
mp.msg.warn("Subtitle download failed")
mp.osd_message("Subtitle download failed")
mp.add_key_binding("b", "auto_load_subs", load_sub_fn)

racuna commented Aug 11, 2016

My distro does no have subliminal on the repos, but your script can use qnapi too instead of subliminal, the only difference would be the arguments:
t.args = {subl, "-q", "-c", "-l", "en", mp.get_property("path")}

and the binary path, of course:
subl = "/usr/bin/qnapi"

But they are pretty similar. I used it and works well. Thanks.

What about using this as fallback option?

It's not working for me...

CatTail commented Jan 5, 2017

@sunrisewestern Change invocation to

    t.args = {subl, "download", "-l", "zh", "--", path}

Works great with qnapi on Windows with @racuna's modification.
With path in line 7 as
subl = "C:\\Program Files (x86)\\QNapi\\qnapi.exe"

And line 11 as
t.args = {subl, "-q", "-c", "-l", "en", mp.get_property("path")}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment