-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathhello.py
More file actions
54 lines (45 loc) · 1.89 KB
/
hello.py
File metadata and controls
54 lines (45 loc) · 1.89 KB
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
import cherrypy, os, json as libjson, pidora, template
current_dir = os.path.dirname(os.path.abspath(__file__)) + "/"
cherrypy.engine.autoreload.unsubscribe()
class Pidora():
data = dict(pianobar=None, songData=None)
#Comment the line below to cancel autostart
data['pianobar'] = pidora.process(['pianobar'], True)
@cherrypy.expose
def index(self):
songData = pidora.getSongData(self.data)
return template.index(songData)
@cherrypy.expose
def api(self, json=None):
cherrypy.response.headers['Content-Type'] = 'application/json'
reply = pidora.api(self.data, json)
return reply["json"]
@cherrypy.expose
def start(self):
if self.data['pianobar'] is None:
pidora.api(self.data, '{"method":"Pianobar.Start", "id":1}')
return "<html><head><title>Pianobar has started</title></head><meta http-equiv=\"refresh\" content=\"3;URL=/mobile\"><body><p>Pianobar is starting</p></body></html>"
else:
return "<html><head><title>Pianobar is already running</title><meta http-equiv=\"refresh\" content=\"3;URL=/mobile\"></head><body><p>Pianobar is already running</p></body></html>"
@cherrypy.expose
def quit(self):
if self.data['pianobar']:
pidora.api(self.data, '{"method":"Pianobar.Quit", "id":1}')
return "<html><head><title>Pianobar has quit</title></head><body><p>Pianobar has quit</p></body></html>"
else:
return "<html><head><title>Pianobar is not running</title></head><body><p>Pianobar is not running</p></body></html>"
@cherrypy.expose
def mobile(self, c=None):
if c is None:
songData = pidora.getSongData(self.data)
return template.mobile(songData)
else:
json = libjson.dumps(dict(method="Control", id=0, command=c))
pidora.api(self.data, json)
raise cherrypy.HTTPRedirect('/mobile')
m = mobile
@cherrypy.expose
def tv(self):
songData = pidora.getSongData(self.data)
return template.tv(songData)
cherrypy.quickstart(Pidora(), config=current_dir + "cpy.conf")