-
Notifications
You must be signed in to change notification settings - Fork 5
/
speed.lua
48 lines (39 loc) · 1.01 KB
/
speed.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
speed_regexs_fn = '~/.config/mpv/scripts/speed.conf'
function string.interpr_hex(str)
return (str:gsub('\\x..', function (c)
return string.char(c:gsub('\\x', '0x')):sub(1, 1)
end))
end
function trim(s)
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
function started()
pth = mp.get_property("path"):lower()
for _, speed_rgx in pairs(speed_regexs) do
if pth:find(speed_rgx[2]) then
mp.set_property("speed", speed_rgx[1])
break
end
end
end
speed_regexs_fn = speed_regexs_fn:gsub('~', os.getenv('HOME'))
speed_regexs = {}
for line in io.lines(speed_regexs_fn) do
rgx = line:match("^\t(.+)")
if speed and rgx then
rgx = trim(rgx):interpr_hex():lower()
if rgx:len() > 0 then
table.insert(speed_regexs, {speed, rgx})
end
else
speed_tmp, rgx = line:match("^([%d%.]+)(.*)")
if speed_tmp and rgx then
speed = speed_tmp
rgx = trim(rgx):interpr_hex():lower()
if rgx:len() > 0 then
table.insert(speed_regexs, {speed, rgx})
end
end
end
end
mp.register_event("file-loaded", started)