dotfiles/.config/mpv/scripts.disabled/auto-loop.lua
2024-11-21 19:44:35 +01:00

20 lines
654 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function auto_loop()
local max = 20
local file_duration = mp.get_property_number("duration", 0)
print(file_duration)
-- Images have a duration of 0, so dont loop and use
-- image-display-duration instead
if file_duration == 0 then
mp.set_property("loop-file", "no")
-- If a GIF or video have duration shorter than <max> seconds
-- make it loop for at least <max> seconds
elseif file_duration < max then
mp.set_property("loop-file", math.floor(max / file_duration))
-- For longer file, play it only once
else
mp.set_property("loop-file", "no")
end
print(mp.get_property("loop-file"))
end
mp.register_event("file-loaded", auto_loop)