dotfiles/.config/mpv/scripts.disabled/auto-loop.lua

21 lines
654 B
Lua
Raw Normal View History

2024-08-05 22:09:12 +02:00
function auto_loop()
2024-11-21 19:44:35 +01:00
local max = 20
2024-08-05 22:09:12 +02:00
local file_duration = mp.get_property_number("duration", 0)
2024-08-05 22:15:55 +02:00
print(file_duration)
2024-08-05 22:09:12 +02:00
-- 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")
2024-08-05 22:15:55 +02:00
-- 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))
2024-08-05 22:09:12 +02:00
-- For longer file, play it only once
else
mp.set_property("loop-file", "no")
end
2024-08-05 22:15:55 +02:00
print(mp.get_property("loop-file"))
2024-08-05 22:09:12 +02:00
end
mp.register_event("file-loaded", auto_loop)