forked from fsahli/music-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox.py
executable file
·78 lines (72 loc) · 3.31 KB
/
box.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
from mpd import MPDClient
#from readtest import *
import re
from CardList import CardList
from Reader import Reader
import sys
def connectMPD():
try:
client = MPDClient() # create client object
client.timeout = 200 # network timeout in seconds (floats allowed), default: None
client.idletimeout = None
print "Connecting..."
client.connect("localhost", 6600)
print "Connected!"
return client
except:
print 'Could not connect to MPD server'
def play(client, plist):
try:
client.stop()
client.clear()
client.add(plist)
# if re.search('playlist',plist): #un-comment for turning on shuffle at start directly
# client.shuffle() #un-comment this line as well for direct-shuffle
client.play()
except:
print 'Could not play playlist %s' % plist
reader = Reader()
cardList = CardList()
print 'Ready: place a card on top of the reader'
while True:
try:
card = reader.readCard()
print 'Read card', card
plist = cardList.getPlaylist(card)
print 'Playlist', plist
if plist != '':
client = connectMPD()
if plist=='pause': #pause
client.pause()
elif plist=='next': #next song
client.next()
elif plist=='play': #play song
client.play()
elif plist=='previous': #previous song
client.previous()
elif plist=='shuffle': #turn on/off shuffle
client.shuffle()
elif plist=='voldown': #volume down in steps
client.status()['volume']
client.status()['state']
level = int(client.status()['volume']) - 10 #change to desired amount for decreasing volume
level = max(min(level, 100), 0)
client.setvol(level)
client.status()['volume']
elif plist=='volup': #volume up in steps
client.status()['volume']
client.status()['state']
level = int(client.status()['volume']) + 10 #change to desired amount for increasing volume
level = max(min(level, 100), 0)
client.setvol(level)
client.status()['volume']
elif plist=='mute': #volume mute
client.setvol(0)
else:
play(client, plist)
client.close()
except KeyboardInterrupt:
sys.exit(0)
except:
pass