From c765e68f05bfe9f0d2e4990bdc8dfabf11cdbc87 Mon Sep 17 00:00:00 2001 From: trainytrain Date: Sun, 9 May 2021 01:29:07 -0700 Subject: init --- mpv/scripts/autoloop.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 mpv/scripts/autoloop.lua (limited to 'mpv/scripts/autoloop.lua') diff --git a/mpv/scripts/autoloop.lua b/mpv/scripts/autoloop.lua new file mode 100644 index 0000000..1c2794d --- /dev/null +++ b/mpv/scripts/autoloop.lua @@ -0,0 +1,53 @@ +-- mpv issue 5222 +-- Automatically set loop-file=inf for duration <= given length. Default is 5s +-- Use autoloop_duration=n in script-opts/autoloop.conf to set your preferred length +-- Alternatively use script-opts=autoloop-autoloop_duration=n in mpv.conf (takes priority) + + +require 'mp.options' + +function getOption() + -- Use recommended way to get options + local options = {autoloop_duration = 5} + read_options(options) + autoloop_duration = options.autoloop_duration + + + -- Keep old way just for compatibility (remove lines 15-27 soon) + if autoloop_duration ~= 5 then + return + end + + local opt = tonumber(mp.get_opt("autoloop-duration")) + if not opt then + return + end + print("Depracted configuration! Please use script-opts directory to set auto_loop duration") + print("Or use 'script-opts=autoloop-autoloop_duration' in mpv.conf") + autoloop_duration = opt + -- Remove lines 15-27 soon +end + +function set_loop() + local duration = mp.get_property_native("duration") + + -- Checks whether the loop status was changed for the last file + was_loop = mp.get_property_native("loop-file") + + -- Cancel operation if there is no file duration + if not duration then + return + end + + -- Loops file if was_loop is false, and file meets requirements + if not was_loop and duration <= autoloop_duration then + mp.set_property_native("loop-file", true) + -- Unloops file if was_loop is true, and file does not meet requirements + elseif was_loop and duration > autoloop_duration then + mp.set_property_native("loop-file", false) + end +end + + +getOption() +mp.register_event("file-loaded", set_loop) -- cgit v1.2.3-13-gbd6f