History

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.

nanahi committed 2 years ago

Commit d2bd77a1 parent 65fef733 files · +32 −7Browse files

Unified · Split

3 files
  1. DOCS/man/options.rst +4 −4
  2. DOCS/man/stats.rst +10 −0
  3. player/lua/stats.lua +18 −3
DOCS/man/options.rst+4−4
@@ -7169,10 +7169,10 @@ Miscellaneous · 7168 unmodified lines
7169-------------7169-------------
7170 7170
7171``--display-tags=tag1,tags2,...``7171``--display-tags=tag1,tags2,...``
7172 Set the list of tags that should be displayed on the terminal. Tags that7172 Set the list of tags that should be displayed on the terminal and stats.
7173 are in the list, but are not present in the played file, will not be shown.7173 Tags that are in the list, but are not present in the played file, will not
7174 If a value ends with ``*``, all tags are matched by prefix (though there7174 be shown. If a value ends with ``*``, all tags are matched by prefix (though
7175 is no general globbing). Just passing ``*`` essentially filtering.7175 there is no general globbing). Just passing ``*`` essentially filtering.
7176 7176
7177 The default includes a common list of tags, call mpv with ``--list-options``7177 The default includes a common list of tags, call mpv with ``--list-options``
7178 to see it.7178 to see it.
DOCS/man/stats.rst+10−0
@@ -93,6 +93,16 @@ Configurable Options · 92 unmodified lines
93 respective duration. This can result in overlapping text when multiple93 respective duration. This can result in overlapping text when multiple
94 scripts decide to print text at the same time.94 scripts decide to print text at the same time.
95 95
96``file_tag_max_length``
97 Default: 128
98
99 Only show file tags shorter than this length, in bytes.
100
101``file_tag_max_count``
102 Default: 16
103
104 Only show the first specified amount of file tags.
105
96``term_width_limit``106``term_width_limit``
97 Default: -1107 Default: -1
98 108
player/lua/stats.lua+18−3
@@ -31,6 +31,8 @@ local o = { · 30 unmodified lines
31 ass_formatting = true,31 ass_formatting = true,
32 persistent_overlay = false, -- whether the stats can be overwritten by other output32 persistent_overlay = false, -- whether the stats can be overwritten by other output
33 filter_params_max_length = 100, -- show one filter per line if list exceeds this length33 filter_params_max_length = 100, -- show one filter per line if list exceeds this length
34 file_tag_max_length = 128, -- only show file tags shorter than this length in bytes
35 file_tag_max_count = 16, -- only show the first x file tags
34 show_frame_info = false, -- whether to show the current frame info36 show_frame_info = false, -- whether to show the current frame info
35 term_width_limit = -1, -- overwrites the terminal width37 term_width_limit = -1, -- overwrites the terminal width
36 term_height_limit = -1, -- overwrites the terminal height38 term_height_limit = -1, -- overwrites the terminal height
@@ -641,13 +643,26 @@ local function add_header(s) · 604 unmodified lines
641end643end
642 644
643 645
644local function add_file(s, print_cache)646local function add_file(s, print_cache, print_tags)
645 append(s, "", {prefix="File:", nl="", indent=""})647 append(s, "", {prefix="File:", nl="", indent=""})
646 append_property(s, "filename", {prefix_sep="", nl="", indent=""})648 append_property(s, "filename", {prefix_sep="", nl="", indent=""})
647 if mp.get_property_osd("filename") ~= mp.get_property_osd("media-title") then649 if mp.get_property_osd("filename") ~= mp.get_property_osd("media-title") then
648 append_property(s, "media-title", {prefix="Title:"})650 append_property(s, "media-title", {prefix="Title:"})
649 end651 end
650 652
653 if print_tags then
654 local tags = mp.get_property_native("display-tags")
655 local tags_displayed = 0
656 for _, tag in ipairs(tags) do
657 local value = mp.get_property("metadata/by-key/" .. tag)
658 if tag ~= "Title" and tags_displayed < o.file_tag_max_count
659 and value and value:len() < o.file_tag_max_length then
660 append(s, value, {prefix=string.gsub(tag, "_", " ") .. ":"})
661 tags_displayed = tags_displayed + 1
662 end
663 end
664 end
665
651 local editions = mp.get_property_number("editions")666 local editions = mp.get_property_number("editions")
652 local edition = mp.get_property_number("current-edition")667 local edition = mp.get_property_number("current-edition")
653 local ed_cond = (edition and editions > 1)668 local ed_cond = (edition and editions > 1)
@@ -1140,7 +1155,7 @@ local function default_stats() · 486 unmodified lines
1140 local stats = {}1155 local stats = {}
1141 eval_ass_formatting()1156 eval_ass_formatting()
1142 add_header(stats)1157 add_header(stats)
1143 add_file(stats, true)1158 add_file(stats, true, false)
1144 add_video_out(stats)1159 add_video_out(stats)
1145 add_video(stats)1160 add_video(stats)
1146 add_audio(stats)1161 add_audio(stats)
@@ -1287,7 +1302,7 @@ local function track_info() · 140 unmodified lines
1287 append(h, "", {prefix=format("%s:%s", desc, scroll_hint()), nl="", indent=""})1302 append(h, "", {prefix=format("%s:%s", desc, scroll_hint()), nl="", indent=""})
1288 h = {table.concat(h)}1303 h = {table.concat(h)}
1289 table.insert(c, o.nl .. o.nl)1304 table.insert(c, o.nl .. o.nl)
1290 add_file(c)1305 add_file(c, false, true)
1291 for i, track in ipairs(mp.get_property_native("track-list")) do1306 for i, track in ipairs(mp.get_property_native("track-list")) do
1292 if track['selected'] then1307 if track['selected'] then
1293 add_track(c, track, i - 1)1308 add_track(c, track, i - 1)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t