[mpv] steal mugen script from amoethyst

This commit is contained in:
2022-11-09 19:51:05 +01:00
parent 584b9a0d9f
commit 87c8314567
4 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
local utils = require("mp.utils")
local function get_kdata(kid)
local resp = mp.command_native({
name = "subprocess",
args = { "curl", "-s", "https://kara.moe/api/karas/" .. kid },
capture_stdout = true,
})
return utils.parse_json(resp.stdout)
end
local function get_title(kdata)
return kdata.titles[kdata.titles_default_language]
end
local function on_load()
local path = mp.get_property("path")
local kid = path:match("^https://kara.moe/kara/.-([0-9a-z-]+)$")
if kid == nil then
kid = path:match("^https://live.karaokes.moe/%?video=([0-9a-z-]+)$")
end
if kid ~= nil then
local kdata = get_kdata(kid)
local mediafile = "https://kara.moe/downloads/medias/" .. kdata.mediafile
local subfile = "https://kara.moe/downloads/lyrics/" .. kdata.subfile
mp.set_property("stream-open-filename", mediafile)
mp.set_property("replaygain-fallback", kdata.gain)
mp.set_property("title", get_title(kdata))
mp.commandv("sub-add", subfile)
end
end
mp.register_event("start-file", on_load)