forked from fsahli/music-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.py
executable file
·54 lines (48 loc) · 1.11 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
#!/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):
client.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':
client.pause()
else:
play(client, plist)
client.close()
except KeyboardInterrupt:
sys.exit(0)
except:
pass