Skip to content

Commit

Permalink
show more playlist with uosc
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jan 15, 2024
1 parent 457bb5f commit 4cbabcb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ MBTN_RIGHT script-message-to menu show
### ~~/script-opts/dyn_menu.conf

- `max_title_length=80`: Limits the title length in dynamic submenu, set to 0 to disable.
- `max_playlist_items=20`: Limit the playlist items in submenu, set to 0 to disable.

## Scripting

Expand Down
25 changes: 20 additions & 5 deletions lua/dyn_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ local msg = require('mp.msg')

-- user options
local o = {
max_title_length = 80, -- limit the title length, set to 0 to disable.
max_title_length = 80, -- limit the title length, set to 0 to disable.
max_playlist_items = 20, -- limit the playlist items in submenu, set to 0 to disable.
}
opts.read_options(o)

local menu_prop = 'user-data/menu/items'
local menu_items = mp.get_property_native(menu_prop, {})
local menu_items_dirty = false
local dyn_menus = {}
local menu_prop = 'user-data/menu/items' -- menu data property
local menu_items = mp.get_property_native(menu_prop, {}) -- raw menu data
local menu_items_dirty = false -- menu data dirty flag
local dyn_menus = {} -- dynamic menu items
local has_uosc = false -- uosc installed flag

-- escape codec name to make it more readable
local function escape_codec(str)
Expand Down Expand Up @@ -326,12 +328,20 @@ local function update_playlist_menu(menu)
if not playlist or #playlist == 0 then return end

for id, item in ipairs(playlist) do
if o.max_playlist_items > 0 and id > o.max_playlist_items then break end
submenu[#submenu + 1] = {
title = build_playlist_title(item, id - 1),
cmd = string.format('playlist-play-index %d', id - 1),
state = item.current and { 'checked' } or {},
}
end

if o.max_playlist_items > 0 and #playlist > o.max_playlist_items then
submenu[#submenu + 1] = {
title = string.format('...\t[%d]', #playlist - o.max_playlist_items),
cmd = has_uosc and 'script-message-to uosc playlist' or 'ignore',
}
end
end

observe_property(menu, 'playlist', 'native', playlist_cb)
Expand Down Expand Up @@ -493,6 +503,11 @@ mp.register_script_message('update', function(keyword, json)
menu_items_dirty = true
end)

-- detect uosc installation
mp.register_script_message('uosc-version', function()
has_uosc = true
end)

-- commit menu items when idle, this reduces the update frequency
mp.register_idle(function()
if menu_items_dirty then
Expand Down

8 comments on commit 4cbabcb

@dyphire
Copy link
Contributor

@dyphire dyphire commented on 4cbabcb Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange changes, a large number of menu items not only exist in the playlist, but track and chapter lists may also appear.
There are have some track list with dozens of items, as well as some chapter list with hundreds of items. Do we all need to do this kind of processing? I think the real problem here is that the current menu cannot conveniently navigate a large number of menu items.

@tsl0922
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's rare to see so many tracks and chapters, but playlist may.

You may set max_playlist_items=0 to return to the previous behaviour.

@dyphire
Copy link
Contributor

@dyphire dyphire commented on 4cbabcb Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's rare to see so many tracks and chapters, but playlist may.

Some streaming videos may have dozens of audio and subtitle tracks, which is not uncommon. In addition, YouTube's automatic subtitle generation may generate dozens of subtitle tracks.

Examples from hundreds of chapters refer to mpvnet-player/mpv.net#442

You may set max_playlist_items=0 to return to the previous behaviour.

Restoring the original behavior is not the focus, but rather this commit is just hiding rather than solving the problem.

@tsl0922
Copy link
Owner Author

@tsl0922 tsl0922 commented on 4cbabcb Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't solve the problem with menu only. If you don't like it, you can disable it or improve it with PR, all the #@ features are optional.

The solution (including playlist support) is just for lazy people like me that don't want to search for another script that do better.

@dyphire
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What confuses me here is whether it is possible to allocate some key binding when the menu is opened, such as HOME END PGUP and PGDOWN for more convenient navigation of a large number of menu items. If possible, we don't need this compromise method.

@tsl0922
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't want to make it complicated, large numbers of menu items is not a good practice though.

@dyphire
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't want to make it complicated, large numbers of menu items is not a good practice though.

Okay, if you're not willing to do this, I think you can explain the dynamic menu content that may generate a large number of menu items in the document and remind people to cooperate with other suitable scripts to improve the user experience.

@tsl0922
Copy link
Owner Author

@tsl0922 tsl0922 commented on 4cbabcb Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, Windows API doesn't remind you too. It maybe a guideline, but shoud not be an enforcement.

Everyone has their own preferences, I'm not going to advise how do they use this plugin is better or not.

Please sign in to comment.