dotfiles

personal dotfiles
git clone anongit@rnpnr.xyz:dotfiles.git
Log | Files | Refs | Feed | Submodules

status-line.lua (1128B)


      1 -- generates a status line useful when running mpv
      2 -- headless from the terminal as a music player
      3 -- updates once per second and pauses with player
      4 
      5 local chapter_str = ""
      6 mp.observe_property("chapter", "number", function(_, cn)
      7 	if cn == nil then chapter_str = "" return end
      8 	local c = "\n> [" .. cn + 1 .. "/"
      9 	c = c .. mp.get_property_osd("chapters") .. "] "
     10 	c = c .. mp.get_property_osd("chapter-metadata/by-key/title")
     11 	chapter_str = c
     12 end)
     13 
     14 local status_line = function()
     15 	local status = ""
     16 	local append = function(s) status = status .. s end
     17 	append("> " .. mp.get_property_osd("media-title"))
     18 	append(chapter_str)
     19 	append("\n> " .. mp.get_property_osd("time-pos"))
     20 	append("/"  .. mp.get_property_osd("duration"))
     21 	append(" (Cached: " .. mp.get_property_osd("demuxer-cache-duration"))
     22 	append(")")
     23 	mp.set_property("options/term-status-msg", status)
     24 end
     25 
     26 timer = mp.add_periodic_timer(1, status_line)
     27 
     28 local pause = function(_, paused)
     29 	if paused then
     30 		timer:stop()
     31 	else
     32 		timer:resume()
     33 	end
     34 	mp.add_timeout(0.1, status_line)
     35 end
     36 
     37 mp.observe_property("pause", "bool", pause)
     38 mp.register_event("seek", status_line)