dotfiles/.config/mpv/scripts/catchup.lua
2022-12-04 20:44:55 +01:00

97 lines
2.2 KiB
Lua

local mp = require 'mp'
local mp_options = require 'mp.options'
local enabled = false
local catching_up = false
local target = 1
local brick = 0
function on_pause_change(name, value)
if not enabled then return end
if value == true then
mp.osd_message("resetting catchup info on pausing", 1)
local catching_up = false
mp.set_property('speed', 1)
end
end
function do_process_timer()
if not enabled then return end
local pause = mp.get_property('pause')
local rem = tonumber(mp.get_property('time-remaining') or 0)
if pause == 'no' then
local cspeed = tonumber(mp.get_property('speed') or 1)
if rem > target + 0.8 + brick and not catching_up then
mp.osd_message("catchup", 1)
catching_up = true
mp.set_property('speed', 1.5)
elseif (rem < target - 0.1 + brick and catching_up) or rem < target - 0.4 + brick and cspeed > 1 then
mp.osd_message("done catching up", 1)
catching_up = false
mp.set_property('speed', 1)
end
if catching_up and cspeed == 1 then
catching_up = false
end
end
end
function on_keybind()
if enabled then
mp.osd_message("disabling catchup features", 3)
enabled = false
if catching_up then
catching_up = false
mp.set_property('speed', 1)
end
else
mp.osd_message("enabling catchup features", 3)
enabled = true
end
end
function increase_target()
target = target + 0.1
mp.osd_message("target: " .. target, 1)
end
function decrease_target()
target = target - 0.1
mp.osd_message("target: " .. target, 1)
end
function increase_brick()
brick = brick + 0.1
mp.osd_message("brick: " .. brick, 1)
end
function decrease_brick()
brick = brick - 0.1
mp.osd_message("brick: " .. brick, 1)
end
mp.observe_property("pause", "bool", on_pause_change)
mp.add_periodic_timer(0.07, do_process_timer)
mp.add_key_binding("Shift+c", "catchup-toggle", on_keybind)
mp.add_key_binding("Ctrl+Down", "catchup-decrease-target", decrease_target)
mp.add_key_binding("Ctrl+Up", "catchup-increase-target", increase_target)
mp.add_key_binding("Ctrl+Left", "catchup-decrease-brick", decrease_brick)
mp.add_key_binding("Ctrl+Right", "catchup-increase-brick", increase_brick)
local options = {
enable = false
}
mp_options.read_options(options, "catchup")
enabled = not options.enable
on_keybind()