summaryrefslogtreecommitdiffstats
path: root/player/lua
<
Commit message (Collapse)AuthorAgeFilesLines
* osc: fix cache displaying 60s in some casesFunami5802021-11-271-2/+2
| | | | It was caused by string.format rounding e.g. 59.9 to 60.
* osc: add options: chapters/playlist OSD, hover chapter formatAvi Halachmi (:avih)2021-11-251-6/+17
| | | | | | | | | | | Previously OSD was always displayed on {ch,pl}_{next,prev} left-click, and seekbar-hover-chapter was always enabled and with fixed format. Now it can be controlled with: - chapters_osd, playlist_osd: yes/no (only affects left-click). - chapter_fmt: lua string.format template, or "no" to disable. Fixes #4675
* ytdl_hook.lua: improve check for sub language before inserting all-subsUmar Javed2021-11-151-1/+1
| | | | | | | youtube-dl and yt-dlp both support --sub-langs and --srt-lang in addition to --sub-lang for defining languages of subtitles. This hook only checked for sub-lang in --ytdl-raw-options and inserted --all-subs in its absence.
* console.lua: define remaining emacs keybindingsGuido Cella2021-11-011-3/+33
|
* osc.lua: avoid infinite ticks loop on idleAvi Halachmi (:avih)2021-10-031-1/+11
| | | | | | | | | | | | | | | Before this commit, animation-end was handled at render(), however, it's not called on idle, which resulted in state.anitype ~= nil, with nothing to reset it during idle, which caused in an infinite tick() loop (starts on first mouse move). Now tick resets the animation on idle, and also, as a safety measure, if we're past 1s after the animation deadline. The safety measure is because the osc states are complex, and it's easier to detect a "we really shouldn't be animating now" at tick() itself rather than detecting the exact states where animation should be reset. Generally, the safety mmeasure is not needed.
* osc.lua: unify animation reset function (no-op)Avi Halachmi (:avih)2021-10-031-6/+8
|
* ytdl_hook.lua: search for yt-dlp by defaultGuido Cella2021-09-251-18/+48
| | | | | | | | | | | Because youtube-dl is inactive and the yt-dlp fork is becoming more popular, make mpv use yt-dlp without any extra configuration. yt-dlp is ordered before youtube-dl because it's more obscure, so users who have yt-dlp installed are more likely to want to use it rather than youtube-dl. Fixes #9208.
* stats.lua: typo lavfi-complexStefan de Konink2021-08-151-2/+2
| | | | Fix typo lavi-complex to lavfi-complex.
* lua: read_options: quote values at error messagesAvi Halachmi (:avih)2021-08-101-3/+3
| | | | | | | This makes it easier to understand the error in cases of incorrect syntax or formatting at .conf files. (js already has this quoting). Fixes #9105
* stats.lua: page 4 (keys): group current-window-scale under windowGuido Cella2021-08-061-1/+1
| | | | | This groups "set current-window-scale ..." under the "window" group instead of "current" in the list of keybindings.
* stats.lua: page 4 (keys): better alignment of non-ascii keysAvi Halachmi (:avih)2021-07-311-2/+16
| | | | | | | | | | | | | | | | | | | | | | | Previously we assumed the key-name string occupies strlen(name) cells, now we count codepoints instead. This improves alignment of non-english key names. Still not perfect because we don't know if the key name is single or double width, but wcwidth not available to scripts, notoriously unreliable (depends on locale, correct and updated tables, etc), and also not always available (Windows). Still, better than nothing, and we err by at most one cell - vs up to three before this commit (4 bytes keyname codepoint). In the future we could do the alignment using libass tags, however, this both complicates the ass-output generation, and also not available when we output for the terminal, so for now only count codepoints. Also, if the key name was in a right-to-left language, then previously the name/command were swapped visually. Now we inject a left-to-right marker before the name to ensure direction. This works also when harfbuzz is disabled for libass (--sub-ass-shaper=simple).
* stats.lua: page 4 (keys): detect single-quotesAvi Halachmi (:avih)2021-07-301-2/+2
|
* stats.lua: fix ass-escape while persistent_overlay=yesAvi Halachmi (:avih)2021-07-251-14/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mpv has two methods to display output from text input: - show-text (scripting: mp.osd_message) has ass disabled by default (escaped), and the property osd-ass-cc can control escaping. - osd-overlay (scripting: mp.set_osd_ass or mp.create_osd_overlay) has ass enabled (unescaped), and osd-ass-cc is NOT supported. By default, stats.lua uses mp.osd_message which does support escaping. That's persistent_overlay=no. When using persistent_overlay=yes then mp.set_osd_ass is used. Due to this, the no_ASS(..) function - which is supposed to escape ass, simply returned its input unmodified when persistent_overlay is enabled. This is not a new issue, and the filters on page 1 use no_ASS() to no avail in persistent mode, however, this content (filter name and value strings) rarely actually needs escaping, and users didn't notice. However, the new page 4 (keys) does break visibly when no_ASS doesn't work, because it tries to escape arbitrary key-names and command strings, and at the very least the key '{' is bound by default, which is displayed incorrectly if escaping doesn't work. Fix this by rolling our own escaping when using mp.set_osd_ass, similar to how the mpv code does it for mp.osd_message (substrings replacements). However, this means that the set_ASS(..) function can no longer behave correctly because escaping requires going through the whole content string rather than only inserting a marker. Luckily, other than at no_ASS, set_ASS was only used at one place (text_style), which is only called from two places: - generate_graph() only needs to restore styles - not to enable ass. - add_header() is only used at the begining of page output, and uses set_ASS to enable ass initially when using mp.osd_message. So remove the set_ASS function, and instead enable ass directly at print_page using osd-ass-cc when mp.osd_message is used. Fixes #9022
* stats.lua: remove script-opts for the main keys (i/I)Guido Cella2021-07-211-4/+2
| | | | | | | Unlike the page switching/scrolling keys which are bound at runtime and therefore we need to know which (configured) keys to bind, the main keys (i/I by default) are static and can be bound via input.conf. And indeed, the builtin bindings at etc/input.conf have them already.
* stats.lua: page 4 (keys): fix "excluding stats keys" - attempt 2Avi Halachmi (:avih)2021-07-201-7/+7
| | | | | | | | | | | | | | | | | | Page 4 bindings listing wants to exclude the interactive keys of the stats script itself - so that they don't hide the normal keys which are bound when stats is not interactive. It did so by testing that the bound command includes stats/__key which is how it usually looks when a script binds keys. However, if a script uses a name for the binding - like stats.lua does for the interative keys (because it later removes them by name when interactive mode ends), then the command has stats/name rather than stats/__key... To fix this, we change the names of the forced interactive bindings to start with __forced_, and that's now also what the page-4 listing excludes.
* Revert "stats.lua: page 4 (keys): fix "excluding stats keys""Avi Halachmi (:avih)2021-07-201-3/+3
| | | | | | | | | | This reverts commit 0f1654811bda0dfdd337734ec33c59b67522234a. It was an incorrect fix, because the key names do get used - to remove the forced bindings once stats exits the interactive mode. And without names - the interactive keys remained active even after stats exited interactive mode.
* stats.lua: page 4 (keys): fix "excluding stats keys"Avi Halachmi (:avih)2021-07-201-3/+3
| | | | | | | | | | | | | | | The page 4 keybinding list tries to skip the interactive bindings of stats itself (because they would hide the normal bindings of these keys when stats is not visible), and to do that it excludes commands containing "script-binding stats/__key" - which is how script-added bindings usually look like. However, keys which are added with a "name" bind stats/name rather than stats/__key... - and that's what stats.lua did till now with its interactive force-bindings. Now the interactive forced bindings are added without a name, and so they do end up using the automatic stats/__key... and get excluded.
* stats.lua: page 4 (keys): support help-like terminal printoutAvi Halachmi (:avih)2021-07-191-2/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | While --input-test is useful, and so is page 4 of stats, until now there was no way to simply print the list in a help-like fashion. This commit adds such printout, invoked by the script opt stats-bindlist=yes, which uses the existing page 4 code. This prints the list on startup and quits immediately - like any help page. It's awkward to invoke compared to other help pages, and it does require the stats page to be enabled (it is by default), however it is a script-generated output, and currently there's no other method to print a help page generated by a script. The printout itself is performed using lua's io.write. While reliable, it's not the standard way for mpv to print to the terminal. Other possible printout methods are mp.msg.info - which also prints "[stats]" prefix on each line (ugly), or forcing term-osd and setting an osd-message which mpv will then print at the terminal - however that's printed to stderr, and could also be subject to timing concerns since we quit right afterwards. In the future we can consider changing/integrating the invocation so that mpv itself could print a help page generated by a script, thus solving both the awkward invocation and printout-method issues.
* stats.lua: add page 4: active key-bindings listAvi Halachmi (:avih)2021-07-191-0/+151
| | | | | | | | | | | | | This is a scrollable page which also works nicely with the terminal OSD. Typically there are more than 100 bound keys. It groups the binding using fuzzy property/command/script name after simple analysis of the command string, and then further sorts the binding in each group according to the "complexity" of the key itself (plain keys -> keys with modifiers, alphabetically, etc). The alignment/grouping style is heavily inspired by @medhefgo's #8924 but otherwise it's an independent implementation.
* stats.lua: scroll: allow throttling page-rebuild (no-op)Avi Halachmi (:avih)2021-07-191-4/+5
| | | | | | | | | | | | | | | Typically the current page is rebuilt and rendered once per second, howeve, scrolling can invoke the rebuild function very frequently, even at a rate which is too fast for the rebuild function to keep up. This can result in high CPU usage and input lag. This commit adds an argument to the page-rebuild function, letting it know whether or not it's called following a scroll keypress, thus allowing it to cache intermediate data so that it doesn't have to re-calculate the whole page from scratch. This additional argument is unused currently, but it could be useful for the internal performance page - which can be relatively heavy.
* stats.lua: move internal performance from page 4 to page 0Avi Halachmi (:avih)2021-07-191-3/+3
| | | | | This allows adding more pages without the internal performance page getting stuck at the middle of the list.
* lua: fix timers comment (no-op)Avi Halachmi (:avih)2021-07-131-2/+3
| | | | | process_timers() doesn't return an absolute time. It returned delta>0 or nil before f73814b1 , and since f73814b1 it can also return 0.
* osc: expose osc-visibility via shared-script-propertiesAvi Halachmi (:avih)2021-07-061-0/+1
| | | | | | | | | | | | | | | | osc-visibility can already be changed at runtime via script-message or other means, but until now there was no way to tell what the current state is. Now shared-script-properties/osc-visibility reflects this state. It's output-only by the osc - changing it does not affect the osc. Useful if a script wants to change osc-visibility temporarily, and later restore to its original state. There's no way to coordinate if more than one script wants to change it, but that would be a hard problem to solve anyway, even if the osc itself tried to coordinate such requests from different sources.
* stats.lua: add scaled resolutionDudemanguy2021-06-251-0/+7
| | | | | Calculate the actual scaled size of the video from osd-dimensions and display it on the stats page.
* lua: idle observers: ensure timers are up-to-dateAvi Halachmi (:avih)2021-06-231-0/+9
| | | | | | | | | | | | | | | This fixes two issues, both of which resulted from the timers-wait period not being re-calculated after idle-observers were executed: - If timers were added from an idle observer then they could fire long after they were due (only when/if the next mpv event arrives). - Idle observers don't execute in zero time, and the wait period for the next timer was implicitly extended by the idle observers execution time (because it was calculated before the idle observers). This commit ensures that if idle-observers were executed, then the timers wait period is re-calculated, which solves both issues.
* lua: timers: don't block forever with slow callbacksAvi Halachmi (:avih)2021-06-231-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, process_timers() kept going as long as there were due timers, which could be for extended periods of time or even forever if there were slow timer callbacks with either periodic timers or if timers were added repeatedly. This prevented dequeuing mpv events, and subsequently, among others, prevented mpv from quitting until process_timers() completed. For instance, this caused process_timers() to never return: function render() <longer than 1/60 s on a slow system> end mp.add_periodic_timer(1/60, render) Similarly, it never returned if a timer callback always added a new one-shot which was already due by the time the callback completed. This commit ensures that process_timers() only executes callbacks which were due when it started, so that timers which are added (or repeated) during process_timers() will wait for the next iteration - after mpv events are dequeued. This has no performance impact under normal conditions (when callbacks complete before the next timer is due). Additionally, previously idle-observers were executed unconditionally after the timers because indeed there was nothing due when (if...) process_timers() completed. However, now process_timers() can return even if there are due timers, so skip idle-observers on such case.
* osc: seekbar hover/drag: display target chapter at the titleAvi Halachmi (:avih)2021-06-221-1/+33
| | | | Fixes #8925
* osc: ensure tick after any mouse-eventAvi Halachmi (:avih)2021-06-201-1/+3
| | | | | | | | | | | | | | | | | Previously tick() was ensured unconditionally only after mouse-move, but there are other mouse-events which need re-rendering (tick), like mouse-down (icons may get grayed-out) or mouse-up (icons may change). For instance: mpv --pause --myclip.mkv then move the mouse over the volume/mute OSC button, then - without moving the mouse - press and release the left mouse button. The osc was not re-rendered because it's paused and the mouse didn't move, so the volume icon didn't get grayed-out when held down, and the icon doesn't change on mouse-up (to reflect the new mute state). Now both these changes are rendered correctly.
* osc: don't initialize while mouse-down over an elementAvi Halachmi (:avih)2021-06-201-1/+8
| | | | | | | | | This is not a new issue, however, until the last commit - 96b246d init probably didn't happen much (or at all) between mouse-down and mouse-up, but after this commit, if there are chapters in a live-stream then osc_init() is used to re-render the markers at the adjusted position - which breaks the OSC buttons functionality if init happened between mouse-down and mouse-up.
* osc: update chapter marker positions when duration changesSagnac2021-06-161-1/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 6abb7e3 updates the markers when the chapters change, but it doesn't update their relative position at the bar when the duration changes. This means that adding chapters to a live stream would result in corresponding chapter markers which were static while the duration changed and thus their positions became incorrect over time until the OSC was reinitialized. This is fixed by observing the duration property if chapters are present and reinitializing the OSC when the duration changes. The live_markers user option, which determines whether the duration property is observed when there are chapters, has been added in order to allow disabling this behaviour as calling request_init() frequently might have some impact on low-end systems. The impact of request_init() on render() was measured to increase from 1-1.5 ms to 2-3 ms on a 2010 MacBook Air, while the impact was neglible on a 2016 Surface Book (increasing only to an average of 1.4 ms from 1.3 ms for n=1500 render cycles). The live_markers option is enabled by default.
* ytdl_hook: improve handling of json parsing errorsRetusthese2021-05-291-10/+12
| | | | | | | | | | This moves the JSON parsing above the main youtube-dl error-handling block and integrates parsing errors into that block. Now, if a parsing error occurs, youtube-dl's stderr will be logged as it is with other errors. This also catches errors that cause youtube-dl to output "null", which would previously be mishandled as a parsing error and crash ytdl_hook when it attempted to concatenate the error string from parse_json.
* osc: re-initialize when chapter list changesRetusthese2021-05-271-0/+1
| | | | | | | | | | | | When the OSC initializes, it checks whether the current video has chapters, and if it does not, it disables its chapter functionality (chapter buttons are grayed out and unusable, chapter indicators don't show on the seek bar). If another script changed the chapter list after the video has loaded, those changes would be ignored by the OSC until some other event causes it to re-initialize, because it did not observe the chapter list property. This is fixed by adding observation of chapter-list alongside the other properties that trigger re-initialization.
* ytdl_hook: expose some JSON fields as tagsYour Name2021-05-111-0/+29
| | | | | | | | | | Shows uploader, channel, description fields. This works only if the media media is constructed as EDL (for youtube it usually does this), and if the all_formats option is not set to true (does anyone even use it?). The former usually happens because youtube serves audio and video separately, though it will not for live HLS/DASH. The latter uses delayed media opening, which breaks the global_tags mechanism (see previous commit).
* scripting (lua/js): utils.getpid: make wrapper of pid propertyAvi Halachmi (:avih)2021-05-011-0/+4
| | | | | | | | | We now have at least 3 scripting APIs which are trivial wrappers around properties: mp.get_mouse_pos, utils.getcwd, utils.getpid. After some discussion on IRC it was decided that it's easier for us to maintain them as trivial wrappers than to deprecate them and inflict pain on users and script authors, so currently no plan to deprecate.
* osc: reset margins when using boxvideo with showfullscreen/showwindowedossifrage2021-04-271-1/+11
| | | | | | | | | | | | | | | | | | | This fixes a bug where using boxvideo with showfullscreen=no or showwindowed=no resulted in the margins not resetting when the OSC wasn't visible. For example, using: script-opts=osc-visibility=always,osc-boxvideo=yes,osc-showfullscreen=no and then going fullscreen would make the OSC disappear but the video margins would remain. This is because boxvideo was missing a dependence on the showfullscreen and showwindowed user options. This is fixed by adding the corresponding conditions to update_margins() and setting state.marginsREQ on fullscreen changes. update_margins() is called on tick() if there's a margins update pending, which guarantees the boxvideo margins are reset appropriately.
* osc: display immediately when visibility changes from never to alwaysossifrage2021-04-251-1/+2
| | | | | | | | | | | | | | | | | | | | | | Clearing state.osd.data with an empty string at render_wipe() fixes an issue where changing the OSC visibility from "never" directly to "always" didn't immediately update the display when the player was paused. This could be verified by starting the player with `--script-opts=osc-visibility=always --pause` and then running `script-message osc-visibility never` followed by `script-message osc-visibility always`. Removing the overlay without changing the contents meant the overlay wouldn't update and display when enabled again until the fields changed in some way (e.g. seeking, mousing over the OSC area, etc.). Clearing state.osd.data before removal of the OSC makes sure set_osd doesn't return on re-enable and instead displays the OSC immediately as the data is now different. render_wipe() is now also used when the OSC needs to be cleared at tick() as using set_osd to clear it with an empty string did not call state.osd:remove() which can allow cleanups related to bitmap memory allocations etc.
* stats.lua: include a filter's @label when displaying filters on page 1Chris Varenhorst2021-03-151-0/+4
|
* ytdl_hook: fix crash on missing track bitraternhmjoj2021-03-081-1/+1
| | | | | | | | Some tracks happen to lack bitrate information (ie. no tbr value). In that case, just ignore the track while computing the max bitrate. For an example, this is a stream in which all audio tracks have no bitrate: https://www.raiplay.it/dirette/rai1
* console: use wl-paste on WaylandGuido Cella2020-12-141-1/+11
|
* auto_profiles: fix compile_cond on lua 5.1Philip Sequeira2020-12-081-6/+10
| | | | | | 5.1's load() doesn't accept strings; loadstring must be used instead. In 5.2, loadstring is deprecated and setfenv is gone.
* lua/js: mp.get_mouse_pos: use the mouse-pos propertyAvi Halachmi (:avih)2020-11-161-0/+5
| | | | | | | mp.get_mouse_pos() is undocumented and is no longer required - the property can be used officially by any client now, however, osc.lua uses it, and also some user scripts learnt to rely on it, so we keep it - as a trivial wrapper around the new mouse-pos property.
* console: let type set the cursor positionGuido Cella2020-10-271-4/+10
| | | | | | | | | | | | | | | | | | This allows keybindings such as: a script-message-to console type "seek :0 absolute" 6 % script-message-to console type "seek absolute-percent" 6 The cursor position 0 isn't allowed because it has the weird effect of filling the console with the text twice, leaving the cursor in the middle. Negative positions would put the cursor n characters before the end, and positions greater than the text's length at the end. They seem to work at first, but the console breaks when you move the cursor, so they aren't allowed. It seems that float values don't cause issues, but I'm using the argument's floor anyway to be safe. Using >= 1 instead of > 0 ignores values like 0.5.
* ytdl_hook: if ytdl not found in config dirs, use ytdl_path as isRicardo Constantino2020-10-271-1/+4
|
* ytdl_hook: support alternative youtube-dl pathRicardo Constantino2020-10-271-2/+4
| | | | | Allows using a youtube-dl not in PATH or a compatible fork of youtube-dl.
* stats: display hw pixel format toosfan52020-10-161-0/+4
|
* ytdl_hook: sort subtitle list by languagewm42020-08-121-1/+7
| | | | | | The subtitle list is returned in randomized order, because a table (i.e. JSON object) is used. To make the order stable across repeated invocations, sort it by language.
* auto_profiles: unapply conditional profiles if declaredwm42020-08-071-4/+10
| | | | | | Uses the mechanism introduced in the previous commit. The hope was to make auto-profiles easier to use, and to get rid of the need for manually created inverse profiles. Not sure if the end result is useful.
* auto_profiles: register hooks for more synchronous profile applicationwm42020-08-051-0/+19