Skip to content

Commit

Permalink
Add toggling of stats
Browse files Browse the repository at this point in the history
You can now either show the stats once or toggle their display. Both are
using different key bindings which are additionally configurable now.

Please bear in mind that "toggling" means "redraw every x seconds for x
seconds". Therefore, this approach is prone to problems especially when
something else is printing text to the OSD as well as every of these
calls will overwrite each other. This is currently a limitation of mpv.

Fixes mpv-player#18
  • Loading branch information
Julian authored and haasn committed Sep 25, 2017
1 parent 236360b commit 07ba92b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
33 changes: 29 additions & 4 deletions player/lua/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ local options = require 'mp.options'

-- Options
local o = {
ass_formatting = true,
-- Default key bindings
key_oneshot = "i",
key_toggle = "I",

duration = 3,
redraw_delay = 2, -- acts as duration in the toggling case
ass_formatting = true,
debug = false,

-- Text style
Expand Down Expand Up @@ -50,7 +55,7 @@ local o = {
options.read_options(o)


function main()
function main(duration)
local stats = {
header = "",
file = "",
Expand All @@ -77,7 +82,7 @@ function main()
add_video(stats)
add_audio(stats)

mp.osd_message(join_stats(stats), o.duration)
mp.osd_message(join_stats(stats), duration or o.duration)
end


Expand Down Expand Up @@ -280,4 +285,24 @@ function b(t)
return o.b1 .. t .. o.b0
end

mp.add_key_binding("i", mp.get_script_name(), main, {repeatable=true})

local timer = mp.add_periodic_timer(o.redraw_delay - 0.1, function() main(o.redraw_delay) end)
timer:kill()

function periodic_main()
if timer:is_enabled() then
timer:kill()
mp.osd_message("", 0)
else
timer:resume()
main(o.redraw_delay)
end
end


mp.add_key_binding(o.key_oneshot, "display_stats", main, {repeatable=true})
if pcall(function() timer:is_enabled() end) then
mp.add_key_binding(o.key_toggle, "display_stats_toggle", periodic_main, {repeatable=false})
else
print("To use continious display of stats please upgrade mpv")
end
15 changes: 8 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ Usage
Place `stats.lua` in your `~/.config/mpv/scripts/` or `~/.mpv/scripts/` folder
to autoload the script. Alternatively load it with `--script=<path>`.

The script is binding itself to `i` (however, not overriding your own bindings)
and can therefore be invoked with this key.
You can create different bindings by adding `<yourkey> script_binding stats` to
`input.conf`.
The script is binding itself to `i` and `I` (however, not overriding your own bindings)
and can therefore be invoked with these keys. `i` will show the stats once while
`I` is toggling them.
You can create different bindings either by using the `script_binding` input
command (in `input.conf`) or by customizing this script (see below).

Customization
-------------
You can configure some settings by creating a file `stats.conf` in a folder
named `lua-settings` within your mpv folder.
You can configure settings by creating a file called `stats.conf` in a folder
named `lua-settings` within your mpv config folder.
Please refer to the `o` table within the script for possible option names and
consult [mpv manual](http://mpv.io/manual/master/#config-syntax) regarding
configuration syntax.
Expand All @@ -28,14 +29,14 @@ To change e.g. the text display duration your `stats.conf` may look like:

A more sophisticated example:

key_oneshot=e
font=Arial
font_size=9
font_color=262626
border_size=0.5
border_color=FFFFFF
alpha=70
duration=5
debug=yes

Note: colors are given as hexadecimal values and use
[ASS tag](http://docs.aegisub.org/3.2/ASS_Tags/#\c) order: BBGGRR (blue green red).

0 comments on commit 07ba92b

Please sign in to comment.