refactor: split mpv plugin into modular script directory

This commit is contained in:
kyasuda
2026-02-24 18:02:57 -08:00
parent 3da9d9e0e0
commit 60cd1c8ac2
23 changed files with 2203 additions and 1959 deletions

60
plugin/subminer/log.lua Normal file
View File

@@ -0,0 +1,60 @@
local M = {}
local LOG_LEVEL_PRIORITY = {
debug = 10,
info = 20,
warn = 30,
error = 40,
}
function M.create(ctx)
local mp = ctx.mp
local msg = ctx.msg
local opts = ctx.opts
local function normalize_log_level(level)
local normalized = (level or "info"):lower()
if LOG_LEVEL_PRIORITY[normalized] then
return normalized
end
return "info"
end
local function should_log(level)
local current = normalize_log_level(opts.log_level)
local target = normalize_log_level(level)
return LOG_LEVEL_PRIORITY[target] >= LOG_LEVEL_PRIORITY[current]
end
local function subminer_log(level, scope, message)
if not should_log(level) then
return
end
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
local line = string.format("[subminer] - %s - %s - [%s] %s", timestamp, string.upper(level), scope, message)
if level == "error" then
msg.error(line)
elseif level == "warn" then
msg.warn(line)
elseif level == "debug" then
msg.debug(line)
else
msg.info(line)
end
end
local function show_osd(message)
if opts.osd_messages then
mp.osd_message("SubMiner: " .. message, 3)
end
end
return {
normalize_log_level = normalize_log_level,
should_log = should_log,
subminer_log = subminer_log,
show_osd = show_osd,
}
end
return M