Skip to content

Instantly share code, notes, and snippets.

@fullmetalsheep
Forked from selsta/autosub.lua
Last active June 26, 2023 12:52
Show Gist options
  • Save fullmetalsheep/28c397b200a7348027d983f31a7eddfa to your computer and use it in GitHub Desktop.
Save fullmetalsheep/28c397b200a7348027d983f31a7eddfa to your computer and use it in GitHub Desktop.

Revisions

  1. fullmetalsheep revised this gist Oct 15, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions trueautosub.lua
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,13 @@
    -- 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
    @@ -23,6 +30,7 @@ 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")
  2. fullmetalsheep revised this gist Aug 21, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion trueautosub.lua
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ function load_sub_fn()
    mp.osd_message("Searching subtitle")
    t = {}

    t.args = {subl, "download", "-f", "-l", "en", mp.get_property("path")}
    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")
  3. fullmetalsheep renamed this gist Nov 24, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. fullmetalsheep revised this gist Nov 24, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autosub.lua
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ function load_sub_fn()
    end
    end

    --added function, auto search for subs and download if not present, the way god inteded :P
    --added function, auto search for subs and download if not present, the way god intended :P
    function autosubs()
    subl = "/usr/local/bin/subliminal" -- use 'which subliminal' to find the path
    mp.msg.info("Searching subtitle")
  5. fullmetalsheep revised this gist Nov 24, 2016. 1 changed file with 23 additions and 3 deletions.
    26 changes: 23 additions & 3 deletions autosub.lua
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,32 @@
    -- 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'

    --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", "-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 inteded :P
    function autosubs()
    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
    @@ -20,4 +39,5 @@ function load_sub_fn()
    end
    end

    mp.add_key_binding("b", "auto_load_subs", load_sub_fn)
    mp.add_key_binding("b", "auto_load_subs", load_sub_fn)
    mp.register_event("file-loaded", autosubs)
  6. @selsta selsta revised this gist Jul 31, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions autosub.lua
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    -- 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
  7. @selsta selsta revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autosub.lua
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ function load_sub_fn()
    mp.msg.info("Searching subtitle")
    mp.osd_message("Searching subtitle")
    t = {}
    t.args = {subl, "-q", "-s", "-l", "en", "--", mp.get_property("path")}
    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")
  8. @selsta selsta revised this gist Mar 19, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions autosub.lua
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    -- default keybinding: b
    -- add this to your input.conf to change the key to download the subtitles
    -- 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
    mp.msg.info("Searching subtitle")
    mp.osd_message("Subtitle download succeeded")
    mp.osd_message("Searching subtitle")
    t = {}
    t.args = {subl, "-q", "-s", "-l", "en", "--", mp.get_property("path")}
    res = utils.subprocess(t)
  9. @selsta selsta revised this gist Mar 1, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions autosub.lua
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,17 @@ local utils = require 'mp.utils'
    function load_sub_fn()
    subl = "/usr/local/bin/subliminal" -- use 'which subliminal' to find the path
    mp.msg.info("Searching subtitle")
    mp.osd_message("Subtitle download succeeded")
    t = {}
    t.args = {subl, "-q", "-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

  10. @selsta selsta revised this gist Feb 26, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion autosub.lua
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    -- default keybinding: b
    -- add this to your input.conf to change the key to download the subtitles
    -- 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
    subl = "/usr/local/bin/subliminal" -- use 'which subliminal' to find the path
    mp.msg.info("Searching subtitle")
    t = {}
    t.args = {subl, "-q", "-s", "-l", "en", "--", mp.get_property("path")}
  11. @selsta selsta created this gist Feb 26, 2015.
    18 changes: 18 additions & 0 deletions autosub.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    -- add this to your input.conf to change the key to download the subtitles
    -- 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
    mp.msg.info("Searching subtitle")
    t = {}
    t.args = {subl, "-q", "-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")
    else
    mp.msg.warn("Subtitle download failed")
    end
    end

    mp.add_key_binding("b", "auto_load_subs", load_sub_fn)