tomasklaen / uosc

Feature-rich minimalist proximity-based UI for MPV player.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: chapter remaining time in topbar

mrfragger opened this issue · comments

Screenshot 2024-01-21 at 8 41 34 PM shows chapter remaining time which is 18m 22 seconds left in current chapter. If possible a way to put it into the uosc topbar somehow? ${chap_remaining_time} doesn't work obviously. Should this be a mpv request?

btw have to have 2 minimum for it to work..say show every 2 seconds. this example shows it every ten seconds the chapter remaining time which I think is fine.

I've updated it to show chapter time, current time and time audio will end.
I only have this OSD show for audio not for video.

local utils = require 'mp.utils'
local msg = require 'mp.msg'

function disp_time(time)
	local hours = math.floor(time/3600)
	local minutes = math.floor((time % 3600)/60)
	local seconds = math.floor(time % 60)
	
	return string.format("%02d:%02d:%02d", hours, minutes, seconds)
end

timer = mp.add_periodic_timer(10, function()
    if mp.get_property_native("chapters")  > 0 then
        local time = mp.get_property_native("time-pos")
        local chap = mp.get_property_native("chapter") + 1 + 1
        local chaps = mp.get_property_native("chapter-list")
        local chap_remaining_time = disp_time(chaps[chap].time - time) 
        timenow = os.date('%I:%M:%S',os.time())
        finishwhen = os.date('%I:%M:%S',os.time()+mp.get_property("time-remaining"))
        mp.osd_message(string.format("-%s", chap_remaining_time.." "..timenow.." "..finishwhen),10)
    end
end)