Commit Graph

3720 Commits

Author SHA1 Message Date
Kacper Michajłow 08e2acbae1 stats.lua: don't use io.write from builtin script
Scripts and especially internal scripts shouln't bypass msg.c logging
code for various resons, ranging from processing the input, filtering
the log levels, truncating the output and so on. io.write() is lazy way
of outputing to stdout without respecting mpv's logging module.

Uses osd message, because this has no prefixes. Added internal
flush-status-line command to flush current output without clearing
before exiting.

This commit will allow us to remove duplicated terminal handling code
from stats.lua, mpv core already handles all that and does it in better
way, without taking shortcuts.
2024-10-17 22:32:10 +02:00
Kacper Michajłow c3404fdf37 console.lua: don't clear not ours osd messages
Note that this still is not perfect, because if osd message is changed,
console cannot know about it and would still clear it, but this change
make it at least not do it to every message even if console is not used.
2024-10-17 22:32:10 +02:00
Guido Cella 50faafd8bd stats.lua: exit with ESC if being toggled
If not opened in oneshot mode, close the stats with ESC. Especially now
that ? toggles showing key bindings by default, this provides an
intuitive way to close the stats.

Also do some minor reformatting of key binding documentation.
2024-10-17 16:57:35 +02:00
Guido Cella 1a558bf5c2 osc.lua: remove NIH list formatting
All of the code to format playlist/track-list/chapter-list is
unnecessary when mpv's core can already show-text these properties.

Also an issue with this custom formatting is that showing fewer entries
than can fit on the OSD can make it seem like the playlist ends there
and there are no entries afterwards.

Also remove lots of pointless code around the track-list (mpv's track id
and the osc_id are exactly the same).

This simplification will make it easier to bind customizable commands,
otherwise yet another script message to call set_track would have to be
added, when cycle sub/audio already output information about the new
track on their own.
2024-10-16 15:10:23 +02:00
Guido Cella 3522dd836e command: implement printing ${track-list/{video,audio,sub}}
This brings show-text ${track-list} in line with osc.lua's
get_tracklist(type) before replacing it with show-text.
2024-10-16 15:10:23 +02:00
Guido Cella 89d78369c6 command: print the number of chapters in show-text ${chapter-list}
Call cut_osd_list() like with ${playlist} to print position/count above
the chapters. This is useful for movies with many chapters.

Stop printing the chapter numbers because they are not useful here, they
are only useful when navigating to a chapter.

Remove one of the spaces before the circles because they are too many.

This replicates osc-chapterlist before replacing it with show-text
${chapter-list}.
2024-10-16 15:10:23 +02:00
Guido Cella 841b66d3ec command: consider the terminal height in cut_osd_list()
cut_osd_list() calls osd_get_text_size() even when outputting to the
terminal, which results in max_lines = 19. Use the actual terminal
height instead.
2024-10-16 15:10:23 +02:00
Guido Cella be1be8ca61 command: print position/count in show-text ${playlist}
...instead of "n hidden items". This brings it in line with osc-playlist
before replacing it with show-text ${playlist}. Also make count_lines()
return the correct count.
2024-10-16 15:10:23 +02:00
Guido Cella 0f74b1bc2d console.lua: improve hovered line calculation
- Don't do anything if clicking on the top counter, the input line or
  the new line between the items and the input line

- Don't scroll upwards when hovering the counter

- Don't redraw before clicking to avoid quickly updating the overlay
  before closing it with touch input, where the item you touch can be
  different from the one that was highlighted
2024-10-16 14:29:21 +02:00
Guido Cella b0f1830a8e console.lua: make the wheel scroll selectable items instead of the match
This makes scrolling with the wheel more usable because it doesn't
matter if the focused item is reset by moving the mouse slightly, and
scrolling always begins immediately.

This makes the MBTN_MID binding to handle_enter() unnecessary so it is
removed.
2024-10-16 14:29:21 +02:00
Guido Cella e88a1a7de7 console.lua: print position/count instead of n hidden items
This makes it consistent with the new changes to show-text ${playlist}
and greatly simplifies the logic, making it sane to implement scrolling
the view with the wheel in the commit.
2024-10-16 14:29:21 +02:00
Dudemanguy 0721b87237 player: make redraw_sub flag work on a per track basis
There can be multiple subtitle tracks (secondary subs) so this logic
should be handled separately.
2024-10-16 02:26:06 +00:00
Dudemanguy fe758a1761 player/command: destroy cached packets after UPDATE_SUB_{FILT,HARD}
Otherwise, the index can technically grow forever because
sub_read_packets will trigger again, read the same packets, then add
them to the list. We should just clear the cache here in this case to
reset it back to 0. Also flag redraw_subs here as well.
2024-10-16 02:26:06 +00:00
Dudemanguy d2d8667259 player: move a redraw_subs edgecase to loadfile
Putting this in handle_osd_redraw was strange and my own comments didn't
help me remember what this was even for. The actual purpose here is that
the osd needs to be redrawn in the still image edge case as you go
through a playlist. This is because all the logic with checking
timestamps isn't applicable and we need to essentially clear the screen
with another redraw. Clearly, it makes more sense for this to be done
when a new file is successfully loaded and not in the osd_redraw where
that happens to work but was called repeatedly pointlessly.
2024-10-16 02:26:06 +00:00
Dudemanguy dfe3edee76 player/sub: avoid pointlessly redecoding subs
This was added in 8f043de961 but the
redecode is a special case that is only ever needed for subtitles on a
still image. Normal video never needs this so just modify the
conditional to avoid doing more work.
2024-10-16 02:26:06 +00:00
Guido Cella 661bd61af8 console.lua: center selectable items around the default item 2024-10-14 20:14:27 +02:00
Guido Cella 3e63c97677 console.lua: highlight the select menu's preselected item
Requested in
https://github.com/mpv-player/mpv/pull/14087#issuecomment-2110889436 and
https://github.com/mpv-player/mpv/pull/15031#issuecomment-2401328081

This is mainly useful to keep highlighting the current playlist entry
after moving the mouse.
2024-10-14 20:14:27 +02:00
Guido Cella ad0c29e5ac console.lua: close with right click
Useful to close the console after it was opened with the mouse.

Also fix the spacing of the previous line.
2024-10-14 20:14:27 +02:00
nanahi 86e8cae9ca stats.lua: add nonscalable prefix to cmd_prefixes 2024-10-14 01:55:49 +02:00
nanahi 72a705c598 console.lua: add nonscalable prefix to command_prefixes 2024-10-14 01:55:49 +02:00
Guido Cella e34f6569ee stats.lua: rename a variable 2024-10-12 21:24:41 +02:00
Guido Cella ba3b4eda64 console.lua: use ${term-clip-cc} to clip lines
Instead of considering every non-ASCII character 2-cell wide, use this
newly introduced property to let msg.c clip the select menu using all
available with.
2024-10-11 15:31:17 +02:00
Kacper Michajłow bf025cd289 msg: allow to truncate the message to terminal width 2024-10-11 15:16:33 +02:00
Crend King c8860fd816 ytdl_hook.lua: always specify --write-srt
Currently by default mpv sets --all-subs when calling yt-dlp for JSON
info. --all-subs is an option that simply expands to --sub-langs all
--write-subs. --write-subs is special that without it yt-dlp will no
longer extract any subtitle info.

mpv's yt-dlp hook has a logic that if user specify any sub-langs in
--ytdl-raw-options, it no longer uses --all-subs. Unfortunately, this
means unaware users will not get any subtitle any more until they study
the mpv internal code and add their own --write-subs.

This PR always specifies --write-srt, an alias of --write-subs, in the
hook, so users don't have to. The alias is used to maintain
compatibility with youtube-dl.

Fixes issue #14818
2024-10-10 18:28:41 +02:00
Dudemanguy 901b9bc888 player/sub: ensure subtitles are updated for images with no audio
The video_pts condition here would bail out on still images with no
audio since their pts is always MP_NOPTS_VALUE. This is not exactly
great because the subtitles may need to be updated so just let these
files also go through the subtitle redraw logic below.
2024-10-10 13:17:47 +00:00
Guido Cella 6ed3781a3d ytdl_hook.lua: add include script-opt of URLs to try with ytdl first
By the default mpv tries opening URLs with ffmpeg first, and users who
don't configure try_ytdl_first get a slower startup for youtube URLs, on
top of yt-dlp already being slow.

Fix this by adding a script-opt of URL pattern to try with ytdl first.
Youtube and twitch are included by default.

Compared to the alternative of trying ytdl first by default and
excluding URLs with a media extension, this only works for the sites
explicitly included in the new option's value, but doesn't have false
positives on media URLs without an extension.
2024-10-09 01:08:31 +02:00
Guido Cella 92403a068c ytdl_hook.lua: lower case URLs for exclude matching 2024-10-09 01:08:31 +02:00
Mohammad AlSaleh 28a4e19a67 command: avoid division by zero in av_timecode_make_string()
`av_timecode_make_string()` divides by fps unconditionally. And
 relying on container_fps always carrying a meaningful value was
 misguided. So we now check that fps is non-zero before calling that
 function.

 Issue encountered with a couple of old FLV files triggering a segfault.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-10-09 00:36:35 +02:00
Guido Cella 8bf5548589 console.lua: allow clicking selectable items
This adds click support for the select menu. Scrolling with the wheel
already worked.

If a custom OSC binds a button to a select.lua script-binding, this lets
users keep using the mouse to select an item.

While the OSC and the select menu are open at the same time, you can no
longer click the OSC's buttons. By using mp.add_key_binding instead of
add_forced_key_binding you could click both, but the console's binding
would be shadowed by MBTN_LEFT bindings in input.conf.
2024-10-08 20:37:56 +02:00
Guido Cella 493cab7efc stats.lua: allow keybindings to toggle the display of a specific page
This lets you define bindings like h script-binding
stats/display-page-4-toggle. Requested in #14966.
2024-10-04 21:13:29 +03:00
Guido Cella be814e3753 stats.lua: scroll keybindings while filtering them
console.lua binds up and down to navigate its history. Add a private
flag to mp.input.get to instruct console.lua not to bind up and down, so
you can use them to scroll the keybindings page while filtering
keybindings.

If it is requested, this can be replaced with an argument to input.get
to not bind arbitrary keys.

Fixes #14966.
2024-10-04 21:13:29 +03:00
Guido Cella b3f8464fa9 input.lua,defaults.js: don't hardcode mp.input arguments
Pass everything in the tables passed by mp.input callers to console.lua
so new flags can be added without modifying these clients.

In Lua, callbacks have to be excluded from the argument tables to not
make utils.format_json() error, while with JSON.stringify they are
automatically omitted.
2024-10-04 21:13:29 +03:00
Guido Cella dcd681ecdd stats.lua: filter keybindings by comment
Requested in #14966.
2024-10-04 21:13:29 +03:00
Kacper Michajłow 7202406fe8 various: remove global.h inclusion where not needed 2024-10-01 12:23:44 +02:00
nanahi 151fa74806 player/external_files: fix null deref when cover-art-whitelist is empty
This can happen when using --cover-art-whitelist-clr.

Fixes: d384a6b793
2024-09-29 22:56:40 +02:00
Andreas Klauer c365e2f7b1 misc/random: seed using libavutil/random_seed
When starting multiple processes of `mpv --shuffle` in parallel,
sometimes the random seed happens to be identical, so files are
played in the same random order.

mp_rand_seed(0) now uses a random seed provided by libavutil,
and only falls back to time in case of failure.
2024-09-28 14:11:56 +02:00
Guido Cella 69ced646f8 lua: remove unused #define mp_lua_len
This is unused since 548ef07864 and 7f91e2684e.
2024-09-26 16:45:08 +02:00
Dudemanguy b52a67dde2 meson: bump required version to 1.3.0
Newer meson versions added support for features that mpv has been using
for a long time. Annoying fallbacks were left in place to not break old
versions but ideally everyone should be using the newer build features.
Both the latest ubuntu LTS and debian stable (in backports) have 1.5.0
in their repos, so go ahead and bump the version so we can drop some old
code and let developers use newer meson features if applicable.
2024-09-24 22:16:59 +00:00
Kacper Michajłow 1c55d600ab stats.lua: add timecode display 2024-09-24 19:47:42 +02:00
llyyr d33bcc51a7 command: add video-frame-info/{gop,smpte,estimated-smpte}-timecode
Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
2024-09-24 19:47:42 +02:00
Kacper Michajłow 2a1485772b console.lua: clear terminal msg after changing to OSD display 2024-09-24 19:21:00 +02:00
llyyr e538c7f413 player/main: guard smtc.h include 2024-09-23 22:13:51 +02:00
Dudemanguy 2bd1e78701 build: ensure HAVE_WIN32_SMTC is always defined
It makes sense to only descend into the subdirectory meson build file on
windows, but we should always make sure HAVE_WIN32_SMTC is 0 for other
platforms. Otherwise, it gets unneccesarily awkward to work with.
2024-09-23 22:13:51 +02:00
Guido Cella 68ea9fecda console.lua: fix the height calculation with --video-osd=no 2024-09-22 17:31:54 +02:00
Kacper Michajłow 71f2220991 meson: use relative file paths for file2string
This fixes "Generated from" comments to not include local source path in
generated files.
2024-09-21 23:39:10 +02:00
Maxim Biro ff47926d6a ytdl_hook: make path and json available to other scripts
It's useful for user scripts to be able to use the same ytdl binary that
ytdl_hook uses without having to replicate ytdl_hook's process of
searching for the ytdl binary.

Some user scripts might also find it useful to be able to access ytdl's
json output that the ytdl_hook already receives, sparing user scripts
from having to make a duplicate ytdl binary invocation to get the json
output.

Providing just the json output is not enough though, as ytdl doesn't communicate
errors though it -- if an error occurs, ytdl provides no json output and instead
prints to stderr. So without stderr, there is no way for user scripts to figure
out why ytdl has failed: no such username / video id, the channel is not live
yet, etc. Because of that, the entire result of the subprocess call is provided
to the user scripts, containing stdout (json), stderr, ytdl's exit code, etc.
2024-09-21 17:53:01 +02: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
llyyr 140196f297 ytdl_hook: fix typo (chapters -> chapter)
Fixes: ec966fb866
2024-09-19 13:55:58 +00:00
Guido Cella 030c283ef5 console.lua: respect --video-osd=no 2024-09-15 18:27:24 +02:00
Guido Cella 8592206c75 console.lua: truncate more characters with --msg-module and --msg-time
Fix the terminal width calculation for the select menu with these
options.
2024-09-15 18:27:24 +02:00