Skip to content

Commit 1f86aea

Browse files
committed
同步与整合上游
1 parent 1655277 commit 1f86aea

File tree

9 files changed

+189
-122
lines changed

9 files changed

+189
-122
lines changed

portable_config/scripts/playlistmanager.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--[[
22
SOURCE_ https://github.com/jonniek/mpv-playlistmanager/blob/master/playlistmanager.lua
3-
COMMIT_ 76626ee6aaa79e08ac937fa6306b4c59f1cd6ee5
3+
COMMIT_ 1a9d250a7d7c7d49a8d0aaa6c4261a50ab74773c
44
55
高级播放列表,用于替换内置的过于简洁的列表
66
自定义快捷键方案示例,在 input.conf 中另起一行:
@@ -38,7 +38,7 @@ local settings = {
3838

3939
filename_replace = "",
4040

41-
--[=====[ START OF SAMPLE REPLACE, to use remove start and end line
41+
--[=====[ START OF SAMPLE REPLACE - Remove this line to use it
4242
--Sample replace: replaces underscore to space on all files
4343
--for mp4 and webm; remove extension, remove brackets and surrounding whitespace, change dot between alphanumeric to space
4444
filename_replace = [[
@@ -266,8 +266,9 @@ update_opts({filename_replace = true, loadfiles_filetypes = true})
266266
function on_loaded()
267267
filename = mp.get_property("filename")
268268
path = mp.get_property('path')
269-
if utils.readdir(path, "dirs") then
270-
-- a directory has been loaded, let's not do anything as mpv will expand it into files
269+
local ext = filename:match("%.(.+)$")
270+
if not ext or not filetype_lookup[ext:lower()] then
271+
-- a directory or playlist has been loaded, let's not do anything as mpv will expand it into files
271272
return
272273
end
273274
--if not a url then join path with working directory

portable_config/scripts/thumbfast.lua

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--[[
22
SOURCE_ https://github.com/po5/thumbfast/blob/master/thumbfast.lua
3-
COMMIT_ 38dc494c68534cefff0cf6a207004dc9d609c87c
3+
COMMIT_ a145b37dc296837a4e48dff68beeeefc674c9bb3
44
55
适配多个OSC类脚本的新缩略图引擎
66
]]--
@@ -254,21 +254,30 @@ local function calc_dimensions()
254254
end
255255
end
256256

257+
local info_timer = nil
258+
257259
local function info(w, h)
258260
local display_w, display_h = w, h
259261

260262
network = mp.get_property_bool("demuxer-via-network", false)
261263
local image = mp.get_property_native("current-tracks/video/image", true)
262264
local albumart = image and mp.get_property_native("current-tracks/video/albumart", false)
263265
local short_video = mp.get_property_native("duration", 0) <= options.min_duration
264-
disabled = not (w and h) or
266+
disabled = (w or 0) == 0 or (h or 0) == 0 or
265267
has_vid == 0 or
266268
(network and not options.network) or
267269
(albumart and not options.audio) or
268270
(image and not albumart) or
269271
(short_video and options.min_duration > 0)
270272

271-
local json, err = mp.utils.format_json({width=display_w, height=display_h, disabled=disabled, socket=options.socket, tnpath=options.tnpath, overlay_id=options.overlay_id})
273+
if info_timer then
274+
info_timer:kill()
275+
info_timer = nil
276+
elseif has_vid == 0 or not disabled then
277+
info_timer = mp.add_timeout(0.05, function() info(w, h) end)
278+
end
279+
280+
local json, err = mp.utils.format_json({width=display_w, height=display_h, disabled=disabled, available=true, socket=options.socket, tnpath=options.tnpath, overlay_id=options.overlay_id})
272281
mp.commandv("script-message", "thumbfast-info", json)
273282
end
274283

@@ -574,7 +583,12 @@ end
574583
local function file_load()
575584
clear()
576585
real_w, real_h = nil, nil
586+
last_real_w, last_real_h = nil, nil
577587
last_seek_time = nil
588+
if info_timer then
589+
info_timer:kill()
590+
info_timer = nil
591+
end
578592

579593
calc_dimensions()
580594
info(effective_w, effective_h)

portable_config/scripts/uosc/elements/Menu.lua

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,13 @@ end
329329

330330
---@param index? integer
331331
---@param menu? MenuStack
332-
function Menu:scroll_to_index(index, menu)
332+
---@param immediate? boolean
333+
function Menu:scroll_to_index(index, menu, immediate)
333334
menu = menu or self.current
334335
if (index and index >= 1 and index <= #menu.items) then
335-
self:scroll_to(round((self.scroll_step * (index - 1)) - ((menu.height - self.scroll_step) / 2)), menu)
336+
local position = round((self.scroll_step * (index - 1)) - ((menu.height - self.scroll_step) / 2))
337+
if immediate then self:set_scroll_to(position, menu)
338+
else self:scroll_to(position, menu) end
336339
end
337340
end
338341

@@ -348,7 +351,7 @@ end
348351
---@param menu? MenuStack
349352
function Menu:select_value(value, menu)
350353
menu = menu or self.current
351-
local index = itable_find(menu.items, function(_, item) return item.value == value end)
354+
local index = itable_find(menu.items, function(item) return item.value == value end)
352355
self:select_index(index, 5)
353356
end
354357

@@ -369,7 +372,7 @@ end
369372

370373
---@param index? integer
371374
---@param menu? MenuStack
372-
function Menu:activate_unique_index(index, menu)
375+
function Menu:activate_one_index(index, menu)
373376
self:deactivate_items(menu)
374377
self:activate_index(index, menu)
375378
end
@@ -378,16 +381,16 @@ end
378381
---@param menu? MenuStack
379382
function Menu:activate_value(value, menu)
380383
menu = menu or self.current
381-
local index = itable_find(menu.items, function(_, item) return item.value == value end)
384+
local index = itable_find(menu.items, function(item) return item.value == value end)
382385
self:activate_index(index, menu)
383386
end
384387

385388
---@param value? any
386389
---@param menu? MenuStack
387-
function Menu:activate_unique_value(value, menu)
390+
function Menu:activate_one_value(value, menu)
388391
menu = menu or self.current
389-
local index = itable_find(menu.items, function(_, item) return item.value == value end)
390-
self:activate_unique_index(index, menu)
392+
local index = itable_find(menu.items, function(item) return item.value == value end)
393+
self:activate_one_index(index, menu)
391394
end
392395

393396
---@param id string
@@ -417,22 +420,22 @@ end
417420
---@param menu? MenuStack
418421
function Menu:delete_value(value, menu)
419422
menu = menu or self.current
420-
local index = itable_find(menu.items, function(_, item) return item.value == value end)
423+
local index = itable_find(menu.items, function(item) return item.value == value end)
421424
self:delete_index(index)
422425
end
423426

424427
---@param menu? MenuStack
425428
function Menu:prev(menu)
426429
menu = menu or self.current
427430
menu.selected_index = math.max(menu.selected_index and menu.selected_index - 1 or #menu.items, 1)
428-
self:scroll_to_index(menu.selected_index, menu)
431+
self:scroll_to_index(menu.selected_index, menu, true)
429432
end
430433

431434
---@param menu? MenuStack
432435
function Menu:next(menu)
433436
menu = menu or self.current
434437
menu.selected_index = math.min(menu.selected_index and menu.selected_index + 1 or 1, #menu.items)
435-
self:scroll_to_index(menu.selected_index, menu)
438+
self:scroll_to_index(menu.selected_index, menu, true)
436439
end
437440

438441
function Menu:back()
@@ -579,8 +582,8 @@ function Menu:enable_key_bindings()
579582
self:add_key_binding('shift+enter', 'menu-select-alt5', self:create_key_action('open_selected_item_soft'))
580583
self:add_key_binding('shift+kp_enter', 'menu-select-alt6', self:create_key_action('open_selected_item_soft'))
581584
self:add_key_binding('esc', 'menu-close', self:create_key_action('close'))
582-
self:add_key_binding('pgup', 'menu-page-up', self:create_key_action('on_pgup'))
583-
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'))
585+
self:add_key_binding('pgup', 'menu-page-up', self:create_key_action('on_pgup'), 'repeatable')
586+
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'), 'repeatable')
584587
self:add_key_binding('home', 'menu-home', self:create_key_action('on_home'))
585588
self:add_key_binding('end', 'menu-end', self:create_key_action('on_end'))
586589
end

portable_config/scripts/uosc/lib/menus.lua

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
159159

160160
local files, directories = read_directory(directory.path, opts.allowed_types)
161161
local is_root = not directory.dirname
162+
local path_separator = path_separator(directory.path)
162163

163164
if not files or not directories then return end
164165

@@ -171,77 +172,72 @@ function open_file_navigation_menu(directory_path, handle_select, opts)
171172

172173
if is_root then
173174
if state.os == 'windows' then
174-
items[#items + 1] = {
175-
title = '..', hint = '驱动器列表', value = {is_drives = true, is_to_parent = true}, separator = true,
176-
}
175+
items[#items + 1] = {title = '..', hint = '驱动器列表', value = '{drives}', separator = true}
177176
end
178177
else
179-
local serialized = serialize_path(directory.dirname)
180-
serialized.is_directory = true
181-
serialized.is_to_parent = true
182-
items[#items + 1] = {title = '..', hint = '上级目录', value = serialized, separator = true}
178+
items[#items + 1] = {title = '..', hint = '上级目录', value = directory.dirname, separator = true}
183179
end
184180

185-
local items_start_index = #items + 1
181+
local selected_index = #items + 1
186182

187-
local path_separator = path_separator(directory.path)
188183
for _, dir in ipairs(directories) do
189-
local serialized = serialize_path(utils.join_path(directory.path, dir))
190-
if serialized then
191-
serialized.is_directory = true
192-
items[#items + 1] = {title = serialized.basename, value = serialized, hint = path_separator}
193-
end
184+
items[#items + 1] = {title = dir, value = join_path(directory.path, dir), hint = path_separator}
194185
end
195186

196187
for _, file in ipairs(files) do
197-
local serialized = serialize_path(utils.join_path(directory.path, file))
198-
if serialized then
199-
serialized.is_file = true
200-
items[#items + 1] = {title = serialized.basename, value = serialized}
201-
end
188+
items[#items + 1] = {title = file, value = join_path(directory.path, file)}
202189
end
203190

204191
for index, item in ipairs(items) do
205-
if not item.value.is_to_parent then
206-
if index == items_start_index then item.selected = true end
207-
208-
if opts.active_path == item.value.path then
209-
item.active = true
210-
if not opts.selected_path then item.selected = true end
211-
end
212-
213-
if opts.selected_path == item.value.path then item.selected = true end
192+
if not item.value.is_to_parent and opts.active_path == item.value then
193+
item.active = true
194+
if not opts.selected_path then selected_index = index end
214195
end
196+
197+
if opts.selected_path == item.value then selected_index = index end
215198
end
216199

217200
local menu_data = {
218201
type = opts.type, title = opts.title or directory.basename .. path_separator, items = items,
219-
on_open = opts.on_open, on_close = opts.on_close,
202+
selected_index = selected_index,
220203
}
204+
local menu_options = {on_open = opts.on_open, on_close = opts.on_close}
221205

222206
return Menu:open(menu_data, function(path)
207+
local is_drives = path == '{drives}'
208+
local is_to_parent = is_drives or #path < #directory_path
223209
local inheritable_options = {
224210
type = opts.type, title = opts.title, allowed_types = opts.allowed_types, active_path = opts.active_path,
225211
}
226212

227-
if path.is_drives then
213+
if is_drives then
228214
open_drives_menu(function(drive_path)
229215
open_file_navigation_menu(drive_path, handle_select, inheritable_options)
230-
end, {type = inheritable_options.type, title = inheritable_options.title, selected_path = directory.path})
216+
end, {
217+
type = inheritable_options.type, title = inheritable_options.title, selected_path = directory.path,
218+
on_open = opts.on_open, on_close = opts.on_close,
219+
})
231220
return
232221
end
233222

234-
if path.is_directory then
223+
local info, error = utils.file_info(path)
224+
225+
if not info then
226+
msg.error('Can\'t retrieve path info for "' .. path .. '". Error: ' .. (error or ''))
227+
return
228+
end
229+
230+
if info.is_dir then
235231
-- Preselect directory we are coming from
236-
if path.is_to_parent then
232+
if is_to_parent then
237233
inheritable_options.selected_path = directory.path
238234
end
239235

240-
open_file_navigation_menu(path.path, handle_select, inheritable_options)
236+
open_file_navigation_menu(path, handle_select, inheritable_options)
241237
else
242-
handle_select(path.path)
238+
handle_select(path)
243239
end
244-
end)
240+
end, menu_options)
245241
end
246242

247243
-- Opens a file navigation menu with Windows drives as items.
@@ -255,23 +251,25 @@ function open_drives_menu(handle_select, opts)
255251
playback_only = false,
256252
args = {'wmic', 'logicaldisk', 'get', 'name', '/value'},
257253
})
258-
local items = {}
254+
local items, selected_index = {}, 1
259255

260256
if process.status == 0 then
261257
for _, value in ipairs(split(process.stdout, '\n')) do
262258
local drive = string.match(value, 'Name=([A-Z]:)')
263259
if drive then
264260
local drive_path = normalize_path(drive)
265261
items[#items + 1] = {
266-
title = drive, hint = '盘符', value = drive_path,
267-
selected = opts.selected_path == drive_path,
268-
active = opts.active_path == drive_path,
262+
title = drive, hint = '盘符', value = drive_path, active = opts.active_path == drive_path,
269263
}
264+
if opts.selected_path == drive_path then selected_index = #items end
270265
end
271266
end
272267
else
273268
msg.error(process.stderr)
274269
end
275270

276-
return Menu:open({type = opts.type, title = opts.title or '驱动器列表', items = items}, handle_select)
271+
return Menu:open(
272+
{type = opts.type, title = opts.title or '驱动器列表', items = items, selected_index = selected_index},
273+
handle_select
274+
)
277275
end

portable_config/scripts/uosc/lib/text.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ function text_width(text, opts)
324324
if not text or text == '' then return 0 end
325325

326326
---@type boolean, boolean
327-
local bold, italic = opts.bold or false, opts.italic or false
327+
local bold, italic = opts.bold or options.font_bold, opts.italic or false
328328

329329
if options.text_width_estimation then
330330
---@type {[string|number]: {[1]: number, [2]: integer}}

0 commit comments

Comments
 (0)