-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.lua
49 lines (36 loc) · 1.36 KB
/
time.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
-- time.lua
-- 'c' shows current time on keypress; keybind name: "show_time_fn"
-- 'C' shows what the time will be at the end of playback; keybind name: "show_end_time_fn"
-- Link: https://github.com/mustaqimM/mpv-scripts/time.lua
options = require 'mp.options'
local opts = {
hour = '%I',
time = 'c',
key = 'C'
}
options.read_options(opts)
hour = string.gsub(opts.hour, '"', "")
function show_time_fn()
mp.msg.info(os.date(hour .. ':%M'))
mp.osd_message(os.date(hour .. ":%M"))
end
function show_end_time_fn()
clock_hour = tonumber(os.date(hour))
clock_minutes = tonumber(os.date("%M"))
local remaining_t_seconds = mp.get_property_number("playtime-remaining") or 0
remaining_t_hours = math.floor(remaining_t_seconds / 3600)
remaining_t_min = (remaining_t_seconds / 60) % 60
end_hour = clock_hour + remaining_t_hours
end_min = math.floor(clock_minutes + remaining_t_min)
if end_min >= 60 then
end_hour = math.floor(end_hour + (end_min / 60))
end_min = math.floor(end_min % 60)
end
if end_hour >= 24 then
end_hour = math.abs(end_hour % 24)
end
mp.msg.info(string.format("Playback will end at: %02d:%02d", end_hour, end_min))
mp.osd_message(string.format("Playback will end at: %02d:%02d", end_hour, end_min))
end
mp.add_key_binding(opts.time, "show_time", show_time_fn)
mp.add_key_binding(opts.key, "show_end_time", show_end_time_fn)