Skip to content

Commit

Permalink
select.lua: add this script
Browse files Browse the repository at this point in the history
This adds script messages to select playlist entries, tracks, chapters,
subtitle lines, bindings and properties using the newly introduced
mp.input.select().

This fully closes #13964.
  • Loading branch information
guidocella authored and kasper93 committed May 12, 2024
1 parent 367a6b5 commit 61f72bd
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 2 deletions.
40 changes: 40 additions & 0 deletions DOCS/man/mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,46 @@ Alt+2 (and Command+2 on macOS)
Command + f (macOS only)
Toggle fullscreen (see also ``--fs``).

(The following keybindings open a selector in the console that lets you choose
from a list of items by typing part of the desired item and/or by navigating
them with keybindings: ``Down`` and ``Ctrl+n`` go down, ``Up`` and ``Ctrl+p`` go
up, ``Page down`` and ``Ctrl+f`` scroll down one page, and ``Page up`` and
``Ctrl+b`` scroll up one page.)

g-p
Select a playlist entry.

g-s
Select a subtitle track.

g-S
Select a secondary subtitle track.

g-a
Select an audio track.

g-v
Select a video track.

g-t
Select a track of any type.

g-c
Select a chapter.

g-l
Select a subtitle line to seek to. This currently requires ``ffmpeg`` in
``PATH``, or in the same folder as mpv on Windows.

g-d
Select an audio device.

g-b
Select a defined input binding.

g-r
Show the values of all properties.

(The following keys are valid if you have a keyboard with multimedia keys.)

PAUSE
Expand Down
4 changes: 4 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@ Program Behavior
`Conditional auto profiles`_ for details. ``auto`` will load the script,
but immediately unload it if there are no conditional profiles.

``--load-select=<yes|no>``
Enable the builtin script that lets you select from lists of items (default:
yes). By default, its keybindings start with the ``g`` key.

``--player-operation-mode=<cplayer|pseudo-gui>``
For enabling "pseudo GUI mode", which means that the defaults for some
options are changed. This option should not normally be used directly, but
Expand Down
12 changes: 12 additions & 0 deletions etc/input.conf
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@
#ctrl+h cycle-values hwdec "auto-safe" "no" # toggle hardware decoding
#F8 show-text ${playlist} # show the playlist
#F9 show-text ${track-list} # show the list of video, audio and sub tracks
#g ignore
#g-p script-binding select/select-playlist
#g-s script-binding select/select-sid
#g-S script-binding select/select-secondary-sid
#g-a script-binding select/select-aid
#g-v script-binding select/select-vid
#g-t script-binding select/select-track
#g-c script-binding select/select-chapter
#g-l script-binding select/select-subtitle-line
#g-d script-binding select/select-audio-device
#g-b script-binding select/select-binding
#g-r script-binding select/show-properties

#
# Legacy bindings (may or may not be removed in the future)
Expand Down
2 changes: 2 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ static const m_option_t mp_opts[] = {
{"load-auto-profiles",
OPT_CHOICE(lua_load_auto_profiles, {"no", 0}, {"yes", 1}, {"auto", -1}),
.flags = UPDATE_BUILTIN_SCRIPTS},
{"load-select", OPT_BOOL(lua_load_select), .flags = UPDATE_BUILTIN_SCRIPTS},
#endif

// ------------------------- stream options --------------------
Expand Down Expand Up @@ -969,6 +970,7 @@ static const struct MPOpts mp_default_opts = {
.lua_load_stats = true,
.lua_load_console = true,
.lua_load_auto_profiles = -1,
.lua_load_select = true,
#endif
.auto_load_scripts = true,
.loop_times = 1,
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ typedef struct MPOpts {
bool lua_load_stats;
bool lua_load_console;
int lua_load_auto_profiles;
bool lua_load_select;

bool auto_load_scripts;

Expand Down
2 changes: 1 addition & 1 deletion player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ typedef struct MPContext {

struct mp_ipc_ctx *ipc_ctx;

int64_t builtin_script_ids[5];
int64_t builtin_script_ids[6];

mp_mutex abort_lock;

Expand Down
3 changes: 3 additions & 0 deletions player/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ static const char * const builtin_lua_scripts[][2] = {
},
{"@auto_profiles.lua",
# include "player/lua/auto_profiles.lua.inc"
},
{"@select.lua",
# include "player/lua/select.lua.inc"
},
{0}
};
Expand Down
2 changes: 1 addition & 1 deletion player/lua/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lua_files = ['defaults.lua', 'assdraw.lua', 'options.lua', 'osc.lua',
'ytdl_hook.lua', 'stats.lua', 'console.lua', 'auto_profiles.lua',
'input.lua', 'fzy.lua']
'input.lua', 'fzy.lua', 'select.lua']
foreach file: lua_files
lua_file = custom_target(file,
input: join_paths(source_root, 'player', 'lua', file),
Expand Down
Loading

0 comments on commit 61f72bd

Please sign in to comment.