This commit is contained in:
2026-03-21 15:12:52 -07:00
parent 11384266e3
commit d9a6b1bfb4
6 changed files with 512 additions and 21 deletions

View File

@@ -4,7 +4,7 @@ local msg = require 'mp.msg'
local M = {}
local MEDEIA_LUA_VERSION = '2026-03-20.1'
local MEDEIA_LUA_VERSION = '2026-03-21.1'
-- Expose a tiny breadcrumb for debugging which script version is loaded.
pcall(mp.set_property, 'user-data/medeia-lua-version', MEDEIA_LUA_VERSION)
@@ -56,6 +56,140 @@ local PIPELINE_REQ_PROP = 'user-data/medeia-pipeline-request'
local PIPELINE_RESP_PROP = 'user-data/medeia-pipeline-response'
local PIPELINE_READY_PROP = 'user-data/medeia-pipeline-ready'
local CURRENT_WEB_URL_PROP = 'user-data/medeia-current-web-url'
local _pipeline_progress_ui = {
overlay = nil,
hide_token = 0,
title = '',
summary = '',
detail = '',
}
function _pipeline_progress_ui.trim(text)
return tostring(text or ''):gsub('^%s+', ''):gsub('%s+$', '')
end
function _pipeline_progress_ui.ass_escape(text)
text = tostring(text or '')
text = text:gsub('\\', '\\\\')
text = text:gsub('{', '\\{')
text = text:gsub('}', '\\}')
text = text:gsub('\n', '\\N')
return text
end
function _pipeline_progress_ui.truncate(text, max_len)
text = _pipeline_progress_ui.trim(text)
max_len = tonumber(max_len or 0) or 0
if max_len <= 0 or #text <= max_len then
return text
end
if max_len <= 3 then
return text:sub(1, max_len)
end
return text:sub(1, max_len - 3) .. '...'
end
function _pipeline_progress_ui.kind_title(kind)
kind = _pipeline_progress_ui.trim(kind):lower()
if kind == 'mpv-download' then
return 'Download'
end
if kind == 'mpv-screenshot' then
return 'Screenshot'
end
return 'Pipeline'
end
function _pipeline_progress_ui.ensure_overlay()
if _pipeline_progress_ui.overlay then
return _pipeline_progress_ui.overlay
end
local ok, overlay = pcall(mp.create_osd_overlay, 'ass-events')
if ok and overlay then
_pipeline_progress_ui.overlay = overlay
end
return _pipeline_progress_ui.overlay
end
function _pipeline_progress_ui.cancel_hide()
_pipeline_progress_ui.hide_token = (_pipeline_progress_ui.hide_token or 0) + 1
end
function _pipeline_progress_ui.render()
local overlay = _pipeline_progress_ui.ensure_overlay()
if not overlay then
return
end
local width, height = 1280, 720
local ok, w, h = pcall(mp.get_osd_size)
if ok and tonumber(w or 0) and tonumber(h or 0) and w > 0 and h > 0 then
width = math.floor(w)
height = math.floor(h)
end
overlay.res_x = width
overlay.res_y = height
if _pipeline_progress_ui.summary == '' and _pipeline_progress_ui.detail == '' then
overlay.data = ''
overlay:update()
return
end
local title = _pipeline_progress_ui.truncate(_pipeline_progress_ui.title ~= '' and _pipeline_progress_ui.title or 'Pipeline', 42)
local summary = _pipeline_progress_ui.truncate(_pipeline_progress_ui.summary, 72)
local detail = _pipeline_progress_ui.truncate(_pipeline_progress_ui.detail, 88)
local lines = {
'{\\b1}' .. _pipeline_progress_ui.ass_escape(title) .. '{\\b0}',
}
if summary ~= '' then
lines[#lines + 1] = _pipeline_progress_ui.ass_escape(summary)
end
if detail ~= '' then
lines[#lines + 1] = '{\\fs18\\c&HDDDDDD&}' .. _pipeline_progress_ui.ass_escape(detail) .. '{\\r}'
end
overlay.data = string.format(
'{\\an9\\pos(%d,%d)\\fs22\\bord2\\shad1\\1c&HFFFFFF&\\3c&H111111&\\4c&H000000&}%s',
width - 28,
34,
table.concat(lines, '\\N')
)
overlay:update()
end
function _pipeline_progress_ui.hide()
_pipeline_progress_ui.cancel_hide()
_pipeline_progress_ui.title = ''
_pipeline_progress_ui.summary = ''
_pipeline_progress_ui.detail = ''
_pipeline_progress_ui.render()
end
function _pipeline_progress_ui.schedule_hide(delay_seconds)
_pipeline_progress_ui.cancel_hide()
local delay = tonumber(delay_seconds or 0) or 0
if delay <= 0 then
_pipeline_progress_ui.hide()
return
end
local token = _pipeline_progress_ui.hide_token
mp.add_timeout(delay, function()
if token ~= _pipeline_progress_ui.hide_token then
return
end
_pipeline_progress_ui.hide()
end)
end
function _pipeline_progress_ui.update(title, summary, detail)
_pipeline_progress_ui.cancel_hide()
_pipeline_progress_ui.title = _pipeline_progress_ui.trim(title)
_pipeline_progress_ui.summary = _pipeline_progress_ui.trim(summary)
_pipeline_progress_ui.detail = _pipeline_progress_ui.trim(detail)
_pipeline_progress_ui.render()
end
local function _get_lua_source_path()
local info = nil
@@ -1705,8 +1839,83 @@ mp.register_script_message('medeia-pipeline-event', function(json)
pcall(mp.set_property, 'user-data/medeia-last-pipeline-event', encoded)
end
local phase = _pipeline_progress_ui.trim(payload.phase)
local event_name = _pipeline_progress_ui.trim(payload.event)
local kind = _pipeline_progress_ui.trim(payload.kind)
local title = _pipeline_progress_ui.kind_title(kind)
local summary = ''
local detail = ''
if phase == 'started' then
local command_text = _pipeline_progress_ui.trim(payload.command_text)
summary = command_text ~= '' and ('Started: ' .. command_text) or ('Started: ' .. kind)
detail = 'Queued job started'
elseif phase == 'progress' then
if event_name == 'pipe-percent' then
local label = _pipeline_progress_ui.trim(payload.pipe_label ~= '' and payload.pipe_label or kind ~= '' and kind or 'pipeline')
local percent = tonumber(payload.percent or 0) or 0
summary = ('%s %d%%'):format(label, math.floor(percent + 0.5))
detail = 'Processing'
elseif event_name == 'status' then
summary = _pipeline_progress_ui.trim(payload.text)
detail = _pipeline_progress_ui.trim(payload.pipe_label ~= '' and payload.pipe_label or kind)
elseif event_name == 'transfer' then
local label = _pipeline_progress_ui.trim(payload.label ~= '' and payload.label or 'transfer')
local percent = tonumber(payload.percent or 0)
if percent then
summary = ('%s %d%%'):format(label, math.floor(percent + 0.5))
else
summary = label
end
local completed = tonumber(payload.completed or 0)
local total = tonumber(payload.total or 0)
if completed and total and total > 0 then
detail = ('%d / %d'):format(math.floor(completed + 0.5), math.floor(total + 0.5))
end
elseif event_name == 'pipe-begin' then
local label = _pipeline_progress_ui.trim(payload.pipe_label ~= '' and payload.pipe_label or kind ~= '' and kind or 'pipeline')
summary = 'Running: ' .. label
local total_items = tonumber(payload.total_items or 0)
if total_items and total_items > 0 then
detail = ('Items: %d'):format(math.floor(total_items + 0.5))
end
elseif event_name == 'pipe-emit' then
local label = _pipeline_progress_ui.trim(payload.pipe_label ~= '' and payload.pipe_label or kind ~= '' and kind or 'pipeline')
local completed = tonumber(payload.completed or 0) or 0
local total = tonumber(payload.total or 0) or 0
summary = total > 0 and ('%s %d/%d'):format(label, completed, total) or label
detail = _pipeline_progress_ui.trim(payload.item_label)
end
end
if phase == 'completed' then
pcall(mp.set_property, 'user-data/medeia-pipeline-progress', '')
pcall(mp.set_property, 'user-data/medeia-pipeline-progress-summary', '')
if payload.success == false then
summary = title .. ' failed'
detail = _pipeline_progress_ui.trim(payload.error)
if detail == '' then
detail = 'Unknown error'
end
else
summary = title .. ' complete'
detail = _pipeline_progress_ui.trim(payload.command_text)
end
_pipeline_progress_ui.update(title, summary, detail)
_pipeline_progress_ui.schedule_hide(2.5)
else
if type(encoded) == 'string' and encoded ~= '' then
pcall(mp.set_property, 'user-data/medeia-pipeline-progress', encoded)
end
if summary ~= '' then
pcall(mp.set_property, 'user-data/medeia-pipeline-progress-summary', summary)
end
_pipeline_progress_ui.update(title, summary, detail)
end
_lua_log(
'pipeline-event: phase=' .. tostring(payload.phase or '')
.. ' event=' .. tostring(payload.event or '')
.. ' success=' .. tostring(payload.success)
.. ' kind=' .. tostring(payload.kind or '')
.. ' error=' .. tostring(payload.error or '')
@@ -2288,7 +2497,6 @@ local function _activate_image_controls()
_bind_image_key('d', 'image-pan-d', function() _change_pan(-ImageControl.pan_step, 0) end, {repeatable=true})
_bind_image_key('=', 'image-zoom-in', function() _change_zoom(ImageControl.zoom_step) end, {repeatable=true})
_disable_image_section()
_bind_image_key('-', 'image-zoom-out', function() _change_zoom(-ImageControl.zoom_step) end, {repeatable=true})
_bind_image_key('+', 'image-zoom-in-fine', function() _change_zoom(ImageControl.zoom_step_slow) end, {repeatable=true})
_bind_image_key('_', 'image-zoom-out-fine', function() _change_zoom(-ImageControl.zoom_step_slow) end, {repeatable=true})
@@ -2300,10 +2508,12 @@ end
local function _deactivate_image_controls()
if not ImageControl.enabled then
_disable_image_section()
return
end
ImageControl.enabled = false
_set_image_property(false)
_disable_image_section()
_restore_q_default()
_unbind_image_keys()
mp.osd_message('Image viewer controls disabled', 1.0)
@@ -4813,6 +5023,12 @@ mp.register_script_message('medios-load-url-event', function(json)
if ensure_uosc_loaded() then
_lua_log('[LOAD-URL] Sending close-menu command to UOSC')
mp.commandv('script-message-to', 'uosc', 'close-menu', LOAD_URL_MENU_TYPE)
mp.add_timeout(0.05, function()
if ensure_uosc_loaded() then
_lua_log('[LOAD-URL] Requesting UOSC cursor sync after menu close')
pcall(mp.commandv, 'script-message-to', 'uosc', 'sync-cursor')
end
end)
else
_lua_log('[LOAD-URL] UOSC not loaded, cannot close menu')
end