Skip to content

Commit

Permalink
同步与整合上游
Browse files Browse the repository at this point in the history
  • Loading branch information
hooke007 committed Jan 23, 2023
1 parent 1c774f8 commit f145006
Show file tree
Hide file tree
Showing 32 changed files with 272 additions and 138 deletions.
4 changes: 4 additions & 0 deletions portable_config/script-opts.conf
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@
script-opts-append = uosc-top_bar_size_fullscreen=46
script-opts-append = uosc-top_bar_controls=yes # 启用顶栏的右侧控制按钮,示例即默认值
script-opts-append = uosc-top_bar_title=yes
# 启用顶栏主标题,yes即使用mpv.conf中的设定,no则禁用,或使用自定义的属性扩展字符串。推荐 ${media-title}
script-opts-append = uosc-top_bar_alt_title=
# 启用顶栏备用标题,留空即不使用,推荐 ${filename}
script-opts-append = uosc-top_bar_alt_title_place=below # <默认below|toggle> 备用标题显示的样式
script-opts-append = uosc-top_bar_title_opacity=0.8
script-opts-append = uosc-top_bar_persistency=

Expand Down
5 changes: 5 additions & 0 deletions portable_config/script-opts/uosc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ top_bar_size=40
top_bar_size_fullscreen=46
# 启用顶栏的右侧控制按钮,示例即默认值
top_bar_controls=yes
# 启用顶栏主标题,yes即使用mpv.conf中的设定,no则禁用,或使用自定义的属性扩展字符串。推荐 ${media-title}
top_bar_title=yes
# 启用顶栏备用标题,留空即不使用,推荐 ${filename}
top_bar_alt_title=
# <默认below|toggle> 备用标题显示的样式
top_bar_alt_title_place=below
top_bar_title_opacity=0.8
top_bar_persistency=

Expand Down
57 changes: 23 additions & 34 deletions portable_config/scripts/load_plus.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--[[
SOURCE_ https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/autoload.lua
COMMIT_ 4bc6686b6a80bbae78febf97652e2f0841ca396a
COMMIT_ 7b09bf7ffc1a927e4d45eb0407ec7024bff2f4d5
SOURCE_ https://github.com/rossy/mpv-open-file-dialog/blob/master/open-file-dialog.lua
COMMIT_ 04fe818fc703d8c5dcc3a6aabe1caeed8286bdbb
Expand Down Expand Up @@ -117,45 +117,34 @@ table.filter = function(t, iter)
end
end

-- splitbynum and alnumcomp from alphanum.lua (C) Andre Bogus
-- Released under the MIT License
-- http://www.davekoelle.com/files/alphanum.lua
-- alphanum sorting for humans in Lua
-- http://notebook.kulchenko.com/algorithms/alphanumeric-natural-sorting-for-humans-in-lua

-- split a string into a table of number and string values
function splitbynum(s)
local result = {}
for x, y in (s or ""):gmatch("(%d*)(%D*)") do
if x ~= "" then table.insert(result, tonumber(x)) end
if y ~= "" then table.insert(result, y) end
function alphanumsort(filenames)
local function padnum(n, d)
return #d > 0 and ("%03d%s%.12f"):format(#n, n, tonumber(d) / (10 ^ #d))
or ("%03d%s"):format(#n, n)
end
return result
end

function clean_key(k)
k = (' '..k..' '):gsub("%s+", " "):sub(2, -2):lower()
return splitbynum(k)
end

-- compare two strings
function alnumcomp(x, y)
local xt, yt = clean_key(x), clean_key(y)
for i = 1, math.min(#xt, #yt) do
local xe, ye = xt[i], yt[i]
if type(xe) == "string" then ye = tostring(ye)
elseif type(ye) == "string" then xe = tostring(xe) end
if xe ~= ye then return xe < ye end
local tuples = {}
for i, f in ipairs(filenames) do
tuples[i] = {f:lower():gsub("0*(%d+)%.?(%d*)", padnum), f}
end
return #xt < #yt
table.sort(tuples, function(a, b)
return a[1] == b[1] and #b[2] < #a[2] or a[1] < b[1]
end)
for i, tuple in ipairs(tuples) do filenames[i] = tuple[2] end
return filenames
end

function get_playlist_filenames()
local filenames = {}
for n = 0, pl_count - 1, 1 do
local filename = mp.get_property('playlist/'..n..'/filename')
local _, file = utils.split_path(filename)
filenames[file] = true
end
return filenames
local filenames = {}
for n = 0, pl_count - 1, 1 do
local filename = mp.get_property('playlist/'..n..'/filename')
local _, file = utils.split_path(filename)
filenames[file] = true
end
return filenames
end

function find_and_add_entries()
Expand Down Expand Up @@ -210,7 +199,7 @@ function find_and_add_entries()
end
return EXTENSIONS[string.lower(ext)]
end)
table.sort(files, alnumcomp)
alphanumsort(files)

if dir == "." then
dir = ""
Expand Down
10 changes: 5 additions & 5 deletions portable_config/scripts/uosc/elements/Element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function Element:init(id, props)

-- Flash timer
self._flash_out_timer = mp.add_timeout(options.flash_duration / 1000, function()
local getTo = function() return self.proximity end
self:tween_property('forced_visibility', 1, getTo, function()
self.forced_visibility = nil
end)
local function getTo() return self.proximity end
local function onTweenEnd() self.forced_visibility = nil end
if self.enabled then self:tween_property('forced_visibility', 1, getTo, onTweenEnd)
else onTweenEnd() end
end)
self._flash_out_timer:kill()

Expand Down Expand Up @@ -138,7 +138,7 @@ end
-- Briefly flashes the element for `options.flash_duration` milliseconds.
-- Useful to visualize changes of volume and timeline when changed via hotkeys.
function Element:flash()
if options.flash_duration > 0 and (self.proximity < 1 or self._flash_out_timer:is_enabled()) then
if self.enabled and options.flash_duration > 0 and (self.proximity < 1 or self._flash_out_timer:is_enabled()) then
self:tween_stop()
self.forced_visibility = 1
request_render()
Expand Down
2 changes: 1 addition & 1 deletion portable_config/scripts/uosc/elements/Elements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ mp.set_key_bindings({
'mbtn_left',
Elements:create_proximity_dispatcher('mbtn_left_up'),
function(...)
update_mouse_pos(nil, mp.get_property_native('mouse-pos'), true)
update_mouse_pos(nil, mp.get_property_native('mouse-pos'))
Elements:proximity_trigger('mbtn_left_down', ...)
end,
},
Expand Down
15 changes: 9 additions & 6 deletions portable_config/scripts/uosc/elements/Timeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ function Timeline:render()
ass:rect(fax, fay, fbx, fby, {opacity = options.timeline_opacity})

-- Uncached ranges
local buffered_time = nil
local buffered_playtime = nil
if state.uncached_ranges then
local opts = {size = 80, anchor_y = fby}
local texture_char = visibility > 0 and 'b' or 'a'
local offset = opts.size / (visibility > 0 and 24 or 28)
for _, range in ipairs(state.uncached_ranges) do
if not buffered_time and (range[1] > state.time or range[2] > state.time) then
buffered_time = range[1] - state.time
if not buffered_playtime and (range[1] > state.time or range[2] > state.time) then
buffered_playtime = (range[1] - state.time) / (state.speed or 1)
end
if options.timeline_cache then
local ax = range[1] < 0.5 and bax or math.floor(t2x(range[1]))
Expand Down Expand Up @@ -319,13 +319,16 @@ function Timeline:render()
if text_opacity > 0 then
local time_opts = {size = self.font_size, opacity = text_opacity, border = 2}
-- Upcoming cache time
if buffered_time and options.buffered_time_threshold > 0 and buffered_time < options.buffered_time_threshold then
if buffered_playtime and options.buffered_time_threshold > 0
and buffered_playtime < options.buffered_time_threshold then
local x, align = fbx + 5, 4
local cache_opts = {size = self.font_size * 0.8, opacity = text_opacity * 0.6, border = 1}
local human = round(math.max(buffered_time, 0)) .. 's'
local human = round(math.max(buffered_playtime, 0)) .. 's'
local width = text_width(human, cache_opts)
local time_width = text_width('00:00:00', time_opts)
local min_x, max_x = bax + spacing + 5 + time_width, bbx - spacing - 5 - time_width
local time_width_end = options.destination_time == 'total' and time_width
or text_width('-00:00:00', time_opts)
local min_x, max_x = bax + spacing + 5 + time_width, bbx - spacing - 5 - time_width_end
if x < min_x then x = min_x elseif x + width > max_x then x, align = max_x, 6 end
draw_timeline_text(x, fcy, align, human, cache_opts)
end
Expand Down
30 changes: 27 additions & 3 deletions portable_config/scripts/uosc/elements/TopBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ local TopBar = class(Element)
function TopBar:new() return Class.new(self) --[[@as TopBar]] end
function TopBar:init()
Element.init(self, 'top_bar')
self.pressed = false
self.size, self.size_max, self.size_min = 0, 0, 0
self.icon_size, self.spacing, self.font_size, self.title_bx = 1, 1, 1, 1
self.size_min_override = options.timeline_start_hidden and 0 or nil
self.top_border = options.timeline_border
self.show_alt_title = false

local function decide_maximized_command()
return state.border
Expand Down Expand Up @@ -99,6 +99,11 @@ function TopBar:update_dimensions()
end
end

function TopBar:toggle_title()
if options.top_bar_alt_title_place ~= 'toggle' then return end
self.show_alt_title = not self.show_alt_title
end

function TopBar:on_prop_border()
self:decide_enabled()
self:update_dimensions()
Expand All @@ -114,6 +119,10 @@ function TopBar:on_prop_maximized()
self:update_dimensions()
end

function TopBar:on_mbtn_left_down()
if cursor.x < self.title_bx then self:toggle_title() end
end

function TopBar:on_display() self:update_dimensions() end

function TopBar:render()
Expand Down Expand Up @@ -142,7 +151,7 @@ function TopBar:render()
end

-- Title
local text = state.title
local text = self.show_alt_title and state.alt_title or state.title
if max_bx - title_ax > self.font_size * 3 and text and text ~= '' then
local opts = {
size = self.font_size, wrap = 2, color = bgt, border = 1, border_color = bg, opacity = visibility,
Expand All @@ -157,10 +166,25 @@ function TopBar:render()
title_ay = by + 1
end

-- Alt title
if state.alt_title and options.top_bar_alt_title_place == 'below' and state.alt_title ~= state.title then
local font_size = self.font_size * 0.9
local height = font_size * 1.3
local by = title_ay + height
local opts = {size = font_size, wrap = 2, color = bgt, border = 1, border_color = bg, opacity = visibility}
local bx = math.min(max_bx, title_ax + text_width(state.alt_title, opts) + padding * 2)
opts.clip = string.format('\\clip(%d, %d, %d, %d)', title_ax, title_ay, bx, by)
ass:rect(title_ax, title_ay, bx, by, {
color = bg, opacity = visibility * options.top_bar_title_opacity, radius = 2,
})
ass:txt(title_ax + padding, title_ay + height / 2, 4, state.alt_title, opts)
title_ay = by + 1
end

-- Subtitle: current chapter
if state.current_chapter and max_bx - title_ax > self.font_size * 3 then
local font_size = self.font_size * 0.8
local height = font_size * 1.5
local height = font_size * 1.3
local text = '' .. state.current_chapter.index .. ': ' .. state.current_chapter.title
local by = title_ay + height
local opts = {
Expand Down
8 changes: 4 additions & 4 deletions portable_config/scripts/uosc/lib/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ sort_filenames = (function()

-- Alphanumeric sorting for humans in Lua
-- http://notebook.kulchenko.com/algorithms/alphanumeric-natural-sorting-for-humans-in-lua
local function pad_number(d)
local dec, n = d:match('(%.?)0*(.+)')
return #dec > 0 and ('%.12f'):format(d) or ('%03d%s'):format(#n, n)
local function pad_number(n, d)
return #d > 0 and ("%03d%s%.12f"):format(#n, n, tonumber(d) / (10 ^ #d))
or ("%03d%s"):format(#n, n)
end

--- In place sorting of filenames
Expand All @@ -35,7 +35,7 @@ sort_filenames = (function()
for i, filename in ipairs(filenames) do
local first_char = filename:sub(1, 1)
local order = symbol_order[first_char] or default_order
local formatted = filename:lower():gsub('%.?%d+', pad_number)
local formatted = filename:lower():gsub('0*(%d+)%.?(%d*)', pad_number)
tuples[i] = {order, formatted, filename}
end
table.sort(tuples, function(a, b)
Expand Down
Loading

0 comments on commit f145006

Please sign in to comment.