-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpv_np.py
49 lines (41 loc) · 1.41 KB
/
mpv_np.py
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
#!/usr/bin/env python
#encoding=utf-8
__module_name__ = "MPV now playing"
__module_version__ = "2.0"
__module_description__ = "Displays MPV info"
__module_author__ = "kuehnelth (v1.0) / null31 (v2.0)"
import socket
import json
from os.path import expanduser
import time
import hexchat
def get_property(s, property):
cmd = {"command": ["get_property", property]}
s.send(json.dumps(cmd).encode() + b'\n')
res = json.loads(s.recv(4096).decode())
if res["error"] != "success":
return res["error"]
else:
return res["data"]
def mpv_np(caller, callee, helper):
s = socket.socket(socket.AF_UNIX)
try:
s.connect(expanduser("~") + "/.config/mpv/socket")
except:
print("Socket error")
return hexchat.EAT_ALL
time_pos = time.strftime('%H:%M:%S', time.gmtime(get_property(s, "time-pos")))
length = time.strftime('%H:%M:%S', time.gmtime(get_property(s, "duration")))
filename = get_property(s, "filename")
render = get_property(s, "current-vo")
version = get_property(s, "mpv-version")
hexchat.command("me now playing \x02%s\x0F [%s/%s] rendering with %s in %s" % (filename, time_pos, length, render, version))
s.close()
return hexchat.EAT_ALL
help_string = "Usage: /mpv \nSetup: Add 'input-ipc-server=~/.config/mpv/socket' to your ~/.config/mpv/mpv.conf"
hexchat.hook_command(
"mpv",
mpv_np,
help = help_string
)
print(help_string)