select.lua: add a miscellaneous menu

This commit is contained in:
Guido Cella
2025-01-08 11:56:13 +01:00
committed by Kacper Michajłow
parent 24db17d10f
commit 3e0b3373df
3 changed files with 66 additions and 0 deletions

View File

@@ -341,6 +341,9 @@ g-b
g-r g-r
Show the values of all properties. Show the values of all properties.
MENU
Show a menu with miscellaneous entries.
See `SELECT`_ for more information. See `SELECT`_ for more information.
(The following keys are valid if you have a keyboard with multimedia keys.) (The following keys are valid if you have a keyboard with multimedia keys.)

View File

@@ -191,6 +191,7 @@
#g-w script-binding select/select-watch-later #g-w script-binding select/select-watch-later
#g-b script-binding select/select-binding #g-b script-binding select/select-binding
#g-r script-binding select/show-properties #g-r script-binding select/show-properties
#MENU script-binding select/menu
#Alt+KP1 add video-rotate -1 # rotate video counterclockwise by 1 degree #Alt+KP1 add video-rotate -1 # rotate video counterclockwise by 1 degree
#Alt+KP5 set video-rotate 0 # reset rotation #Alt+KP5 set video-rotate 0 # reset rotation

View File

@@ -579,3 +579,65 @@ mp.add_key_binding(nil, "show-properties", function ()
end, end,
}) })
end) end)
mp.add_key_binding(nil, "menu", function ()
local sub_track_count = 0
local audio_track_count = 0
local video_track_count = 0
local text_sub_selected = false
local is_disc = mp.get_property("current-demuxer") == "disc"
local image_sub_codecs = {["dvd_subtitle"] = true, ["hdmv_pgs_subtitle"] = true}
for _, track in pairs(mp.get_property_native("track-list")) do
if track.type == "sub" then
sub_track_count = sub_track_count + 1
if track["main-selection"] == 0 and not image_sub_codecs[track.codec] then
text_sub_selected = true
end
elseif track.type == "audio" then
audio_track_count = audio_track_count + 1
elseif track.type == "video" then
video_track_count = video_track_count + 1
end
end
local menu = {
{"Subtitles", "script-binding select/select-sid", sub_track_count > 0},
{"Secondary subtitles", "script-binding select/select-secondary-sid", sub_track_count > 1},
{"Subtitle lines", "script-binding select/select-subtitle-line", text_sub_selected},
{"Audio tracks", "script-binding select/select-aid", audio_track_count > 1},
{"Video tracks", "script-binding select/select-vid", video_track_count > 1},
{"Playlist", "script-binding select/select-playlist",
mp.get_property_native("playlist-count") > 1},
{"Chapters", "script-binding select/select-chapter", mp.get_property("chapter")},
{is_disc and "Titles" or "Editions", "script-binding select/select-edition",
mp.get_property_native("edition-list/count", 0) > 1},
{"Audio devices", "script-binding select/select-audio-device", audio_track_count > 0},
{"Key bindings", "script-binding select/select-binding", true},
{"History", "script-binding select/select-watch-history", true},
{"Watch later", "script-binding select/select-watch-later", true},
{"Stats for nerds", "script-binding stats/display-page-1-toggle", true},
{"File info", "script-binding stats/display-page-5-toggle", true},
{"Help", "script-binding stats/display-page-4-toggle", true},
}
local labels = {}
local commands = {}
for _, entry in ipairs(menu) do
if entry[3] then
labels[#labels + 1] = entry[1]
commands[#commands + 1] = entry[2]
end
end
input.select({
prompt = "",
items = labels,
submit = function (i)
mp.command(commands[i])
end,
})
end)