-
Notifications
You must be signed in to change notification settings - Fork 0
/
xchat_mpd.py
executable file
·52 lines (49 loc) · 1.35 KB
/
xchat_mpd.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import socket,re,xchat
__module_name__ = "mpd-np"
__module_version__ = "0.2"
__module_description__ = "mpd now playing"
host='127.0.0.1'
port=6600
init_string = ' ♫'
end_string = ' ♫'
def playing(word, word_eol, userdata):
if len(word) < 2:
custom_msg="escuchando:"
else:
custom_msg=word_eol[1]+":"
mpd=socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
mpd.connect((host,port))
welcome=mpd.recv(1024)
mpd.send('currentsong\r\n')
#get all the info about current track being played
data=mpd.recv(4096)
try:
artist=re.findall(r'Artist[:]\s[\S ]+',data)[0].split(':')[1]
except:
artist=""
try:
title=re.findall(r'Title[:]\s[\S ]+',data)[0].split(':')[1]
except:
title=""
try:
album=re.findall(r'Album[:]\s[\S ]+',data)[0].split(':')[1]
except:
album=""
#not info from track
if not artist:
try:
filename=re.findall(r'file[:]\s[\S ]+',data)[0]
filename=filename[filename.rindex("/")+1:].split('.')[0]
except:
filename=""
msg=custom_msg + init_string + filename + end_string
else:
msg=custom_msg + init_string + artist+' -' + title + ' -' + album + end_string
xchat.command('me ' + msg)
data=""
mpd.close()
return xchat.EAT_ALL
#hooks into the show xchat command
xchat.hook_command("mpd",playing, help="/mpd [custom message]")