22This is mpv's original player/lua/osc.lua patched to display thumbnails
33
44Sections are denoted with -- mpv_thumbnail_script.lua --
5-
5+ Current osc.lua version: 97816bbef0f97cfda7abdbe560707481d5f68ccd
66]] --
77
88local assdraw = require ' mp.assdraw'
@@ -47,6 +47,7 @@ local user_opts = {
4747 tooltipborder = 1 , -- border of tooltip in bottom/topbar
4848 timetotal = false , -- display total time instead of remaining time?
4949 timems = false , -- display timecodes with milliseconds?
50+ seekranges = true , -- display seek ranges?
5051 visibility = " auto" , -- only used at init to set visibility_mode(...)
5152 boxmaxchars = 80 , -- title crop threshold for box layout
5253}
6465
6566-- mpv_thumbnail_script.lua --
6667
68+ -- Patch in msg.trace
69+ if not msg .trace then
70+ msg .trace = function (...) return mp .log (" trace" , ... ) end
71+ end
72+
6773Thumbnailer :register_client ()
6874
6975function get_thumbnail_y_offset (thumb_size , msy )
@@ -1931,6 +1937,9 @@ function osc_init()
19311937 end
19321938 end
19331939 ne .slider .seekRangesF = function ()
1940+ if not (user_opts .seekranges ) then
1941+ return nil
1942+ end
19341943 local cache_state = mp .get_property_native (" demuxer-cache-state" , nil )
19351944 if not cache_state then
19361945 return nil
@@ -2010,25 +2019,23 @@ function osc_init()
20102019 ne .content = function ()
20112020 local dmx_cache = mp .get_property_number (" demuxer-cache-duration" )
20122021 local cache_used = mp .get_property_number (" cache-used" )
2022+ local dmx_cache_state = mp .get_property_native (" demuxer-cache-state" , {})
20132023 local is_network = mp .get_property_native (" demuxer-via-network" )
2024+ local show_cache = cache_used and not dmx_cache_state [" eof" ]
20142025 if dmx_cache then
20152026 dmx_cache = string.format (" %3.0fs" , dmx_cache )
20162027 end
2017- if cache_used then
2018- local suffix = " KiB"
2019- if (cache_used >= 1024 ) then
2020- cache_used = cache_used / 1024
2021- suffix = " MiB"
2022- end
2023- cache_used = string.format (" %5.1f%s" , cache_used , suffix )
2028+ if dmx_cache_state [" fw-bytes" ] then
2029+ cache_used = (cache_used or 0 )* 1024 + dmx_cache_state [" fw-bytes" ]
20242030 end
2025- if (is_network and dmx_cache ) or cache_used then
2031+ if (is_network and dmx_cache ) or show_cache then
20262032 -- Only show dmx-cache-duration by itself if it's a network file.
20272033 -- Cache can be forced even for local files, so always show that.
20282034 return string.format (" Cache: %s%s%s" ,
20292035 (dmx_cache and dmx_cache or " " ),
2030- ((dmx_cache and cache_used ) and " + " or " " ),
2031- (cache_used or " " ))
2036+ ((dmx_cache and show_cache ) and " | " or " " ),
2037+ (show_cache and
2038+ utils .format_bytes_humanized (cache_used ) or " " ))
20322039 else
20332040 return " "
20342041 end
@@ -2076,7 +2083,7 @@ function show_osc()
20762083 -- show when disabled can happen (e.g. mouse_move) due to async/delayed unbinding
20772084 if not state .enabled then return end
20782085
2079- msg .debug (" show_osc" )
2086+ msg .trace (" show_osc" )
20802087 -- remember last time of invocation (mouse move)
20812088 state .showtime = mp .get_time ()
20822089
@@ -2088,7 +2095,7 @@ function show_osc()
20882095end
20892096
20902097function hide_osc ()
2091- msg .debug (" hide_osc" )
2098+ msg .trace (" hide_osc" )
20922099 if not state .enabled then
20932100 -- typically hide happens at render() from tick(), but now tick() is
20942101 -- no-op and won't render again to remove the osc, so do that manually.
@@ -2132,7 +2139,7 @@ end
21322139
21332140function timer_start ()
21342141 if not (state .timer_active ) then
2135- msg .debug (" timer start" )
2142+ msg .trace (" timer start" )
21362143
21372144 if (state .timer == nil ) then
21382145 -- create new timer
@@ -2148,7 +2155,7 @@ end
21482155
21492156function timer_stop ()
21502157 if (state .timer_active ) then
2151- msg .debug (" timer stop" )
2158+ msg .trace (" timer stop" )
21522159
21532160 if not (state .timer == nil ) then
21542161 -- kill timer
@@ -2174,12 +2181,12 @@ function request_init()
21742181end
21752182
21762183function render_wipe ()
2177- msg .debug (" render_wipe()" )
2184+ msg .trace (" render_wipe()" )
21782185 mp .set_osd_ass (0 , 0 , " {}" )
21792186end
21802187
21812188function render ()
2182- msg .debug (" rendering" )
2189+ msg .trace (" rendering" )
21832190 local current_screen_sizeX , current_screen_sizeY , aspect = mp .get_osd_size ()
21842191 local mouseX , mouseY = get_virt_mouse_pos ()
21852192 local now = mp .get_time ()
@@ -2393,7 +2400,7 @@ function tick()
23932400 if (state .idle ) then
23942401
23952402 -- render idle message
2396- msg .debug (" idle message" )
2403+ msg .trace (" idle message" )
23972404 local icon_x , icon_y = 320 - 26 , 140
23982405
23992406 local ass = assdraw .ass_new ()
0 commit comments