Skip to content

Instantly share code, notes, and snippets.

@chrippa
Forked from ChrisK2/ls_hook.lua
Last active August 29, 2015 14:11
Show Gist options
  • Save chrippa/0331d87479dc7bfffef9 to your computer and use it in GitHub Desktop.
Save chrippa/0331d87479dc7bfffef9 to your computer and use it in GitHub Desktop.
local utils = require 'mp.utils'
local msg = require 'mp.msg'
local ls = {
path = "livestreamer",
}
mp.add_hook("on_load", 9, function()
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
@wiiaboo
Copy link

wiiaboo commented Dec 31, 2014

For some reason, if I use this script to try watch a twitch.tv stream it always throws "Error 400" or sometimes "Error 403", but if I copy the URL from using "livestreamer --stream-url" and open that directly it works.

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