-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
84 lines (63 loc) · 1.84 KB
/
player.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
79
80
81
82
83
import os
import time
from helpers import getPlaylist
status_file = 'status'
print('Internet Radio On: Awaiting Channel Instruction')
class mplayer:
command = 'mplayer -slave -quiet -ao alsa '
playing = False
running = False
def startUp(self, stream):
import os,subprocess
print self.command + stream
self.mp = subprocess.Popen(self.command + stream, stdin=subprocess.PIPE, shell = True)
self.playing = True
self.running = True
def loadChannel(self, stream):
cmd = 'loadfile ' + stream + '\n'
self.mp.stdin.write(cmd)
self.playing = True
def stopChannel(self):
cmd = 'stop' + '\n'
self.mp.stdin.write(cmd)
self.playing = False
self.running = False
class airplayer:
# command =
playing = False
running = False
def startAirPi(self):
os.system('shairport/shairport.pl -a AirPi &')
self.playing = True
self.running = True
def stopAirPi(self):
os.system('killall perl')
self.playing = False
self.running = False
def getToPlay():
fh = open(status_file)
output = fh.read()
fh.close()
return output
(mode, ino, dev, nlink, uid, gid, size, atime, last_modified_time, ctime) = os.stat(status_file)
mp = mplayer()
ap = airplayer()
while True:
time.sleep(1)
(mode, ino, dev, nlink, uid, gid, size, atime, new_last_modified_time, ctime) = os.stat(status_file)
if new_last_modified_time != last_modified_time:
last_modified_time = new_last_modified_time
options = getPlaylist()
choice = getToPlay()
if choice == 'AirPlay Mode':
if ap.running == False:
if mp.running == True and mp.playing == True:
mp.stopChannel()
ap.startAirPi()
else:
if ap.running == True:
ap.stopAirPi()
if mp.running == False:
mp.startUp(options[choice])
else:
mp.loadChannel(options[choice])