-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapmute.py
executable file
·72 lines (66 loc) · 1.67 KB
/
snapmute.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
#!/usr/bin/env python3
import asyncio
import snapcast.control
import curses
from curses import wrapper
#init curses stuff
hostname="nosuch"
stdscr=curses.initscr()
#curses.noecho()
curses.cbreak()
stdscr.keypad(True)
curses.start_color()
curses.use_default_colors()
curses.init_pair(1,1,-1)
def getserver():
loop = asyncio.get_event_loop()
server = loop.run_until_complete(snapcast.control.create_server(loop,hostname))
return(server)
def mutetoggle(server,index):
loop = asyncio.get_event_loop()
client=server.clients[index]
loop.run_until_complete(server.client_volume(client.identifier, {'muted': not client.muted}))
def main(stdscr):
index=0
while True:
stdscr.clear()
server=getserver()
clients=server.clients
names=[]
y=0
for client in clients:
if y==index:
at=curses.A_REVERSE
elif client.muted:
at=curses.A_DIM
else:
at=curses.A_BOLD
stdscr.addstr(y,1,client.friendly_name,at)
y+=1
key=stdscr.getkey()
#print(key)
if index==y:
index=0
elif index==-1:
index=y-1
if (key=="KEY_DOWN") | (key=="j"):
index+=1
elif (key=="KEY_UP") | (key=="k"):
index-=1
elif key=="\n":
mutetoggle(server,index)
elif key=="q":
break
if index==y:
index=0
elif index==-1:
index=y-1
#stdscr.addstr(y+1,1,key)
stdscr.refresh()
return;
wrapper(main)
#end curses stuff
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()