Move Kodi remote and Uptimerobot scripts out of the main repo
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
-- name = "Kodi Remote"
|
||||
-- description = "Kodi multimedia center remote control widget"
|
||||
-- type = "widget"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- arguments_help = "Enter the Kodi IP address and port in the following format: 192.168.0.102:8080"
|
||||
-- version = "1.1"
|
||||
|
||||
local colors = require "md_colors"
|
||||
local json = require "json"
|
||||
|
||||
-- constants
|
||||
|
||||
local media_type = "application/json"
|
||||
|
||||
local get_players_cmd = [[ { "id": 1, "jsonrpc": "2.0", "method": "Player.GetActivePlayers" } ]]
|
||||
local play_cmd = [[ {"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": XXX }, "id": 1} ]]
|
||||
local stop_cmd = [[ {"jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": XXX }, "id": 1} ]]
|
||||
local prev_cmd = [[ {"jsonrpc": "2.0", "method": "Player.GoTo", "params": {"playerid": XXX,"to":"previous"}, "id":1} ]]
|
||||
local next_cmd = [[ {"jsonrpc": "2.0", "method": "Player.GoTo", "params": {"playerid": XXX,"to":"next"}, "id":1} ]]
|
||||
local forward_cmd = [[ {"jsonrpc": "2.0", "method": "Player.Seek", "params": { "playerid": XXX, "value": { "seconds": 300 } }, "id": 1} ]]
|
||||
local backward_cmd = [[ {"jsonrpc": "2.0", "method": "Player.Seek", "params": { "playerid": XXX, "value": { "seconds": -300 } }, "id": 1} ]]
|
||||
|
||||
local buttons = { "fa:fast-backward", "-5m", "fa:play", "fa:stop", "+5m", "fa:fast-forward", "Open Kore" }
|
||||
local buttons_cmds = { prev_cmd, backward_cmd, play_cmd, stop_cmd, forward_cmd, next_cmd }
|
||||
|
||||
-- global vars
|
||||
|
||||
local url = nil
|
||||
local curr_idx = nil
|
||||
|
||||
function on_preview()
|
||||
if next(settings:get()) == nil then
|
||||
ui:show_text("Remote control for Kodi multimedia player")
|
||||
return
|
||||
else
|
||||
on_resume()
|
||||
end
|
||||
end
|
||||
|
||||
function on_resume()
|
||||
if next(settings:get()) == nil then
|
||||
ui:show_text("Tap to enter Kodi address")
|
||||
return
|
||||
end
|
||||
|
||||
init_url_from_settings()
|
||||
|
||||
ui:set_folding_flag(true)
|
||||
ui:show_buttons(buttons)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if next(settings:get()) == nil then
|
||||
settings:show_dialog()
|
||||
return
|
||||
end
|
||||
|
||||
if (idx == 7) then
|
||||
apps:launch("org.xbmc.kore")
|
||||
return
|
||||
end
|
||||
|
||||
curr_idx = idx
|
||||
http:post(url, get_players_cmd, media_type, "players")
|
||||
end
|
||||
|
||||
function on_network_result_players(result)
|
||||
local parsed = json.decode(result)
|
||||
|
||||
if parsed.error ~= nil then
|
||||
show_error(parsed)
|
||||
return
|
||||
end
|
||||
|
||||
-- not playing anything
|
||||
if next(parsed.result) == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local player_id = parsed.result[1].playerid
|
||||
local cmd = buttons_cmds[curr_idx]:replace("XXX", player_id)
|
||||
|
||||
http:post(url, cmd, media_type, "cmd")
|
||||
|
||||
curr_idx = nil
|
||||
end
|
||||
|
||||
function on_network_result_cmd(result)
|
||||
local parsed = json.decode(result)
|
||||
|
||||
if parsed.error ~= nil then
|
||||
show_error(parsed)
|
||||
end
|
||||
end
|
||||
|
||||
-- utils
|
||||
|
||||
function init_url_from_settings()
|
||||
local ip_port = settings:get()[1]:split(":")
|
||||
url = "http://"..ip_port[1]..":"..ip_port[2].."/jsonrpc"
|
||||
end
|
||||
|
||||
function show_error(parsed)
|
||||
ui:show_toast("Error "..parsed.error.code..": "..parsed.error.message)
|
||||
end
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
-- name = "Uptimerobot"
|
||||
-- description = "Shows uptime information from uptimerobot.com. Needs API key."
|
||||
-- data_source = "uptimerobot.com"
|
||||
-- type = "widget"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- version = "1.1"
|
||||
-- arguments_help = "Enter your API key"
|
||||
|
||||
local json = require "json"
|
||||
local md_colors = require "md_colors"
|
||||
|
||||
-- constants
|
||||
local api_url = "https://api.uptimerobot.com/v2/"
|
||||
local click_url = "https://uptimerobot.com/dashboard#mainDashboard"
|
||||
local media_type = "application/x-www-form-urlencoded"
|
||||
|
||||
function on_preview()
|
||||
if (next(settings:get()) == nil) then
|
||||
ui:show_text("Shows uptime information from uptimerobot.com")
|
||||
return
|
||||
else
|
||||
on_alarm()
|
||||
end
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
if (next(settings:get()) == nil) then
|
||||
ui:show_text("Tap to enter API key")
|
||||
return
|
||||
end
|
||||
|
||||
local key = settings:get()[1]
|
||||
local body = "api_key="..key.."&format=json"
|
||||
|
||||
http:post(api_url.."getMonitors", body, media_type)
|
||||
end
|
||||
|
||||
function on_click()
|
||||
if (next(settings:get()) == nil) then
|
||||
settings:show_dialog()
|
||||
else
|
||||
system:open_browser(click_url)
|
||||
end
|
||||
end
|
||||
|
||||
function on_network_result(result, code)
|
||||
if (code >= 400) then
|
||||
ui:show_text("Error: "..code)
|
||||
return
|
||||
end
|
||||
|
||||
local parsed = json.decode(result)
|
||||
|
||||
if (parsed.stat ~= "ok") then
|
||||
ui:show_text("Error: "..parsed.error.message)
|
||||
return
|
||||
end
|
||||
|
||||
local strings_tab = {}
|
||||
|
||||
for k,v in ipairs(parsed.monitors) do
|
||||
strings_tab[k] = v.friendly_name..": "..format_status(v.status)
|
||||
end
|
||||
|
||||
ui:show_table(table_to_tables(strings_tab, 2))
|
||||
end
|
||||
|
||||
-- utils
|
||||
|
||||
function format_status(status)
|
||||
local statuses = { "not checked", "up", "error", "error", "error", "error", "error", "seems down", "down" }
|
||||
local status_colors = { "yellow_500", "green_500", "red_500", "red_500", "red_500", "red_500", "red_500", "orange_500", "red_500" }
|
||||
|
||||
local status_str = statuses[status] or "unknown"
|
||||
local status_color = md_colors[status_colors[status]] or md_colors["grey_500"]
|
||||
|
||||
return "<font color=\""..status_color.."\">"..status_str.."</font>"
|
||||
end
|
||||
|
||||
function table_to_tables(tab, num)
|
||||
local out_tab = {}
|
||||
local row = {}
|
||||
|
||||
for k,v in ipairs(tab) do
|
||||
table.insert(row, v)
|
||||
if k % num == 0 then
|
||||
table.insert(out_tab, row)
|
||||
row = {}
|
||||
end
|
||||
end
|
||||
|
||||
return out_tab
|
||||
end
|
||||
Reference in New Issue
Block a user