This commit is contained in:
2026-04-03 11:33:51 +02:00
parent 64922e1ae3
commit 0ed904319d
57 changed files with 2935 additions and 1377 deletions
+611 -80
View File
@@ -1,8 +1,10 @@
local msg = require('mp.msg')
local utils = require("mp.utils")
local unpack = unpack or table.unpack
input_loaded, input = pcall(require, "mp.input")
uosc_available = false
latest_menu_anime = {}
-- 打开番剧数据匹配菜单
function get_animes(query)
@@ -69,10 +71,11 @@ function get_animes(query)
end
if uosc_available then
update_menu_uosc(menu_type, menu_title, items, footnote, menu_cmd, query)
latest_menu_anime = update_menu_uosc(menu_type, menu_title, items, footnote, menu_cmd, query)
elseif input_loaded then
show_message("", 0)
mp.add_timeout(0.1, function()
latest_menu_anime = utils.format_json(items)
open_menu_select(items)
end)
end
@@ -124,6 +127,13 @@ function get_episodes(animeTitle, bangumiId)
return
end
table.insert(items, {
title = "← 返回搜索结果",
value = { "script-message-to", mp.get_script_name(), "open-latest-menu-anime", latest_menu_anime },
keep_open = false,
selectable = true,
})
for _, episode in ipairs(response.bangumi.episodes) do
table.insert(items, {
title = episode.episodeTitle,
@@ -136,6 +146,7 @@ function get_episodes(animeTitle, bangumiId)
end
if uosc_available then
footnote = mp.get_property("filename")
update_menu_uosc(menu_type, menu_title, items, footnote)
elseif input_loaded then
mp.add_timeout(0.1, function()
@@ -154,6 +165,7 @@ function update_menu_uosc(menu_type, menu_title, menu_item, menu_footnote, menu_
keep_open = true,
selectable = false,
align = "center",
icon = "spinner",
})
else
items = menu_item
@@ -171,6 +183,8 @@ function update_menu_uosc(menu_type, menu_title, menu_item, menu_footnote, menu_
}
local json_props = utils.format_json(menu_props)
mp.commandv("script-message-to", "uosc", "open-menu", json_props)
return json_props
end
function open_menu_select(menu_items, is_time)
@@ -182,10 +196,16 @@ function open_menu_select(menu_items, is_time)
end
mp.commandv('script-message-to', 'console', 'disable')
input.select({
prompt = '筛选:',
prompt = is_time and '筛选:' or '选择:',
items = item_titles,
submit = function(id)
mp.commandv(unpack(item_values[id]))
input.terminate()
local v = item_values[id]
if type(v) == 'table' then
mp.commandv(unpack(v))
elseif type(v) == 'string' then
mp.command(v)
end
end,
})
end
@@ -250,12 +270,114 @@ end
-- 打开弹幕源添加管理菜单
function open_add_menu_get()
mp.commandv('script-message-to', 'console', 'disable')
local menu_log, deal_value = {}, {}
-- 重建菜单内容函数
local function rebuild_menu_log(select_num)
deal_value = {}
menu_log = {
{ text = "【既有弹幕源】", style = "{\\c&H00CCFF&\\b1}" },
{ text = "----------------------------", style = "{\\c&H888888&}" }
}
local serial = 0
for url, source in pairs(DANMAKU.sources) do
if source.data then
serial = serial + 1
local action, text
if source.from == "api_server" then
action = source.blocked and "unblock" or "block"
text = string.format(" [%02d] %s [来源:弹幕服务器%s] ", serial, url,
source.blocked and "(已屏蔽)" or "(未屏蔽)")
else
action = "delete"
text = string.format(" [%02d] %s [来源:用户添加] ", serial, url)
end
local style = (tonumber(select_num) == serial) and
"{\\c&HFFDE7F&\\b1}" or (action == "unblock" and "{\\c&H4C4CC3&\\b0}" or "{\\c&HCCCCCC&\\b0}")
deal_value[serial] = {value = url, action = action}
table.insert(menu_log, {text = text, style = style})
end
end
if serial == 0 then
table.insert(menu_log, { text = "", style = "" })
end
end
-- 显示菜单
local function show_menu(extra_lines, select_num)
rebuild_menu_log(select_num)
local display = {}
for _, item in ipairs(menu_log) do table.insert(display, item) end
table.insert(display, { text = "----------------------------", style = "{\\c&H888888&}" })
if extra_lines then
if #extra_lines < 2 then table.insert(display, { text = "\n", style = "" }) end
for _, line in ipairs(extra_lines) do table.insert(display, line) end
else
table.insert(display, { text = "\n", style = "" })
table.insert(display, {
text = "提示: 输入【选项数字】可屏蔽或删除既有弹幕源",
style = "{\\c&H999999&}"
})
end
input.set_log(display)
end
-- 获取操作提示
local function get_hint(action)
local hints = {
block = "按回车执行,屏蔽该弹幕源",
unblock = "按回车执行,解除该弹幕源的屏蔽",
delete = "按回车执行,删除该弹幕源"
}
return hints[action] or "按回车执行获取输入源地址url的弹幕"
end
input.get({
prompt = 'Input url:',
keep_open = true,
prompt = "请在此输入源地址url: ",
opened = function() show_menu() end,
edited = function(text)
text = text:gsub("^%s*(.-)%s*$", "%1")
if text == "" then
show_menu()
return
end
local num = tonumber(text)
local event = num and deal_value[num]
local hint = get_hint(event and event.action)
show_menu({
{ text = string.format("已输入: %s", text), style = "{\\c&HCCCCCC&}" },
{ text = hint, style = "{\\c&H999999&}" }
}, text)
end,
submit = function(text)
input.terminate()
mp.commandv("script-message-to", mp.get_script_name(), "add-source-event", text)
text = text:gsub("^%s*(.-)%s*$", "%1")
if text == "" then return end
local num = tonumber(text)
local event = num and deal_value[num]
if event then
local args = string.format('{"type":"activate","value":"%s","action":"%s"}',
string.gsub(event.value, '\\', '\\\\'), event.action)
mp.commandv("script-message-to", mp.get_script_name(), "setup-danmaku-source", args)
else
input.terminate()
mp.commandv("script-message-to", mp.get_script_name(), "add-source-event", text)
end
mp.add_timeout(0.1, show_menu)
end
})
end
@@ -263,19 +385,19 @@ end
function open_add_menu_uosc()
local sources = {}
for url, source in pairs(DANMAKU.sources) do
if source.fname then
if source.data then
local item = {title = url, value = url, keep_open = true,}
if source.from == "api_server" then
if source.blocked then
item.hint = "来源:弹幕服务器(已屏蔽)"
item.actions = {{icon = "check", name = "unblock"},}
item.actions = {{icon = "check", name = "unblock", label = "解除屏蔽"},}
else
item.hint = "来源:弹幕服务器(未屏蔽)"
item.actions = {{icon = "not_interested", name = "block"},}
item.actions = {{icon = "not_interested", name = "block", label = "屏蔽"},}
end
else
item.hint = "来源:用户添加"
item.actions = {{icon = "delete", name = "delete"},}
item.actions = {{icon = "delete", name = "delete", label = "删除"},}
end
table.insert(sources, item)
end
@@ -312,13 +434,36 @@ function open_content_menu(pos)
if COMMENTS ~= nil then
for _, event in ipairs(COMMENTS) do
local text = event.clean_text:gsub("^m%s[mbl%s%-%d%.]+$", ""):gsub("^%s*(.-)%s*$", "%1")
local delay = get_delay_for_time(DELAYS, event.start_time)
local start_time = event.start_time + delay
local end_time = event.end_time + delay
local delay = event.delay
local start_time = event.start_time
local end_time = event.end_time
if text and text ~= "" and start_time >= 0 and start_time <= duration then
local delay_label_suffix = nil
local delay_num = delay and tonumber(delay)
if delay_num and math.abs(delay_num) > 0 then
delay_label_suffix = string.format("已存在延迟: %+0.1fs", delay_num)
end
local adjust_label = '调整弹幕延迟'
if delay_label_suffix then
adjust_label = adjust_label .. '' .. delay_label_suffix .. ''
end
table.insert(items, {
title = abbr_str(text, 60),
hint = seconds_to_time(start_time),
hint = seconds_to_time(start_time) .. " (" .. utf8_sub(remove_query(event.source), 1, 70) .. ")",
actions = {
{
name = 'block_source',
icon = 'block',
label = '屏蔽对应弹幕源'
},
{
name = 'adjust_delay',
icon = 'more_time',
label = adjust_label,
},
},
value = { "seek", start_time, "absolute" },
active = time_pos >= start_time and time_pos <= end_time,
})
@@ -330,7 +475,9 @@ function open_content_menu(pos)
type = "menu_content",
title = "弹幕内容",
footnote = "使用 / 打开搜索",
items = items
items = items,
item_actions_place = "outside",
callback = {mp.get_script_name(), 'handle-danmaku-content-action'},
}
local json_props = utils.format_json(menu_props)
@@ -361,12 +508,134 @@ local menu_items_config = {
local ordered_keys = {"bold", "fontsize", "outline", "shadow", "scrolltime", "opacity", "displayarea"}
-- 设置弹幕样式菜单
function add_danmaku_setup(actived, status)
if not uosc_available then
show_message("无uosc UI框架不支持使用该功能", 2)
return
function open_style_menu_get(query, indicator)
mp.commandv('script-message-to', 'console', 'disable')
local menu_log = {}
local select_num = 0
local select_query = nil
if query then
if tonumber(query) ~= nil then
select_num = tonumber(query)
else
for i, v in ipairs(ordered_keys) do
if v == query then
select_num = i
end
end
end
select_query = ordered_keys[select_num]
end
local function build_menu(source)
menu_log = {
{ text = "【弹幕样式菜单】", style = "{\\c&H00CCFF&\\b1}" },
{ text = ("-"):rep(33), style = "{\\c&H888888&}" }
}
local serial = 0
for _, key in ipairs(ordered_keys) do
serial = serial + 1
local config = menu_items_config[key]
local text = string.format(" [%02d] %s [目前:%s] ", serial, config.title, config.hint)
text = config.hint ~= config.original and text .. "" or text
local style = serial == select_num and "{\\c&HFFDE7F&}" or "{\\c&HCCCCCC&}"
local item_config = { text = text, style = style }
table.insert(menu_log, item_config)
end
table.insert(menu_log, { text = ("-"):rep(33), style = "{\\c&H888888&}" })
if select_num == 0 then
table.insert(menu_log, {
text = "注: 样式更改仅在本次播放生效",
style = "{\\c&HFFDE7F&}"
})
table.insert(menu_log, {
text = "提示: 输入【w】可上移选项【s】可下移选项",
style = "{\\c&H999999&}"
})
else
local input_text = source and source or ""
local config = menu_items_config[select_query]
local suffix = ""
if config and config.hint ~= config.original then
suffix = "(输入\\r恢复默认配置"
end
input_text = string.format("已输入%s: %s", suffix, input_text)
local scope = config and config.footnote or ""
local hint_text = select_query == "bold" and "提示: 输入【y】切换状态" or "提示: " .. scope
local hint_style = "{\\c&H999999&}"
if source and source:lower() == "\\r" then
hint_text = string.format("提示: 回车将恢复默认配置 < %s >", config.original)
end
if indicator == "refresh" or indicator == "updata" then
indicator = ""
hint_text = "提示: 样式更改成功"
hint_style = "{\\c&HFFDE7F&}"
mp.add_timeout(1.5, build_menu)
elseif indicator == "error" then
indicator = ""
hint_text = "提示: 输入非数字字符或范围出错"
hint_style = "{\\c&H4C4CC3&}"
mp.add_timeout(1.5, build_menu)
end
table.insert(menu_log, { text = input_text, style = "{\\c&HCCCCCC&}" })
table.insert(menu_log, { text = hint_text, style = hint_style })
end
input.set_log(menu_log)
end
input.get({
keep_open = true,
prompt = "请在此输入操作w/s|上移/下移): ",
opened = function() build_menu() end,
edited = function(text)
text = text:gsub("^%s*(.-)%s*$", "%1")
if text == "" then
build_menu()
return
end
if text:lower() == "w" or text:lower() == "s" then
input.terminate()
select_num = text:lower() == "w" and select_num - 1 or select_num + 1
select_num = (select_num > #ordered_keys) and 1 or (select_num <= 0 and #ordered_keys or select_num)
mp.add_timeout(0.01, function()
open_style_menu_get(select_num)
end)
return
end
build_menu(text)
end,
submit = function(text)
if select_query == nil then return end
text = text:gsub("^%s*(.-)%s*$", "%1")
if text == "" then return end
if text:lower() == "\\r" then
input.terminate()
local args = string.format('{"type":"activate","action":"%s","index":%d}', select_query, select_num)
mp.commandv("script-message-to", mp.get_script_name(), "setup-danmaku-style", args)
else
if menu_items_config[select_query]["scope"] ~= nil then
input.terminate()
mp.commandv("script-message-to", mp.get_script_name(), "setup-danmaku-style", select_query, text)
elseif text:lower() == "y" and select_query == "bold" then
input.terminate()
local args = string.format('{"type":"activate","index":%d}', select_num)
mp.commandv("script-message-to", mp.get_script_name(), "setup-danmaku-style", args)
end
end
return
end
})
end
function open_style_menu_uosc(actived, status)
local items = {}
for _, key in ipairs(ordered_keys) do
local config = menu_items_config[key]
@@ -407,7 +676,7 @@ function add_danmaku_setup(actived, status)
elseif status == "error" then
menu_props.title = "输入非数字字符或范围出错"
-- 创建一个定时器在1秒后触发回调函数删除搜索栏错误信息
mp.add_timeout(1.0, function() add_danmaku_setup(actived, "updata") end)
mp.add_timeout(1.0, function() open_style_menu_uosc(actived, "updata") end)
end
menu_props.search_style = "palette"
menu_props.search_debounce = "submit"
@@ -419,8 +688,216 @@ function add_danmaku_setup(actived, status)
mp.commandv("script-message-to", "uosc", actions, json_props)
end
function open_style_menu(actived, status)
if uosc_available then
open_style_menu_uosc(actived, status)
elseif input_loaded then
mp.add_timeout(0.01, function()
open_style_menu_get(actived, status)
end)
else
show_message("无支持可用的 UI框架不支持使用该功能", 3)
end
end
-- 打开以指定时间为起点的延迟菜单
function open_delay_from_time_get(source, time, status)
mp.commandv('script-message-to', 'console', 'disable')
local menu_log = {}
local function build_menu(query, input_text)
menu_log = {
{ text = "【从该时间起调整弹幕延迟】", style = "{\\c&H00CCFF&\\b1}" },
{ text = ("-"):rep(33), style = "{\\c&H888888&}" }
}
table.insert(menu_log, { text = "\n", style = "" })
local hint_text = "提示:请输入数字,单位(秒)/ 或者按照形如\"14m15s\"的格式输入分钟数加秒数"
local hint_style = "{\\c&H999999&}"
if status == "error" then
hint_text = "提示: 输入非数字字符或范围出错"
hint_style = "{\\c&H4C4CC3&}"
end
table.insert(menu_log, { text = input_text and ("已输入:" .. input_text) or "", style = "{\\c&HCCCCCC&}" })
table.insert(menu_log, { text = hint_text, style = hint_style })
input.set_log(menu_log)
end
input.get({
keep_open = true,
prompt = "请输入要设置的延迟(秒或 XmYs: ",
opened = function() build_menu() end,
edited = function(text)
text = text:gsub("^%s*(.-)%s*$", "%1")
if text == "" then
build_menu()
return
end
build_menu(text)
end,
submit = function(text)
text = text and text:gsub("^%s*(.-)%s*$", "%1") or ""
if text == "" then return end
input.terminate()
local parsed = parse_delay_input(text)
if parsed ~= nil then
mp.commandv("script-message", "danmaku-delay", tostring(parsed), tostring(time), tostring(source))
else
open_delay_from_time(time, "error")
end
end
})
end
function open_delay_from_time_uosc(source, time, status)
if not uosc_available then
show_message("无uosc UI框架不支持使用该功能", 2)
return
end
local menu_props = {
type = "menu_delay_from_time",
title = "从该时间起调整弹幕延迟",
search_style = "palette",
search_debounce = "submit",
footnote = "请输入数字,单位(秒)/ 或者按照形如\"14m15s\"的格式输入分钟数加秒数",
items = {},
on_search = { "script-message-to", mp.get_script_name(), "setup-content-delay", tostring(time), tostring(source) },
}
if status == "error" then
menu_props.title = "输入非数字字符或范围出错"
mp.add_timeout(1.0, function() open_delay_from_time_uosc(source, time) end)
end
local json_props = utils.format_json(menu_props)
mp.commandv("script-message-to", "uosc", "open-menu", json_props)
end
function open_delay_from_time(source, time, status)
if uosc_available then
open_delay_from_time_uosc(source, time, status)
elseif input_loaded then
mp.add_timeout(0.01, function()
open_delay_from_time_get(source, time, status)
end)
else
show_message("无支持可用的 UI框架不支持使用该功能", 3)
end
end
-- 设置弹幕源延迟菜单
function danmaku_delay_setup(source_url)
function open_delay_menu_get(source, status)
mp.commandv('script-message-to', 'console', 'disable')
local menu_log = {}
local serial = 0
local select_num = 0
if source and tonumber(source) ~= nil then
select_num = tonumber(source)
end
local select_url = nil
local function build_menu(query, text)
menu_log = {
{ text = "【弹幕源延迟菜单】", style = "{\\c&H00CCFF&\\b1}" },
{ text = ("-"):rep(33), style = "{\\c&H888888&}" }
}
serial, select_num = 0, 0
for url, src in pairs(DANMAKU.sources) do
if src.data and not src.blocked then
local delay = 0
serial = serial + 1
select_num = (url == source) and serial or select_num
if src.delay_segments then
for _, seg in ipairs(src.delay_segments) do
if seg.start == 0 then
delay = seg.delay or 0
break
end
end
end
local hint = "当前弹幕源延迟: " .. string.format("%.1f", delay + 1e-10) .. ""
local text = string.format(" [%02d] %s [%s] ", serial, url, hint)
local style = (serial == select_num) and "{\\c&HFFDE7F&}" or "{\\c&HCCCCCC&}"
table.insert(menu_log, { text = text, style = style })
select_url = serial == select_num and url or select_url
end
end
if serial == 0 then
table.insert(menu_log, { text = "", style = "" })
end
table.insert(menu_log, { text = ("-"):rep(33), style = "{\\c&H888888&}" })
if select_num == 0 then
table.insert(menu_log, { text = "\n", style = "" })
table.insert(menu_log, {
text = "提示: 输入【w】可上移选项【s】可下移选项",
style = "{\\c&H999999&}"
})
else
local input_text = "已输入:" .. (text ~= nil and text or "")
local hint_text = "提示:请输入数字,单位(秒)/ 或者按照形如\"14m15s\"的格式输入分钟数加秒数"
local hint_style = "{\\c&H999999&}"
if status == "refresh" then
status = ""
hint_text = "提示: 样式更改成功"
hint_style = "{\\c&HFFDE7F&}"
mp.add_timeout(1.5, build_menu)
elseif status == "error" then
status = ""
hint_text = "提示: 输入非数字字符或范围出错"
hint_style = "{\\c&H4C4CC3&}"
mp.add_timeout(1.5, build_menu)
end
-- table.insert(menu_log, { text = input_text, style = "{\\c&HCCCCCC&}" })
table.insert(menu_log, { text = input_text, style = "{\\c&HCCCCCC&}" })
table.insert(menu_log, { text = hint_text, style = hint_style })
end
input.set_log(menu_log)
end
input.get({
keep_open = true,
prompt = "请在此输入操作w/s|上移/下移): ",
opened = function() build_menu() end,
edited = function(text)
text = text:gsub("^%s*(.-)%s*$", "%1")
if text == "" then
build_menu()
return
end
if text:lower() == "w" or text:lower() == "s" then
input.terminate()
select_num = text:lower() == "w" and select_num - 1 or select_num + 1
select_num = (select_num > serial) and 1 or (select_num <= 0 and serial or select_num)
mp.add_timeout(0.01, function()
open_delay_menu_get(select_num)
end)
return
end
build_menu(select_num, text)
end,
submit = function(text)
if select_url == nil then return end
text = text:gsub("^%s*(.-)%s*$", "%1")
if text == "" then return end
input.terminate()
mp.commandv("script-message-to", mp.get_script_name(), "setup-source-delay", select_url, text)
return
end
})
end
function open_delay_menu_uosc(source_url, status)
if not uosc_available then
show_message("无uosc UI框架不支持使用该功能", 2)
return
@@ -428,7 +905,7 @@ function danmaku_delay_setup(source_url)
local sources = {}
for url, source in pairs(DANMAKU.sources) do
if source.fname and not source.blocked then
if source.data and not source.blocked then
local delay = 0
if source.delay_segments then
for _, seg in ipairs(source.delay_segments) do
@@ -453,7 +930,13 @@ function danmaku_delay_setup(source_url)
callback = {mp.get_script_name(), 'setup-source-delay'},
}
if source_url ~= nil then
menu_props.title = "请输入数字,单位(秒)/ 或者按照形如\"14m15s\"的格式输入分钟数加秒数"
if status == "error" then
menu_props.title = "输入非数字字符或范围出错"
-- 创建一个定时器在1秒后触发回调函数删除搜索栏错误信息
mp.add_timeout(1.0, function() open_delay_menu_uosc(source_url) end)
else
menu_props.title = "请输入数字,单位(秒)/ 或者按照形如\"14m15s\"的格式输入分钟数加秒数"
end
menu_props.search_style = "palette"
menu_props.search_debounce = "submit"
menu_props.on_search = { "script-message-to", mp.get_script_name(), "setup-source-delay", source_url }
@@ -463,18 +946,29 @@ function danmaku_delay_setup(source_url)
mp.commandv("script-message-to", "uosc", "open-menu", json_props)
end
function open_delay_menu(source, status)
if uosc_available then
open_delay_menu_uosc(source, status)
elseif input_loaded then
mp.add_timeout(0.01, function()
open_delay_menu_get(source, status)
end)
else
show_message("无支持可用的 UI框架不支持使用该功能", 3)
end
end
-- 总集合弹幕菜单
local total_menu_items_config = {
{ title = "弹幕搜索", action = "open_search_danmaku_menu" },
{ title = "从源添加弹幕", action = "open_add_source_menu" },
{ title = "弹幕源延迟设置", action = "open_source_delay_menu" },
{ title = "弹幕样式", action = "open_danmaku_style_menu" },
{ title = "弹幕内容", action = "open_content_danmaku_menu" },
}
function open_add_total_menu_uosc()
local items = {}
local total_menu_items_config = {
{ title = "弹幕搜索", action = "open_search_danmaku_menu" },
{ title = "从源添加弹幕", action = "open_add_source_menu" },
{ title = "弹幕源延迟设置", action = "open_source_delay_menu" },
{ title = "弹幕样式", action = "open_setup_danmaku_menu" },
{ title = "弹幕内容", action = "open_content_danmaku_menu" },
}
if DANMAKU.anime and DANMAKU.episode then
local episode = DANMAKU.episode:gsub("%s.-$","")
@@ -509,11 +1003,6 @@ end
function open_add_total_menu_select()
local item_titles, item_values = {}, {}
local total_menu_items_config = {
{ title = "弹幕搜索", action = "open_search_danmaku_menu" },
{ title = "从源添加弹幕", action = "open_add_source_menu" },
{ title = "弹幕内容", action = "open_content_danmaku_menu" },
}
for i, config in ipairs(total_menu_items_config) do
item_titles[i] = config.title
item_values[i] = { "script-message-to", mp.get_script_name(), config.action }
@@ -537,7 +1026,7 @@ function open_add_total_menu()
end
end
-- 添加 uosc 菜单栏按钮
mp.commandv(
"script-message-to",
"uosc",
@@ -570,7 +1059,7 @@ mp.commandv(
utils.format_json({
icon = "palette",
tooltip = "弹幕样式",
command = "script-message open_setup_danmaku_menu",
command = "script-message open_danmaku_style_menu",
})
)
@@ -611,8 +1100,8 @@ mp.register_script_message("set", function(prop, value)
if value == "on" then
ENABLED = true
set_danmaku_visibility(true)
if COMMENTS == nil then
set_danmaku_visibility(true)
local path = mp.get_property("path")
init(path)
else
@@ -622,7 +1111,6 @@ mp.register_script_message("set", function(prop, value)
else
show_message("关闭弹幕", 2)
ENABLED = false
set_danmaku_visibility(false)
hide_danmaku_func()
end
@@ -664,12 +1152,13 @@ mp.register_script_message("add-source-event", function(query)
add_danmaku_source(query, true)
end)
mp.register_script_message("open_setup_danmaku_menu", function()
mp.register_script_message("open_danmaku_style_menu", function()
if uosc_available then
mp.commandv("script-message-to", "uosc", "close-menu", "menu_total")
end
add_danmaku_setup()
open_style_menu()
end)
mp.register_script_message("open_content_danmaku_menu", function()
if uosc_available then
mp.commandv("script-message-to", "uosc", "close-menu", "menu_total")
@@ -677,6 +1166,17 @@ mp.register_script_message("open_content_danmaku_menu", function()
open_content_menu()
end)
mp.register_script_message("open-latest-menu-anime", function ()
if uosc_available then
mp.commandv("script-message-to", "uosc", "open-menu", latest_menu_anime)
elseif input_loaded then
show_message("", 0)
mp.add_timeout(0.1, function()
open_menu_select(utils.parse_json(latest_menu_anime))
end)
end
end)
mp.register_script_message("setup-danmaku-style", function(query, text)
local event = utils.parse_json(query)
if event ~= nil then
@@ -688,13 +1188,13 @@ mp.register_script_message("setup-danmaku-style", function(query, text)
menu_items_config.bold.hint = options.bold and "true" or "false"
end
-- "updata" 模式会保留输入框文字
add_danmaku_setup(ordered_keys[event.index], "updata")
open_style_menu(ordered_keys[event.index], "updata")
return
else
-- msg.info("event.action" .. event.action)
options[event.action] = menu_items_config[event.action]["original"]
menu_items_config[event.action]["hint"] = options[event.action]
add_danmaku_setup(event.action, "updata")
open_style_menu(event.action, "updata")
if event.action == "fontsize" or event.action == "scrolltime" then
load_danmaku(true)
end
@@ -718,14 +1218,14 @@ mp.register_script_message("setup-danmaku-style", function(query, text)
options[query] = tostring(num)
menu_items_config[query]["hint"] = options[query]
-- "refresh" 模式会清除输入框文字
add_danmaku_setup(query, "refresh")
open_style_menu(query, "refresh")
if query == "fontsize" or query == "scrolltime" then
load_danmaku(true, true)
end
return
end
end
add_danmaku_setup(query, "error")
open_style_menu(query, "error")
end
end)
@@ -734,14 +1234,10 @@ mp.register_script_message('setup-danmaku-source', function(json)
if event.type == 'activate' then
if event.action == "delete" then
local rm = DANMAKU.sources[event.value]["fname"]
if rm and file_exists(rm) and DANMAKU.sources[event.value]["from"] ~= "user_local" then
os.remove(rm)
end
DANMAKU.sources[event.value] = nil
remove_source_from_history(event.value)
mp.commandv("script-message-to", "uosc", "close-menu", "menu_source")
open_add_menu_uosc()
open_add_menu()
load_danmaku(true)
end
@@ -749,7 +1245,7 @@ mp.register_script_message('setup-danmaku-source', function(json)
DANMAKU.sources[event.value]["blocked"] = true
add_source_to_history(event.value, DANMAKU.sources[event.value])
mp.commandv("script-message-to", "uosc", "close-menu", "menu_source")
open_add_menu_uosc()
open_add_menu()
load_danmaku(true)
end
@@ -757,7 +1253,7 @@ mp.register_script_message('setup-danmaku-source', function(json)
DANMAKU.sources[event.value]["blocked"] = false
add_source_to_history(event.value, DANMAKU.sources[event.value])
mp.commandv("script-message-to", "uosc", "close-menu", "menu_source")
open_add_menu_uosc()
open_add_menu()
load_danmaku(true)
end
end
@@ -768,39 +1264,74 @@ mp.register_script_message("setup-source-delay", function(query, text)
if event ~= nil then
-- item点击
if event.type == "activate" then
danmaku_delay_setup(event.value)
open_delay_menu(event.value)
end
else
-- 数值输入
if text == nil or text == "" then
return
end
local newText, _ = text:gsub("%s", "") -- 移除所有空白字符
local num = tonumber(newText)
local delay_segments = shallow_copy(DANMAKU.sources[query]["delay_segments"] or {})
for i = #delay_segments, 1, -1 do
if delay_segments[i].start == 0 then
table.remove(delay_segments, i)
end
local delay = parse_delay_input(text)
if delay ~= nil then
mp.commandv("script-message", "danmaku-delay", tostring(delay), "0")
mp.commandv("script-message-to", "uosc", "close-menu", "menu_delay")
mp.add_timeout(0.1, function()
open_delay_menu(query, "refresh")
end)
else
open_delay_menu(query, "error")
end
if num ~= nil then
table.insert(delay_segments, 1, { start = 0, delay = tonumber(num) })
DANMAKU.sources[query]["delay_segments"] = delay_segments
add_source_to_history(query, DANMAKU.sources[query])
mp.commandv("script-message-to", "uosc", "close-menu", "menu_delay")
danmaku_delay_setup(query)
load_danmaku(true, true)
elseif newText:match("^%-?%d+m%d+s$") then
local minutes, seconds = string.match(newText, "^(%-?%d+)m(%d+)s$")
minutes = tonumber(minutes)
seconds = tonumber(seconds)
if minutes < 0 then seconds = -seconds end
table.insert(delay_segments, 1, { start = 0, delay = 60 * minutes + seconds })
DANMAKU.sources[query]["delay_segments"] = delay_segments
add_source_to_history(query, DANMAKU.sources[query])
mp.commandv("script-message-to", "uosc", "close-menu", "menu_delay")
danmaku_delay_setup(query)
load_danmaku(true, true)
end
end)
mp.register_script_message('handle-danmaku-content-action', function(json)
local event = utils.parse_json(json)
if not event or event.type ~= 'activate' then return end
if event.action then
local d = COMMENTS[event.index]
if not d or not d.source then return end
if event.action == "block_source" then
DANMAKU.sources[d.source]["blocked"] = true
add_source_to_history(d.source, DANMAKU.sources[d.source])
mp.commandv("script-message-to", "uosc", "close-menu", "menu_content")
load_danmaku(true)
elseif event.action == "adjust_delay" then
-- 打开以该弹幕时间为起点的延迟菜单(该延迟将作用于该时间点及之后的弹幕),仅针对该条弹幕的 source
mp.commandv("script-message", "open_content_delay_menu", d.source, tostring(d.start_time))
end
else
if event.value then
if type(event.value) == "table" then
mp.commandv(unpack(event.value))
else
mp.command(event.value)
end
mp.commandv("script-message-to", "uosc", "close-menu", "menu_content")
end
end
end)
mp.register_script_message("open_content_delay_menu", function(source, time)
open_delay_from_time(source, tonumber(time))
end)
mp.register_script_message("setup-content-delay", function(...)
local args = {...}
if #args == 1 then
return
end
if #args >= 2 then
local time = tonumber(args[1])
local source = args[2]
local delay_str = args[3]
local delay = parse_delay_input(delay_str)
if delay ~= nil then
mp.commandv("script-message", "danmaku-delay", tostring(delay), tostring(time), tostring(source))
mp.commandv("script-message-to", "uosc", "close-menu", "menu_delay_from_time")
else
open_delay_from_time(source, tonumber(time), "error")
end
end
end)