Skip to content

Commit

Permalink
同步与整合上游
Browse files Browse the repository at this point in the history
  • Loading branch information
hooke007 committed Nov 12, 2022
1 parent 1655277 commit 1f86aea
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 122 deletions.
9 changes: 5 additions & 4 deletions portable_config/scripts/playlistmanager.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[
SOURCE_ https://github.com/jonniek/mpv-playlistmanager/blob/master/playlistmanager.lua
COMMIT_ 76626ee6aaa79e08ac937fa6306b4c59f1cd6ee5
COMMIT_ 1a9d250a7d7c7d49a8d0aaa6c4261a50ab74773c
高级播放列表,用于替换内置的过于简洁的列表
自定义快捷键方案示例,在 input.conf 中另起一行:
Expand Down Expand Up @@ -38,7 +38,7 @@ local settings = {

filename_replace = "",

--[=====[ START OF SAMPLE REPLACE, to use remove start and end line
--[=====[ START OF SAMPLE REPLACE - Remove this line to use it
--Sample replace: replaces underscore to space on all files
--for mp4 and webm; remove extension, remove brackets and surrounding whitespace, change dot between alphanumeric to space
filename_replace = [[
Expand Down Expand Up @@ -266,8 +266,9 @@ update_opts({filename_replace = true, loadfiles_filetypes = true})
function on_loaded()
filename = mp.get_property("filename")
path = mp.get_property('path')
if utils.readdir(path, "dirs") then
-- a directory has been loaded, let's not do anything as mpv will expand it into files
local ext = filename:match("%.(.+)$")
if not ext or not filetype_lookup[ext:lower()] then
-- a directory or playlist has been loaded, let's not do anything as mpv will expand it into files
return
end
--if not a url then join path with working directory
Expand Down
20 changes: 17 additions & 3 deletions portable_config/scripts/thumbfast.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[
SOURCE_ https://github.com/po5/thumbfast/blob/master/thumbfast.lua
COMMIT_ 38dc494c68534cefff0cf6a207004dc9d609c87c
COMMIT_ a145b37dc296837a4e48dff68beeeefc674c9bb3
适配多个OSC类脚本的新缩略图引擎
]]--
Expand Down Expand Up @@ -254,21 +254,30 @@ local function calc_dimensions()
end
end

local info_timer = nil

local function info(w, h)
local display_w, display_h = w, h

network = mp.get_property_bool("demuxer-via-network", false)
local image = mp.get_property_native("current-tracks/video/image", true)
local albumart = image and mp.get_property_native("current-tracks/video/albumart", false)
local short_video = mp.get_property_native("duration", 0) <= options.min_duration
disabled = not (w and h) or
disabled = (w or 0) == 0 or (h or 0) == 0 or
has_vid == 0 or
(network and not options.network) or
(albumart and not options.audio) or
(image and not albumart) or
(short_video and options.min_duration > 0)

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})
if info_timer then
info_timer:kill()
info_timer = nil
elseif has_vid == 0 or not disabled then
info_timer = mp.add_timeout(0.05, function() info(w, h) end)
end

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})
mp.commandv("script-message", "thumbfast-info", json)
end

Expand Down Expand Up @@ -574,7 +583,12 @@ end
local function file_load()
clear()
real_w, real_h = nil, nil
last_real_w, last_real_h = nil, nil
last_seek_time = nil
if info_timer then
info_timer:kill()
info_timer = nil
end

calc_dimensions()
info(effective_w, effective_h)
Expand Down
29 changes: 16 additions & 13 deletions portable_config/scripts/uosc/elements/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,13 @@ end

---@param index? integer
---@param menu? MenuStack
function Menu:scroll_to_index(index, menu)
---@param immediate? boolean
function Menu:scroll_to_index(index, menu, immediate)
menu = menu or self.current
if (index and index >= 1 and index <= #menu.items) then
self:scroll_to(round((self.scroll_step * (index - 1)) - ((menu.height - self.scroll_step) / 2)), menu)
local position = round((self.scroll_step * (index - 1)) - ((menu.height - self.scroll_step) / 2))
if immediate then self:set_scroll_to(position, menu)
else self:scroll_to(position, menu) end
end
end

Expand All @@ -348,7 +351,7 @@ end
---@param menu? MenuStack
function Menu:select_value(value, menu)
menu = menu or self.current
local index = itable_find(menu.items, function(_, item) return item.value == value end)
local index = itable_find(menu.items, function(item) return item.value == value end)
self:select_index(index, 5)
end

Expand All @@ -369,7 +372,7 @@ end

---@param index? integer
---@param menu? MenuStack
function Menu:activate_unique_index(index, menu)
function Menu:activate_one_index(index, menu)
self:deactivate_items(menu)
self:activate_index(index, menu)
end
Expand All @@ -378,16 +381,16 @@ end
---@param menu? MenuStack
function Menu:activate_value(value, menu)
menu = menu or self.current
local index = itable_find(menu.items, function(_, item) return item.value == value end)
local index = itable_find(menu.items, function(item) return item.value == value end)
self:activate_index(index, menu)
end

---@param value? any
---@param menu? MenuStack
function Menu:activate_unique_value(value, menu)
function Menu:activate_one_value(value, menu)
menu = menu or self.current
local index = itable_find(menu.items, function(_, item) return item.value == value end)
self:activate_unique_index(index, menu)
local index = itable_find(menu.items, function(item) return item.value == value end)
self:activate_one_index(index, menu)
end

---@param id string
Expand Down Expand Up @@ -417,22 +420,22 @@ end
---@param menu? MenuStack
function Menu:delete_value(value, menu)
menu = menu or self.current
local index = itable_find(menu.items, function(_, item) return item.value == value end)
local index = itable_find(menu.items, function(item) return item.value == value end)
self:delete_index(index)
end

---@param menu? MenuStack
function Menu:prev(menu)
menu = menu or self.current
menu.selected_index = math.max(menu.selected_index and menu.selected_index - 1 or #menu.items, 1)
self:scroll_to_index(menu.selected_index, menu)
self:scroll_to_index(menu.selected_index, menu, true)
end

---@param menu? MenuStack
function Menu:next(menu)
menu = menu or self.current
menu.selected_index = math.min(menu.selected_index and menu.selected_index + 1 or 1, #menu.items)
self:scroll_to_index(menu.selected_index, menu)
self:scroll_to_index(menu.selected_index, menu, true)
end

function Menu:back()
Expand Down Expand Up @@ -579,8 +582,8 @@ function Menu:enable_key_bindings()
self:add_key_binding('shift+enter', 'menu-select-alt5', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('shift+kp_enter', 'menu-select-alt6', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('esc', 'menu-close', self:create_key_action('close'))
self:add_key_binding('pgup', 'menu-page-up', self:create_key_action('on_pgup'))
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'))
self:add_key_binding('pgup', 'menu-page-up', self:create_key_action('on_pgup'), 'repeatable')
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'), 'repeatable')
self:add_key_binding('home', 'menu-home', self:create_key_action('on_home'))
self:add_key_binding('end', 'menu-end', self:create_key_action('on_end'))
end
Expand Down
80 changes: 39 additions & 41 deletions portable_config/scripts/uosc/lib/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function open_file_navigation_menu(directory_path, handle_select, opts)

local files, directories = read_directory(directory.path, opts.allowed_types)
local is_root = not directory.dirname
local path_separator = path_separator(directory.path)

if not files or not directories then return end

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

if is_root then
if state.os == 'windows' then
items[#items + 1] = {
title = '..', hint = '驱动器列表', value = {is_drives = true, is_to_parent = true}, separator = true,
}
items[#items + 1] = {title = '..', hint = '驱动器列表', value = '{drives}', separator = true}
end
else
local serialized = serialize_path(directory.dirname)
serialized.is_directory = true
serialized.is_to_parent = true
items[#items + 1] = {title = '..', hint = '上级目录', value = serialized, separator = true}
items[#items + 1] = {title = '..', hint = '上级目录', value = directory.dirname, separator = true}
end

local items_start_index = #items + 1
local selected_index = #items + 1

local path_separator = path_separator(directory.path)
for _, dir in ipairs(directories) do
local serialized = serialize_path(utils.join_path(directory.path, dir))
if serialized then
serialized.is_directory = true
items[#items + 1] = {title = serialized.basename, value = serialized, hint = path_separator}
end
items[#items + 1] = {title = dir, value = join_path(directory.path, dir), hint = path_separator}
end

for _, file in ipairs(files) do
local serialized = serialize_path(utils.join_path(directory.path, file))
if serialized then
serialized.is_file = true
items[#items + 1] = {title = serialized.basename, value = serialized}
end
items[#items + 1] = {title = file, value = join_path(directory.path, file)}
end

for index, item in ipairs(items) do
if not item.value.is_to_parent then
if index == items_start_index then item.selected = true end

if opts.active_path == item.value.path then
item.active = true
if not opts.selected_path then item.selected = true end
end

if opts.selected_path == item.value.path then item.selected = true end
if not item.value.is_to_parent and opts.active_path == item.value then
item.active = true
if not opts.selected_path then selected_index = index end
end

if opts.selected_path == item.value then selected_index = index end
end

local menu_data = {
type = opts.type, title = opts.title or directory.basename .. path_separator, items = items,
on_open = opts.on_open, on_close = opts.on_close,
selected_index = selected_index,
}
local menu_options = {on_open = opts.on_open, on_close = opts.on_close}

return Menu:open(menu_data, function(path)
local is_drives = path == '{drives}'
local is_to_parent = is_drives or #path < #directory_path
local inheritable_options = {
type = opts.type, title = opts.title, allowed_types = opts.allowed_types, active_path = opts.active_path,
}

if path.is_drives then
if is_drives then
open_drives_menu(function(drive_path)
open_file_navigation_menu(drive_path, handle_select, inheritable_options)
end, {type = inheritable_options.type, title = inheritable_options.title, selected_path = directory.path})
end, {
type = inheritable_options.type, title = inheritable_options.title, selected_path = directory.path,
on_open = opts.on_open, on_close = opts.on_close,
})
return
end

if path.is_directory then
local info, error = utils.file_info(path)

if not info then
msg.error('Can\'t retrieve path info for "' .. path .. '". Error: ' .. (error or ''))
return
end

if info.is_dir then
-- Preselect directory we are coming from
if path.is_to_parent then
if is_to_parent then
inheritable_options.selected_path = directory.path
end

open_file_navigation_menu(path.path, handle_select, inheritable_options)
open_file_navigation_menu(path, handle_select, inheritable_options)
else
handle_select(path.path)
handle_select(path)
end
end)
end, menu_options)
end

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

if process.status == 0 then
for _, value in ipairs(split(process.stdout, '\n')) do
local drive = string.match(value, 'Name=([A-Z]:)')
if drive then
local drive_path = normalize_path(drive)
items[#items + 1] = {
title = drive, hint = '盘符', value = drive_path,
selected = opts.selected_path == drive_path,
active = opts.active_path == drive_path,
title = drive, hint = '盘符', value = drive_path, active = opts.active_path == drive_path,
}
if opts.selected_path == drive_path then selected_index = #items end
end
end
else
msg.error(process.stderr)
end

return Menu:open({type = opts.type, title = opts.title or '驱动器列表', items = items}, handle_select)
return Menu:open(
{type = opts.type, title = opts.title or '驱动器列表', items = items, selected_index = selected_index},
handle_select
)
end
2 changes: 1 addition & 1 deletion portable_config/scripts/uosc/lib/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function text_width(text, opts)
if not text or text == '' then return 0 end

---@type boolean, boolean
local bold, italic = opts.bold or false, opts.italic or false
local bold, italic = opts.bold or options.font_bold, opts.italic or false

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

0 comments on commit 1f86aea

Please sign in to comment.