Last active
March 13, 2016 04:49
-
-
Save sielicki/93fffbff4a5f45611efd to your computer and use it in GitHub Desktop.
openwebifzap.lua -- create zap requests for openwebif remote api directly from VLC.
This file contains 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
-- Put this in ~/.local/share/vlc/lua/meta/reader/ | |
-- | |
-- If you're watching an Openwebif stream, or rather, if you're watching a | |
-- stream in VLC over http with exactly 10 values separated by colons, this | |
-- translates it into an API call for openWebif that will trigger your dish mover. | |
-- VLC requires this for script scheduling. We want this to always run, so we | |
-- say that it is local, even though it is making network requests. | |
function descriptor() | |
return { scope="local" } | |
end | |
-- Extracts the domain name in vlc.path such that it can be interpolated back | |
-- when we make a request to zap. | |
function baseHost(s) | |
return string.match(s, "^http://[^/]*/") | |
end | |
-- Extracts a sRef from a URL. | |
function refID (s) | |
return string.match(s, "=.*:.*:.*:.*:.*:.*:.*:.*:.*:.*:") | |
end | |
-- Takes in a hostname and a referenceID. | |
function zapURL (hostname, refid) | |
return (hostname .. "api/zap?sRef" .. refid) | |
end | |
-- This is the function that VLC will call in this file when it schedules us. | |
function read_meta() | |
-- check the URI against our patterns. If it doesn't match, we shouldn't | |
-- try to make a request. If it does match both, it's a reasonable guess | |
-- that it is a playlist on an openwebif box. | |
local base = baseHost(vlc.item:uri()) | |
local zapID = refID(vlc.item:uri()) | |
if not (base and zapID) then | |
return | |
end | |
-- Generate a GET at the proper URL. | |
vlc.stream(zapURL(base, zapID)) | |
return | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment