-
-
Save chrippa/0331d87479dc7bfffef9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.