mirror of
https://github.com/acatoire/bipbipzizik.git
synced 2026-03-10 08:01:18 +00:00
Modified box.py to call haplaylist shell script
Box.py now calls haplaylist.sh and passes the plist variable. The haplaylist.sh calls a curl command to a home assistant instance running on another machine and passes the playlist variable to an input_text component. Also included is the musiccards.service for systemd to start box.py automatically on boot.
This commit is contained in:
35
box.py
35
box.py
@@ -1,34 +1,11 @@
|
||||
#!/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
|
||||
import subprocess
|
||||
import shlex
|
||||
|
||||
reader = Reader()
|
||||
cardList = CardList()
|
||||
@@ -42,13 +19,9 @@ while True:
|
||||
plist = cardList.getPlaylist(card)
|
||||
print 'Playlist', plist
|
||||
if plist != '':
|
||||
client = connectMPD()
|
||||
if plist=='pause':
|
||||
client.pause()
|
||||
else:
|
||||
play(client, plist)
|
||||
client.close()
|
||||
subprocess.check_call( ["./haplaylist.sh %s" % plist], shell=True)
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user