-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathclemenshow.py
61 lines (51 loc) · 2.01 KB
/
clemenshow.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
50
51
52
53
54
55
56
57
58
59
60
61
"""
Simple weechat script for showing currently playing song from clementine.
Basic install / usage:
place into ~/.weechat/python/autoload
/python load python/autoload/clemenshow.py
/np
"""
SCRIPT_NAME = "clemenshow"
SCRIPT_AUTHOR = "Leigh MacDonald <leigh.macdonald@gmail.com>"
SCRIPT_VERSION = "1.1"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Clementine now playing script"
SCRIPT_COMMAND = "np"
import sys
from os.path import exists
try:
import weechat
IMPORT_OK = True
except ImportError:
print("This script must be run under WeeChat 3.4 or better.")
print("Get WeeChat now at: https://weechat.org/")
IMPORT_OK = False
try:
from dbus import Bus, DBusException
except ImportError:
print("Please install python-dbus")
IMPORT_OK = False
def get_type(path):
p = path.split(".")
return p[len(p)-1].upper()
#@DebugArgs
def np_command(data, buffer, args):
try:
c = bus.get_object('org.mpris.clementine', '/Player')
f = c.GetMetadata()
weechat.command(buffer, "/me %s | %s [%s@%dkbps/%dHz]" % (f['artist'].encode('UTF-8'),
f['title'].encode('UTF-8'),
get_type(f['location'].encode('UTF-8')),
int(f['audio-bitrate']),
int(f['audio-samplerate'])))
except DBusException:
weechat.prnt(buffer, "Doesnt look like clementine is running, if it is make sure dbus is running")
except Exception as err:
weechat.prnt(buffer, err)
finally:
return weechat.WEECHAT_RC_OK
if __name__ == "__main__" and IMPORT_OK:
weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", "")
weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC, "", "", "", "np_command", "")
weechat.prnt("", "%s | %s" % (SCRIPT_NAME, SCRIPT_AUTHOR))
bus = Bus(Bus.TYPE_SESSION)