Skip to content

Instantly share code, notes, and snippets.

@selsta
Forked from chrippa/ls_hook.lua
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selsta/cdb1e3172a87f6f028c6 to your computer and use it in GitHub Desktop.
Save selsta/cdb1e3172a87f6f028c6 to your computer and use it in GitHub Desktop.
Livestreamer hook for mpv. Made by ChrisK3 and chrippa.
local utils = require 'mp.utils'
local msg = require 'mp.msg'
local ls = {
path = "livestreamer",
}
mp.add_hook("on_load", 11, function()
if mp.get_property_bool("options/ytdl") then
return
end
local url = mp.get_property("stream-open-filename")
if ls:can_handle_url(url) then
local stream_url = ls:stream_url(url)
if not stream_url then
return
end
msg.debug("stream url: " .. stream_url)
mp.set_property("stream-open-filename", stream_url)
-- original URL since livestreamer doesn't give us anything better
mp.set_property("file-local-options/media-title", url)
end
end)
local function exec(...)
local ret = utils.subprocess({args = {...}})
return ret.status, ret.stdout
end
function ls:can_handle_url(url)
return exec(self.path, "--can-handle-url", url) == 0
end
function ls:stream_url(url)
local es, stream_url = exec(
self.path, "--stream-url", "--stream-types", "hls,rtmp,http", url, "best"
)
if es == 0 then
return stream_url:gsub("\n", "")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment