-
-
Save selsta/cdb1e3172a87f6f028c6 to your computer and use it in GitHub Desktop.
Livestreamer hook for mpv. Made by ChrisK3 and chrippa.
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", 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