-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathanilist.lua
55 lines (47 loc) · 1.2 KB
/
anilist.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
local cmd = nil
local complete = false
local function start_process(args)
return mp.command_native_async({
name = "subprocess",
playback_only = false,
args = args
}, function() end)
end
local function start_presence()
if cmd ~= nil then
return
end
cmd = start_process({python_path, run_presence_path})
mp.osd_message("Discord RPC: Started")
end
local function stop_presence()
mp.abort_async_command(cmd)
cmd = nil
mp.osd_message("Discord RPC: Stopped")
end
local function update_presence(pos)
start_process({python_path, update_presence_path, mp.get_property("path"), pos})
end
local function check_completion(pos)
if tonumber(pos) >= 80 then
start_process({python_path, update_path, mp.get_property("path")})
complete = true
end
end
Timer = mp.add_periodic_timer(5, function()
local pos = mp.get_property("percent-pos")
update_presence(pos)
if not complete then
check_completion(pos)
end
end)
mp.register_event("start-file", function()
complete = false
Timer:resume()
start_presence()
end)
mp.register_event("shutdown", function()
if cmd ~= nil then
stop_presence()
end
end)