-
Notifications
You must be signed in to change notification settings - Fork 9
/
lats.lua
79 lines (68 loc) · 2.2 KB
/
lats.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- lats, the Low ATtention Span mpv script
--
-- This script will tell mpv to skip to the next playlist entry after a
-- fixed time (default: 10 seconds). LATS also enables shuffling and
-- looping by default.
--
-- This allows for a viewing experience similar to flipping through a
-- bunch of channels or tuning into different radio stations. The original
-- purpose for this was to have a fun way to re-watch a long series, quickly
-- reliving many moments, but this may also be useful for trying to locate a
-- scene/moment in one or more files.
--
-- You almost certainly don't want this behavior all of the time, so you almost
-- certainly should not install this script into your ~~/scripts/ directory.
-- Instead, place it into mpv's configuration directory (e.g., ~/.config/mpv)
-- and when you want to enable it, pass the option --script='~~/lats.lua' to
-- mpv.
--
-- Options recognized by this script:
--
-- duration: seconds until skip (default 10)
-- shuffle: sets --shuffle (default true)
-- loop: sets --loop-playlist=inf (default true)
--
require "mp.options"
o = { duration = 10, shuffle = true, loop = true }
read_options(o, "lats")
mp.set_property("resume-playback", "no")
if o.shuffle then mp.set_property("shuffle", "yes") end
if o.loop then mp.set_property("loop-playlist", "inf") end
timer = mp.add_periodic_timer(o.duration, function()
mp.commandv("playlist-next", "force")
end)
timer:kill()
-- when file loads, seek to random position and start timer
mp.register_event("file-loaded", function()
timer:kill()
dur = mp.get_property_number("duration")
if dur == nil then
return
end
upper = dur - o.duration
if upper >= 1 then
internal_seek = 1
mp.commandv("seek", math.random(upper), "absolute+keyframes")
if not mp.get_property_bool("pause") then
timer:resume()
end
else
internal_seek = -1
end
end)
-- don't skip around while player is paused
mp.observe_property("pause", "bool", function(_, pause)
if internal_seek == -1 then
return
end
if pause then timer:stop() else timer:resume() end
end)
-- stop skipping around if the user seeks
mp.register_event("seek", function()
if internal_seek == 1 then
internal_seek = 0
else
internal_seek = -1
timer:stop()
end
end)