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

Showing the changes to player/lua/stats.lua (1 of 3 files). Show all

Unified · Split

player/lua/stats.lua+18−3
@@ -31,6 +31,8 @@ local o = { · 30 unmodified lines
3131 ass_formatting = true,
3232 persistent_overlay = false, -- whether the stats can be overwritten by other output
3333 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
3436 show_frame_info = false, -- whether to show the current frame info
3537 term_width_limit = -1, -- overwrites the terminal width
3638 term_height_limit = -1, -- overwrites the terminal height
@@ -641,13 +643,26 @@ local function add_header(s) · 604 unmodified lines
641643 end
642644
643645
644−local function add_file(s, print_cache)
646+local function add_file(s, print_cache, print_tags)
645647 append(s, "", {prefix="File:", nl="", indent=""})
646648 append_property(s, "filename", {prefix_sep="", nl="", indent=""})
647649 if mp.get_property_osd("filename") ~= mp.get_property_osd("media-title") then
648650 append_property(s, "media-title", {prefix="Title:"})
649651 end
650652
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+
651666 local editions = mp.get_property_number("editions")
652667 local edition = mp.get_property_number("current-edition")
653668 local ed_cond = (edition and editions > 1)
@@ -1140,7 +1155,7 @@ local function default_stats() · 486 unmodified lines
11401155 local stats = {}
11411156 eval_ass_formatting()
11421157 add_header(stats)
1143− add_file(stats, true)
1158+ add_file(stats, true, false)
11441159 add_video_out(stats)
11451160 add_video(stats)
11461161 add_audio(stats)
@@ -1287,7 +1302,7 @@ local function track_info() · 140 unmodified lines
12871302 append(h, "", {prefix=format("%s:%s", desc, scroll_hint()), nl="", indent=""})
12881303 h = {table.concat(h)}
12891304 table.insert(c, o.nl .. o.nl)
1290− add_file(c)
1305+ add_file(c, false, true)
12911306 for i, track in ipairs(mp.get_property_native("track-list")) do
12921307 if track['selected'] then
12931308 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