Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats.lua: display file tags #13913

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7169,10 +7169,10 @@ Miscellaneous
-------------

``--display-tags=tag1,tags2,...``
Set the list of tags that should be displayed on the terminal. Tags that
are in the list, but are not present in the played file, will not be shown.
If a value ends with ``*``, all tags are matched by prefix (though there
is no general globbing). Just passing ``*`` essentially filtering.
Set the list of tags that should be displayed on the terminal and stats.
Tags that are in the list, but are not present in the played file, will not
be shown. If a value ends with ``*``, all tags are matched by prefix (though
there is no general globbing). Just passing ``*`` essentially filtering.

The default includes a common list of tags, call mpv with ``--list-options``
to see it.
Expand Down
10 changes: 10 additions & 0 deletions DOCS/man/stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ Configurable Options
respective duration. This can result in overlapping text when multiple
scripts decide to print text at the same time.

``file_tag_max_length``
Default: 128

Only show file tags shorter than this length, in bytes.

``file_tag_max_count``
Default: 16

Only show the first specified amount of file tags.

``term_width_limit``
Default: -1

Expand Down
21 changes: 18 additions & 3 deletions player/lua/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ local o = {
ass_formatting = true,
persistent_overlay = false, -- whether the stats can be overwritten by other output
filter_params_max_length = 100, -- show one filter per line if list exceeds this length
file_tag_max_length = 128, -- only show file tags shorter than this length in bytes
file_tag_max_count = 16, -- only show the first x file tags
show_frame_info = false, -- whether to show the current frame info
term_width_limit = -1, -- overwrites the terminal width
term_height_limit = -1, -- overwrites the terminal height
Expand Down Expand Up @@ -641,13 +643,26 @@ local function add_header(s)
end


local function add_file(s, print_cache)
local function add_file(s, print_cache, print_tags)
append(s, "", {prefix="File:", nl="", indent=""})
append_property(s, "filename", {prefix_sep="", nl="", indent=""})
if mp.get_property_osd("filename") ~= mp.get_property_osd("media-title") then
append_property(s, "media-title", {prefix="Title:"})
end

if print_tags then
local tags = mp.get_property_native("display-tags")
kasper93 marked this conversation as resolved.
Show resolved Hide resolved
local tags_displayed = 0
for _, tag in ipairs(tags) do
local value = mp.get_property("metadata/by-key/" .. tag)
if tag ~= "Title" and tags_displayed < o.file_tag_max_count
and value and value:len() < o.file_tag_max_length then
append(s, value, {prefix=string.gsub(tag, "_", " ") .. ":"})
tags_displayed = tags_displayed + 1
end
end
end

local editions = mp.get_property_number("editions")
local edition = mp.get_property_number("current-edition")
local ed_cond = (edition and editions > 1)
Expand Down Expand Up @@ -1140,7 +1155,7 @@ local function default_stats()
local stats = {}
eval_ass_formatting()
add_header(stats)
add_file(stats, true)
add_file(stats, true, false)
add_video_out(stats)
add_video(stats)
add_audio(stats)
Expand Down Expand Up @@ -1287,7 +1302,7 @@ local function track_info()
append(h, "", {prefix=format("%s:%s", desc, scroll_hint()), nl="", indent=""})
h = {table.concat(h)}
table.insert(c, o.nl .. o.nl)
add_file(c)
add_file(c, false, true)
for i, track in ipairs(mp.get_property_native("track-list")) do
if track['selected'] then
add_track(c, track, i - 1)
Expand Down