-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpdnotify.py
executable file
·56 lines (46 loc) · 1.4 KB
/
mpdnotify.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
#!/usr/bin/python
import mpd
import subprocess
import datetime
import time
def sendmessage(title, message):
subprocess.Popen(['notify-send', title, message, '-i', '/home/damonj/bin/note.png'])
return
client = mpd.MPDClient(use_unicode=True)
client.connect("localhost", 6600)
currentTrack = ""
currentState = "badger"
previousState = "ferret"
while True:
if client.idle('player') != "" :
d = client.currentsong()
noted = "false"
if client.status()['state'] == "pause":
previousState = currentState
currentState = client.status()['state']
print ("Previous : " + previousState)
print ("Current : " + currentState)
if client.status()['state'] == "play" :
try:
artist = d['artist']
title = d['title']
album = d['album']
time = d['time']
except KeyError:
artist = ""
title = ""
album = ""
time = ""
if d['title'] != currentTrack and noted == "false":
sendmessage( artist , title +"\n"+ album +"\n"+ str(datetime.timedelta(seconds=int(time))) )
currentTrack = title
previousState = currentState
currentState = client.status()['state']
noted = "true"
else:
if d['title'] == currentTrack and currentState != previousState:
sendmessage( artist , title +"\n"+ album +"\n"+ str(datetime.timedelta(seconds=int(time))) )
currentTrack = title
previousState = currentState
currentState = client.status()['state']
noted = "true"