dfdfdd
This commit is contained in:
128
MPV/LUA/main.lua
128
MPV/LUA/main.lua
@@ -688,9 +688,114 @@ local function _reset_pan_zoom()
|
||||
_show_image_status('Zoom reset')
|
||||
end
|
||||
|
||||
local function _sanitize_filename_component(s)
|
||||
s = trim(tostring(s or ''))
|
||||
if s == '' then
|
||||
return 'screenshot'
|
||||
end
|
||||
-- Windows-unfriendly characters: <>:"/\|?* and control chars
|
||||
s = s:gsub('[%c]', '')
|
||||
s = s:gsub('[<>:"/\\|%?%*]', '_')
|
||||
s = trim(s)
|
||||
s = s:gsub('[%.%s]+$', '')
|
||||
if s == '' then
|
||||
return 'screenshot'
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
local function _strip_title_extension(title, path)
|
||||
title = trim(tostring(title or ''))
|
||||
if title == '' then
|
||||
return title
|
||||
end
|
||||
path = tostring(path or '')
|
||||
local ext = path:match('%.([%w%d]+)$')
|
||||
if not ext or ext == '' then
|
||||
return title
|
||||
end
|
||||
ext = ext:lower()
|
||||
local suffix = '.' .. ext
|
||||
if title:lower():sub(-#suffix) == suffix then
|
||||
return trim(title:sub(1, #title - #suffix))
|
||||
end
|
||||
return title
|
||||
end
|
||||
|
||||
local function _capture_screenshot()
|
||||
mp.commandv('screenshot')
|
||||
mp.osd_message('Screenshot captured', 0.7)
|
||||
local function _format_time_label(seconds)
|
||||
local total = math.max(0, math.floor(tonumber(seconds or 0) or 0))
|
||||
local hours = math.floor(total / 3600)
|
||||
local minutes = math.floor(total / 60) % 60
|
||||
local secs = total % 60
|
||||
local parts = {}
|
||||
if hours > 0 then
|
||||
table.insert(parts, ('%dh'):format(hours))
|
||||
end
|
||||
if minutes > 0 or hours > 0 then
|
||||
table.insert(parts, ('%dm'):format(minutes))
|
||||
end
|
||||
table.insert(parts, ('%ds'):format(secs))
|
||||
return table.concat(parts)
|
||||
end
|
||||
|
||||
local time = mp.get_property_number('time-pos') or mp.get_property_number('time') or 0
|
||||
local label = _format_time_label(time)
|
||||
|
||||
local raw_title = trim(tostring(mp.get_property('media-title') or ''))
|
||||
local raw_path = tostring(mp.get_property('path') or '')
|
||||
if raw_title == '' then
|
||||
raw_title = 'screenshot'
|
||||
end
|
||||
raw_title = _strip_title_extension(raw_title, raw_path)
|
||||
local safe_title = _sanitize_filename_component(raw_title)
|
||||
|
||||
local filename = safe_title .. '_' .. label .. '.png'
|
||||
local temp_dir = mp.get_property('user-data/medeia-config-temp') or os.getenv('TEMP') or os.getenv('TMP') or '/tmp'
|
||||
local out_path = utils.join_path(temp_dir, filename)
|
||||
|
||||
local ok = pcall(function()
|
||||
mp.commandv('screenshot-to-file', out_path, 'video')
|
||||
end)
|
||||
if not ok then
|
||||
mp.osd_message('Screenshot failed', 2)
|
||||
return
|
||||
end
|
||||
|
||||
_ensure_selected_store_loaded()
|
||||
local selected_store = _get_selected_store()
|
||||
selected_store = trim(tostring(selected_store or ''))
|
||||
selected_store = selected_store:gsub('^\"', ''):gsub('\"$', '')
|
||||
|
||||
if selected_store == '' then
|
||||
mp.osd_message('Select a store first (Store button)', 2)
|
||||
return
|
||||
end
|
||||
|
||||
local python_exe = _resolve_python_exe(true)
|
||||
if not python_exe or python_exe == '' then
|
||||
mp.osd_message('Screenshot saved; Python not found', 3)
|
||||
return
|
||||
end
|
||||
|
||||
local start_dir = mp.get_script_directory() or ''
|
||||
local cli_py = find_file_upwards(start_dir, 'CLI.py', 8)
|
||||
if not cli_py or cli_py == '' or not utils.file_info(cli_py) then
|
||||
mp.osd_message('Screenshot saved; CLI.py not found', 3)
|
||||
return
|
||||
end
|
||||
|
||||
local res = utils.subprocess({
|
||||
args = { python_exe, cli_py, 'add-file', '-store', selected_store, '-path', out_path },
|
||||
cancellable = false,
|
||||
})
|
||||
|
||||
if res and res.status == 0 then
|
||||
mp.osd_message('Screenshot saved to store: ' .. selected_store, 3)
|
||||
else
|
||||
local stderr = (res and res.stderr) or 'unknown error'
|
||||
mp.osd_message('Screenshot upload failed: ' .. tostring(stderr), 5)
|
||||
end
|
||||
end
|
||||
|
||||
mp.register_script_message('medeia-image-screenshot', function()
|
||||
@@ -2528,6 +2633,25 @@ mp.add_key_binding("L", "medeia-lyric-toggle-shift", lyric_toggle)
|
||||
mp.add_timeout(0, function()
|
||||
pcall(ensure_mpv_ipc_server)
|
||||
pcall(_lua_log, 'medeia-lua loaded version=' .. MEDEIA_LUA_VERSION)
|
||||
|
||||
-- Load optional modules (kept in separate files).
|
||||
pcall(function()
|
||||
local script_dir = mp.get_script_directory() or ''
|
||||
local candidates = {}
|
||||
if script_dir ~= '' then
|
||||
table.insert(candidates, script_dir .. '/sleep_timer.lua')
|
||||
table.insert(candidates, script_dir .. '/LUA/sleep_timer.lua')
|
||||
table.insert(candidates, script_dir .. '/../sleep_timer.lua')
|
||||
end
|
||||
table.insert(candidates, 'C:/medios/Medios-Macina/MPV/LUA/sleep_timer.lua')
|
||||
for _, p in ipairs(candidates) do
|
||||
local ok, chunk = pcall(loadfile, p)
|
||||
if ok and chunk then
|
||||
pcall(chunk)
|
||||
break
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user