-
Notifications
You must be signed in to change notification settings - Fork 0
/
vserver.py
executable file
·51 lines (40 loc) · 1.07 KB
/
vserver.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
#!/usr/bin/python
from flask import Flask, request
import json
import alsaaudio
import os
app = Flask(__name__, static_folder = "static")
m = alsaaudio.Mixer()
vol = 0
htmlfile = ""
@app.route("/")
def hello():
with open(htmlfile) as f:
return f.read()
@app.route("/volume", methods = ["POST", "GET"])
def volume():
if request.method == "POST":
change_volume(request.form['change'])
return json.dumps({"volume" : get_current_volume()})
@app.route("/mute", methods = ["POST"])
def mute():
global vol
if get_current_volume() == 0:
change_volume(vol)
else:
vol = get_current_volume()
m.setvolume(0)
return json.dumps({"volume" : get_current_volume()})
def get_current_volume():
return m.getvolume()[0]
def change_volume(by=10):
new_volume = get_current_volume() + int(by)
if new_volume > 100:
new_volume = 100
elif new_volume < 0:
new_volume = 0
m.setvolume(new_volume)
if __name__ == "__main__":
htmlfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), "volumec.html")
vol = get_current_volume()
app.run(debug = False, host = "0.0.0.0")