initial commit

This commit is contained in:
2024-08-03 22:42:15 -04:00
commit d400da457e
4 changed files with 1006 additions and 0 deletions

41
utils/curl.lua Normal file
View File

@ -0,0 +1,41 @@
local mp = require('mp')
local utils = require('mp.utils')
local msg = require('mp.msg')
local M = {}
--- run a curl request
---@param cmd table list of curl args
---@param method? string
---@return table? json, number? httpcode
function M.request(cmd, method)
if type(cmd) == "string" then
cmd = { cmd }
end
table.insert(cmd, 1, '%{http_code}')
table.insert(cmd, 1, "-w")
if method then
table.insert(cmd, 1, method)
table.insert(cmd, 1, "-X")
end
table.insert(cmd, 1, "curl")
local r = mp.command_native({
name = "subprocess",
capture_stdout = true,
capture_stderr = true,
playback_only = false,
args = cmd
})
local json, err, code = utils.parse_json(r.stdout, true)
if not json then
msg.error(string.format("failed to parse json: %s", err))
return
end
return json, tonumber(code)
end
return M