-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmus-remote.py
executable file
·62 lines (50 loc) · 1.66 KB
/
cmus-remote.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
#!/usr/bin/env python
# cmus-remote, your own cmus remote control you can access
# from everywhere.
# Uncopyrighted. Enric Morales 2014
from flask import Flask, render_template
from backend import Cmus
from ConfigParser import ConfigParser
config = ConfigParser()
config.read('cmus-remote.ini')
user = config.get('main', 'user')
cmus = Cmus(user)
app = Flask(__name__)
@app.route("/")
def index():
if cmus.is_socket_alive():
actions = ['prev', 'play', 'pause', 'next']
status = cmus.status()
if status['paused'] or status['stopped']:
hilite = "play"
actions.pop(actions.index('pause'))
else:
hilite = "pause"
actions.pop(actions.index('play'))
return render_template('index.html',
actions=actions,
hilite=hilite,
status=status)
else:
return render_template('error.html')
@app.route('/<action>')
def do_action(action):
if cmus.is_socket_alive():
status = cmus.status()
actions = {'prev': cmus.prev,
'play': cmus.play,
'next': cmus.nnext,
'pause': cmus.pause,
'stop': cmus.stop}
if action in actions:
message = actions[action]()
else:
message = "No such action '%s'" % action
return render_template('index.html',
status=status,
message=message)
else:
return render_template('error.html')
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=8080)