-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocket_server.py
45 lines (31 loc) · 1.07 KB
/
socket_server.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
import socket
import alsaaudio
from os import system
def volume_up():
system("vlc-ctrl volume +10%")
def volume_down():
system("vlc-ctrl volume -0.1")
def run_socket():
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind(('', 8090))
listen_socket.listen(0)
print('Serving HTTP on port %s' % 8090)
is_paused = False
while True:
client_connection, client_address = listen_socket.accept()
request = client_connection.recv(1024)
print(request)
if request in [b'Up', b'Clockwise', b'Right']:
volume_up()
elif request in [b'Down', b'anti-clockwise', b'Left']:
volume_down()
elif request in [b'wave']:
if is_paused:
system("vlc-ctrl play")
else:
system("vlc-ctrl pause")
is_paused = not is_paused
client_connection.close()
if __name__ == "__main__":
run_socket()