From d2bd77ada0831604a2eb05b16079204d6806d38e Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Wed, 17 Apr 2024 06:27:04 -0400 Subject: [PATCH] stats.lua: display file tags This adds file tags to display along with the title, including album/artist etc. for music, and series etc. for some videos. The list of tags to display is identical to the tags printed to the terminal and is controlled by the --display-tags option. To filter out overlength tags (such as long comments and lyrics) and files with too many tags, add file_tag_max_length and file_tag_max_count options so that tags longer than this length are not displayed, and only the first few tags are displayed. Also makes tags show on page 5 only. --- DOCS/man/options.rst | 8 ++++---- DOCS/man/stats.rst | 10 ++++++++++ player/lua/stats.lua | 21 ++++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index d7a74daac0..e2c3c6d00c 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -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. diff --git a/DOCS/man/stats.rst b/DOCS/man/stats.rst index b87e0d5961..0e42f44496 100644 --- a/DOCS/man/stats.rst +++ b/DOCS/man/stats.rst @@ -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 diff --git a/player/lua/stats.lua b/player/lua/stats.lua index ce2166867e..74b17c3722 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -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 @@ -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") + 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) @@ -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) @@ -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)