61 Commits

Author SHA1 Message Date
Guido Cella ae3189567b select.lua: add select-secondary-subtitle-line
Requested in https://github.com/mpv-player/mpv/pull/17730#issuecomment-4321224996
2026-04-26 08:55:42 +02:00
Guido Cella 77ed8fef88 select.lua: use sub-lines instead of forking to ffmpeg
This:

- Removes the dependency of ffmpeg in PATH - useful on Windows, macOS
  (?), Flatpak.
- Will support subrandr.
- Avoids redownloading network subtitles.
- Avoids slow demuxing of large mkvs.
- But no longer returns future lines of embedded subtitles.
- No longer returns embedded lines of regions you seeked beyond without
  playing them.
- Changing sub track drops cached subtitles.
2026-04-25 19:58:52 +02:00
bennyyip 74d3c80640 select.lua: add confirmation on "Clear history" 2026-04-17 19:30:27 +02:00
nanahi 1839da1d07 select.lua: use _name key for mp.command_native 2026-04-06 18:33:20 +02:00
Kacper Michajłow 396bf65ec5 select.lua: fix crash on user_profiles sort
The list is filtered, so we need to not use index of the input.

Fixes: Lua error: attempt to compare string with nil
2026-03-08 11:50:08 +01:00
Simon Bruder 534b2d2ea6 {demux,player}: expose original and commentary track flags
Those flags were added to the Matroska specification together with the
already implemented hearing-impaired and visual-impaired flags.

They allow specifying whether a track is a commentary track or in the
original language without relying on the free-form track name, which
makes consistent tagging and parsing by machines easier.

Ref: https://github.com/ietf-wg-cellar/matroska-specification/pull/447
Ref: https://www.rfc-editor.org/rfc/rfc9559#name-original-flag
Ref: https://www.rfc-editor.org/rfc/rfc9559#name-commentary-flag
2026-02-20 20:31:04 +01:00
Guido Cella aa82213726 select.lua: don't set an empty prompt
Not needed since 44816ef8ff.
2026-02-15 16:36:28 +01:00
Guido Cella 102e693f49 select.lua: sort the track submenu
track-list doesn't necessarily return tracks sorted by type so we need
to sort them ourselves.
2026-02-14 01:07:27 +01:00
verygoodlee 70c893988a select.lua: quote and escape string arguments in menu item commands
try to define a `[foo \ "bar"]` profile in mpv.conf, the command
to apply it in context-menu is `apply-profile foo \ "bar"`,
which is obviously incorrect, the correct command should be
`apply-profile "foo \\ \"bar\""`.

for string arguments that may contain spaces or some special
characters, we need to quote and escape them in JSON-style,
fortunately, `utils.format_json` can do this very well.
2026-02-05 16:14:48 +01:00
Guido Cella d6eeff690d select.lua: handle empty lines at the end of the file
Prevent a crash in this case due to lines[i + 1] being nil.
2026-01-31 14:26:04 +01:00
Guido Cella a0f593202a select.lua: handle carriage returns in menu.conf
Fixes https://github.com/mpv-player/mpv/pull/16816#issuecomment-3804029038
2026-01-31 14:26:04 +01:00
Guido Cella 01cb6433c0 select.lua: always observe --osd-playlist-entry
The playlist submenu does not update in this edge case:

- Have a playlist-count > 99 on the first vo-configured. This makes
  playlist() return before observing --osd-playlist-entry.
- Remove playlist entries until the count is < 100
- Change --osd-playlist-entry
- Show the playlist submenu before changing the playlist
2026-01-30 10:53:19 +01:00
Guido Cella d79172ac3e select.lua: update the playlist submenu after playlist-move
Observing playlist-pos and playlist-count is not enough to update it
after playlist-move, but we can observe any playlist property with type
none to get notified of every MP_EVENT_CHANGE_PLAYLIST, even if the
property has not changed.

This is similar to the
mp.observe_property("vsync-jitter", "none", recorder) hack used by
stats.lua to replicate the deprecated tick event.

Fixes https://github.com/mpv-player/mpv/pull/16816#discussion_r2727498518
2026-01-28 15:21:38 +01:00
Guido Cella f4b37b6455 select.lua: populate the context menu
Make select.lua parse menu.conf on the first vo-configured and fill
menu-data with the properties referenced in menu.conf change. This is
disabled in the libmpv profile.

This is done from select.lua to reuse functions to format the data and
retrieve key bindings.

There is also a script-binding that opens the correct context menu
depending on --load-context-menu.

While the context menu is scrollable, for the playlist it is better to
start from around the current entry rather than from the beginning, and
since menu-data has no way to specify where to start, when there are
more than 25 items playlist items this adds … entries that open the
scrollable console menu when clicked.

input-bindings is parsed to show the shortcuts bound to commands. Since
it is not observable, it just uses the bindings from the first time the
context menu is opened.

Multimedia and numpad keys are also not shown to reduce clutter.

The old Context Menu section of the docs is merged in the more detailed
context_menu.rst to not repeat the same information.
2026-01-25 20:56:42 +01:00
Guido Cella 8f2d69e1cc select.lua: skip key bindings of forced input sections
Avoid showing forced key bindings by modal scripts that temporarily
overwrite keybindings, like console and stats. These have section
input_forced_$scriptName. Unfortunately this skips all keybindings added
with mp.add_forced_key_binding even if you may want to show them.

Also skip the OSC sections "input" and "window-controls"; these sections
are not called input_forced_osc because the OSC uses
mp.enable_key_bindings() directly instead of mp.add_key_binding().

This mainly benefits the shortcuts in the context menu that the next
commit will add, but is also useful select/select-binding.
2026-01-25 20:56:42 +01:00
Filip Hejsek ed83c7c51e select.lua: add dvb_subtitle to the list of image subtitle codecs 2026-01-24 14:07:37 +01:00
Guido Cella 833e2f254e select.lua: link to mpv's IRC channel in the menu
Add a menu entry that opens mpv's IRC channel so users can quickly ask
support questions.
2026-01-21 11:27:07 +01:00
Guido Cella 8bbcdec992 Revert "{osc,select}.lua: show playlist entries with trailing /"
This reverts commit ee05804bfa. Only the
select.lua part since osc.lua list formatting was removed.

Since playlist/N/filename is now normalized, it is never going to have
trailing slashes so there is no need to strip them.
2026-01-12 15:10:37 +00:00
Guido Cella d15f34b24e select.lua: preserve empty LRC lines
Subtitle extraction preserves empty lines in LRC subtitles because they
are useful for separating verses and choruses. 036fae317c changed their
sub codec from subrip to text, so update select.lua accordingly.
2025-12-27 15:42:16 +01:00
Guido Cella 67330ba2de select.lua: don't go beyond the max line length
Fixes 7be6095c23.
2025-10-10 08:44:03 +02:00
rach-md 7be6095c23 select.lua: rename some menus with proper name 2025-10-10 06:14:07 +02:00
Guido Cella f147b133f0 select.lua: add online documentation menu entry 2025-09-20 18:10:23 +02:00
Guido Cella 7c1a4acdb2 select.lua: add edit-config-file and edit-input-conf
Add script bindings to edit mpv.conf and input.conf, and add them to the
menu. These are useful as shortcuts, but the main motivation is that new
users often ask why they can't find mpv.conf and input.conf, so this
creates them if they don't exist.
2025-09-20 18:10:23 +02:00
dyphire 3f6038f6cc select.lua: refactor subtitle parse
Avoid repeated display of the same content at the same subtitle time

Keep blank lines for both lrc and srt formats
2025-07-06 17:18:10 +02:00
Guido Cella b554d43cde select.lua: display editions when before the first edition
When the first edition is not at the start of the file but after the
current time position, the current-edition property is -1, which
prevented displaying any edition.

Fixes https://github.com/mpv-player/mpv/issues/16073#issuecomment-2787316609
2025-04-17 00:07:22 +02:00
verygoodlee f837e951af select.lua: simplify the time formatting function
The C version of time formatting function has been exposed to lua,
so why not use it, `osc.lua` and `stats.lua` are already using it.
2025-03-31 11:57:06 +02:00
Guido Cella 6171e4800c select.lua: display chapters when before the first chapter
When the first chapter is not at the start of the file but after the
current time position, the chapter property is -1, which prevented
displaying any chapter.

Fixes #16073.
2025-03-19 12:28:44 +01:00
Guido Cella 66659a4b15 select.lua: don't quickly close and reopen the menu
Use the new keep_open flag to avoid flicker when opening submenus.
2025-02-24 16:26:58 +01:00
Guido Cella b848ffad12 select.lua: fix LSP warning
I don't know why I didn't get it before but Lua's LSP now complains with

Compute `"Edition " .. (edition.id + 1)` first. You may need to add
brackets. [ambiguity-1].

Just move the parenthesis to make it happy.
2025-02-22 15:32:27 +01:00
Guido Cella d840e7846c select.lua: don't add File info to the menu when no file is playing 2025-02-21 15:45:37 +01:00
Guido Cella 73b84595a8 select.lua: change the --save-watch-history warning text
The current warning was fine when you select history directly, but
giving more information can be useful when you happen to see it by right
clicking the title without prior information.

Fixes https://github.com/mpv-player/mpv/pull/15655#discussion_r1948053973
2025-02-09 23:30:54 +01:00
Guido Cella 3e0b3373df select.lua: add a miscellaneous menu 2025-01-27 21:06:50 +01:00
Guido Cella e2090533cf select.lua: select from the watch history with g-h
Implement selection of the entries in the watch history.

The last entry in the selector deletes the history file.
2025-01-27 18:53:28 +01:00
Guido Cella 20375d1133 select.lua: show the ID of editions without title
MKV editions can have no title. Print "Edition" and their IDs instead of
showing an empty selection.
2025-01-24 04:35:36 +00:00
Guido Cella 7a59a12b76 select.lua: select files with watch later files with g-w
Implement selection of files to resume playing from watch later config
files. Requires --write-filename-in-watch-later-config.
2025-01-05 23:21:50 +01:00
Guido Cella 0c3c4a315b select.lua: use mp.msg.warn for unavailable messages 2025-01-05 23:21:50 +01:00
Guido Cella 50a3da73b7 select.lua: fix select-edition crash on non-MKVs
In files other than MKVs edition-list is an empty table, not nil. It is
current-edition that is nil.

However nil still needs to be checked to not crash with mpv --idle.
2024-12-31 10:13:38 +01:00
Guido Cella 5e4b825a48 select.lua: abort edition selection when there's only 1
MKVs have 1 edition by default so don't show an empty edition selection
in that case.
2024-12-13 03:46:03 +01:00
Guido Cella 43f4568816 select.lua: select editions 2024-12-02 21:44:18 +01:00
Guido Cella e3eeaec813 select.lua: don't use add_forced_key_binding
There's no advantage in using the forced version here. It is a leftover
from when this was an external script and forced was necessary to bind
key sequences reliably until 3f83671f20.
2024-09-19 13:57:39 +00:00
Guido Cella ee05804bfa {osc,select}.lua: show playlist entries with trailing /
If a playlist entry ends with a slash these scripts only show the
basename which is empty. Fix this by stripping trailing slashes so that
the last directory component becomes the basename.
2024-08-06 20:27:33 +02:00
Guido Cella 5f768a688b loadfile,select.lua: print only one bitrate
Print demux-bitrate if available, else hls-bitrate, not both (as
demux-bitrate is generally more reliable). This avoids printing "HLS
kbps" which looks weird.

Fixes
https://github.com/mpv-player/mpv/pull/14453#discussion_r1700550385
2024-08-02 08:41:43 +02:00
Guido Cella 5f8ac5b862 loadfile,select.lua: print bitrates of tracks 2024-07-18 22:52:35 +02:00
Guido Cella 7bcd525dce various: sync shown track flags
Show the same flags in loadfile.c, select.lua and stats.lua. The only
differences are that only stats.lua prints both image and albumart
because it's supposed to show detailed track information, and select.lua
prints the image flag because pressing g-v doesn't show Video or Image
like in loadfile.c and stats.lua.
2024-07-18 22:52:35 +02:00
Guido Cella 2fd88ffbae various: print Image instead or Video for image tracks
Fixes #8561.
2024-07-18 22:52:35 +02:00
Guido Cella 82ffe8f425 loadfile: update the format of terminal track information
Stop making unselected tracks and editions grey because they can be hard
to read over a dark background (\033[2m would be hard to differentiate
from regular text with a light theme instead), and because there is no
way to not print the escape sequences in --log-file.

Just use the same circles as the OSD and OSC. We need to print the empty
circles for alignment on mlterm with East Asian fonts (we could also
make them invisible with \033[8m but it would still get added to log
files).

Add back the space before tracks and editions when printed after
"Playing..." or "Track switched" and similar, so they look like a
sub-section of it, consistently with the metadata which starts with
space which makes it look like a sub-section of the "File tags" line.

Leave 2 spaces between track columns.

Make the lang options only as long as the longest language.

Place hls-bitrate within the same parentheses as the other data.

Replace the incomprehensible (*) (f) and [P] with textual descriptions
within []. Also place external there.

Stop converting Hz to kHz for consistency with other log messages, e.g.
AO: [pipewire] 48000Hz stereo 2ch floatp

Remove the space in "2 ch" so it doesn't look like 2 separate values (We
considered using mp_chmap_to_str(&s->codec->channels) but it prints
values like "unknown2").
2024-06-24 16:19:31 +02:00
Guido Cella 8873beabc3 select.lua: consider --sub-delay for the subtitle line selector
Preselect and seek to the correct subtitle line when there is a
sub-delay.

Also slightly increase the offset without a video track else it
occasionally doesn't seek to the selected line with non-0 sub-delay and
no video. This now uses the same offset as sub/sd.h.
2024-06-22 13:42:27 +00:00
Guido Cella e3f496dbf5 select.lua: don't use sub-start to preselect subtitle lines
There is no need to compare sub-start now that we don't check for exact
matches with ffmpeg's timestamps. time-pos can always be used.

Comparing time-pos removes the need for the workaround of sub-start of
embedded subtitles being earlier than ffmpeg's timestamps, as time-pos
is always slightly after sub-start.

Removing this workaround also fixes a bug present since 4059d1832b,
which started comparing numerical values of timestamps instead of
strings to determine the preselected subtitle line, where the line after
the current one is preselected when sub-start is greater than ffmpeg's
timestamps because they have been rounded, e.g. sub-start 10.001 is >
than ffmpeg's 10.00.

This will also allow considering --sub-delay in the comparisons, as
comparing sub-start - sub-delay would preselect the wrong lines.
2024-06-22 13:42:27 +00:00
Guido Cella dc998560aa options: add --osd-playlist-entry
Allow configuring whether to print the media-title, the filename or both
(as `<title> (<filename>)`) in show-text ${playlist}, the OSC playlist
and in the playlist selector.

Showing only titles hides information when files are badly tagged, or
when it hides the track numbers of album songs. But showing filenames is
not as useful as titles e.g. when playing URLs with media titles. This
option lets the user choose which one to show, or show both if switching
is inconvenient.

The OSC's playlist_media_title script-opt is removed because this option
is better since it works everywhere after configuring it once.

Closes #11653.

Also show the full URLs of playlist entries instead of their basenames
in osc.lua and select.lua, consistently with mp_property_playlist().

For simplicity, this just checks if entries contain :// instead of
replicating all of mp_is_url().

Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
2024-06-08 01:43:15 +02:00
Guido Cella 75645263dd select.lua: support extracting ytdl_hook subtitles
They don't work because they have EDL URLs, but we can attempt to
extract their real URLs.
2024-06-07 22:45:41 +02:00