This commit is contained in:
2026-03-20 23:27:35 -07:00
parent cc9c1850a8
commit 6bb3875185
2 changed files with 111 additions and 73 deletions

View File

@@ -4,7 +4,7 @@ local msg = require 'mp.msg'
local M = {}
local MEDEIA_LUA_VERSION = '2026-03-19.2'
local MEDEIA_LUA_VERSION = '2026-03-20.1'
-- Expose a tiny breadcrumb for debugging which script version is loaded.
pcall(mp.set_property, 'user-data/medeia-lua-version', MEDEIA_LUA_VERSION)
@@ -598,7 +598,6 @@ local _refresh_store_cache
local _uosc_open_list_picker
local _run_pipeline_detached
local _run_pipeline_background_job
local _run_pipeline_cli_async
local _cached_store_names = {}
local _store_cache_loaded = false
@@ -1699,24 +1698,22 @@ local function _start_screenshot_store_save(store, out_path, tags)
cmd = cmd .. ' | add-tag ' .. quote_pipeline_arg(tag_string)
end
_lua_log('screenshot-save: async pipeline cmd=' .. cmd)
_lua_log('screenshot-save: queueing repl pipeline cmd=' .. cmd)
local started, start_err = _run_pipeline_cli_async(cmd, nil, function(success, _result, detail)
if success then
mp.osd_message('Screenshot saved to store: ' .. store .. tag_suffix, 3)
return
end
mp.osd_message('Screenshot upload failed: ' .. tostring(detail or 'unknown'), 5)
end)
if started then
mp.osd_message('Screenshot upload started to store: ' .. store .. tag_suffix, 3)
return true
end
mp.osd_message('Screenshot upload failed to start: ' .. tostring(start_err or 'unknown'), 5)
return false
return _queue_pipeline_in_repl(
cmd,
'Queued in REPL: screenshot -> ' .. store .. tag_suffix,
'Screenshot queue failed',
'screenshot-save',
{
kind = 'mpv-screenshot',
mpv_notify = {
success_text = 'Screenshot saved to store: ' .. store .. tag_suffix,
failure_text = 'Screenshot upload failed',
duration_ms = 3500,
},
}
)
end
local function _commit_pending_screenshot(tags)
@@ -3579,49 +3576,6 @@ local function _build_pipeline_cli_args(pipeline_cmd, seeds)
return args, nil
end
_run_pipeline_cli_async = function(pipeline_cmd, seeds, cb)
local args, build_err = _build_pipeline_cli_args(pipeline_cmd, seeds)
if type(args) ~= 'table' then
if type(cb) == 'function' then
cb(false, nil, tostring(build_err or 'invalid pipeline args'))
end
return false, tostring(build_err or 'invalid pipeline args')
end
mp.command_native_async(
{
name = 'subprocess',
args = args,
capture_stdout = true,
capture_stderr = true,
playback_only = false,
},
function(success, result, err)
if not success then
if type(cb) == 'function' then
cb(false, result, tostring(err or 'subprocess failed'))
end
return
end
local ok = false
local detail = 'invalid subprocess result'
if type(result) == 'table' then
local err_text = trim(tostring(result.error or ''))
local status = tonumber(result.status)
ok = (err_text == '' or err_text == 'success') and (status == nil or status == 0)
detail = _describe_subprocess_result(result)
end
if type(cb) == 'function' then
cb(ok, result, detail)
end
end
)
return true, nil
end
local function _run_pipeline_cli_detached(pipeline_cmd, seeds)
local args, build_err = _build_pipeline_cli_args(pipeline_cmd, seeds)
if type(args) ~= 'table' then
@@ -3765,12 +3719,15 @@ local function _open_save_location_picker_for_pending_download()
return
end
local clip_range = trim(tostring(_pending_download.clip_range or ''))
local title = clip_range ~= '' and ('Save clip ' .. clip_range) or 'Save location'
local function build_items()
local selected = _get_selected_store()
local items = {
{
title = 'Pick folder…',
hint = 'Save to a local folder',
hint = clip_range ~= '' and ('Save clip ' .. clip_range .. ' to a local folder') or 'Save to a local folder',
value = { 'script-message-to', mp.get_script_name(), 'medios-download-pick-path', '{}' },
},
}
@@ -3797,7 +3754,7 @@ local function _open_save_location_picker_for_pending_download()
end
-- Always open immediately with whatever store cache we have.
_uosc_open_list_picker(DOWNLOAD_STORE_MENU_TYPE, 'Save location', build_items())
_uosc_open_list_picker(DOWNLOAD_STORE_MENU_TYPE, title, build_items())
-- Best-effort refresh; if it succeeds, reopen menu with stores.
mp.add_timeout(0.05, function()
@@ -3806,7 +3763,7 @@ local function _open_save_location_picker_for_pending_download()
end
_refresh_store_cache(1.5, function(success, changed)
if success and changed then
_uosc_open_list_picker(DOWNLOAD_STORE_MENU_TYPE, 'Save location', build_items())
_uosc_open_list_picker(DOWNLOAD_STORE_MENU_TYPE, title, build_items())
end
end)
end)
@@ -3911,7 +3868,54 @@ local function _start_download_flow_for_current()
end
_lua_log('download: using current format=' .. tostring(fmt))
_pending_download = { url = url, format = fmt }
local clip_range = _get_trim_range_from_clip_markers()
_pending_download = {
url = url,
format = fmt,
clip_range = clip_range,
}
if clip_range and clip_range ~= '' then
_lua_log('download: using clip_range=' .. tostring(clip_range))
else
local clip_marker_count = 0
local marker_label = nil
for idx = 1, CLIP_MARKER_SLOT_COUNT do
local marker_time = clip_markers[idx]
if type(marker_time) == 'number' then
clip_marker_count = clip_marker_count + 1
if not marker_label then
marker_label = _format_clip_marker_label(marker_time)
end
end
end
if clip_marker_count == 1 then
_lua_log('download: single clip marker detected; asking whether to continue with full download')
if not ensure_uosc_loaded() then
mp.osd_message('Only one clip marker is set. Set the second marker or clear markers before downloading.', 4)
return
end
_uosc_open_list_picker('medios_download_clip_decision', marker_label and ('One clip marker set: ' .. marker_label) or 'One clip marker set', {
{
title = 'Download full item',
hint = 'Ignore the single marker and continue',
value = { 'script-message-to', mp.get_script_name(), 'medios-download-proceed-full', '{}' },
},
{
title = 'Clear clip markers and download full item',
hint = 'Reset markers, then continue with a full download',
value = { 'script-message-to', mp.get_script_name(), 'medios-download-clear-markers-and-proceed', '{}' },
},
{
title = 'Go back and edit clip markers',
hint = 'Set the second marker or replace the existing one',
value = { 'script-message-to', mp.get_script_name(), 'medios-download-edit-markers', '{}' },
},
})
return
end
end
_open_save_location_picker_for_pending_download()
end
@@ -4087,9 +4091,15 @@ mp.register_script_message('medios-download-pick-store', function(json)
local url = tostring(_pending_download.url)
local fmt = tostring(_pending_download.format)
local clip_range = trim(tostring(_pending_download.clip_range or ''))
local query = 'format:' .. fmt
if clip_range ~= '' then
query = query .. ',clip:' .. clip_range
end
local clip_suffix = clip_range ~= '' and (' [' .. clip_range .. ']') or ''
local pipeline_cmd = 'download-file -url ' .. quote_pipeline_arg(url)
.. ' -query ' .. quote_pipeline_arg('format:' .. fmt)
.. ' -query ' .. quote_pipeline_arg(query)
.. ' | add-file -store ' .. quote_pipeline_arg(store)
_set_selected_store(store)
@@ -4100,8 +4110,8 @@ mp.register_script_message('medios-download-pick-store', function(json)
'download-store-save',
{
mpv_notify = {
success_text = 'Download completed: store ' .. store .. ' [' .. fmt .. ']',
failure_text = 'Download failed: store ' .. store .. ' [' .. fmt .. ']',
success_text = 'Download completed: store ' .. store .. ' [' .. fmt .. ']' .. clip_suffix,
failure_text = 'Download failed: store ' .. store .. ' [' .. fmt .. ']' .. clip_suffix,
duration_ms = 3500,
},
}
@@ -4109,6 +4119,28 @@ mp.register_script_message('medios-download-pick-store', function(json)
_pending_download = nil
end)
mp.register_script_message('medios-download-proceed-full', function()
if type(_pending_download) ~= 'table' or not _pending_download.url or not _pending_download.format then
return
end
_pending_download.clip_range = nil
_open_save_location_picker_for_pending_download()
end)
mp.register_script_message('medios-download-clear-markers-and-proceed', function()
if type(_pending_download) ~= 'table' or not _pending_download.url or not _pending_download.format then
return
end
_reset_clip_markers()
_pending_download.clip_range = nil
_open_save_location_picker_for_pending_download()
end)
mp.register_script_message('medios-download-edit-markers', function()
_pending_download = nil
mp.osd_message('Edit clip markers, then run Download again', 4)
end)
mp.register_script_message('medios-download-pick-path', function()
if type(_pending_download) ~= 'table' or not _pending_download.url or not _pending_download.format then
return
@@ -4125,9 +4157,15 @@ mp.register_script_message('medios-download-pick-path', function()
local url = tostring(_pending_download.url)
local fmt = tostring(_pending_download.format)
local clip_range = trim(tostring(_pending_download.clip_range or ''))
local query = 'format:' .. fmt
if clip_range ~= '' then
query = query .. ',clip:' .. clip_range
end
local clip_suffix = clip_range ~= '' and (' [' .. clip_range .. ']') or ''
local pipeline_cmd = 'download-file -url ' .. quote_pipeline_arg(url)
.. ' -query ' .. quote_pipeline_arg('format:' .. fmt)
.. ' -query ' .. quote_pipeline_arg(query)
.. ' | add-file -path ' .. quote_pipeline_arg(folder)
_queue_pipeline_in_repl(
@@ -4137,8 +4175,8 @@ mp.register_script_message('medios-download-pick-path', function()
'download-folder-save',
{
mpv_notify = {
success_text = 'Download completed: folder [' .. fmt .. ']',
failure_text = 'Download failed: folder [' .. fmt .. ']',
success_text = 'Download completed: folder [' .. fmt .. ']' .. clip_suffix,
failure_text = 'Download failed: folder [' .. fmt .. ']' .. clip_suffix,
duration_ms = 3500,
},
}