70 lines
1.7 KiB
Python
Executable File
70 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import socket
|
|
import getopt
|
|
import sys
|
|
import subprocess
|
|
|
|
client_socket = socket.socket()
|
|
server_IP = "192.168.188.64"
|
|
|
|
def connect(host, port = 5000):
|
|
client_socket.connect((host, port))
|
|
|
|
def disconnect():
|
|
client_socket.close() # close the connection
|
|
|
|
def send(data):
|
|
client_socket.send(data.encode()) # send message
|
|
|
|
def helpmenu():
|
|
print("Options:")
|
|
print("-h show help")
|
|
print("-s <color> set static color in hex")
|
|
print("-v visualizer()")
|
|
|
|
def visualizer():
|
|
cava = subprocess.Popen(["cava", "-p", "./config"], stdout=subprocess.PIPE)
|
|
sed = subprocess.Popen(["sed", "-u", "s/;.*;$//"], stdin=cava.stdout, stdout=subprocess.PIPE)
|
|
subprocess.Popen([sys.argv[0]], stdin=sed.stdout, shell=True)
|
|
cava.stdout.close()
|
|
sed.stdout.close()
|
|
|
|
def rgb_to_hex(r,g,b):
|
|
return "%02x%02x%02x" % (r,g,b)
|
|
|
|
def main(argv):
|
|
|
|
if not sys.stdin.isatty():
|
|
connect(server_IP)
|
|
for volume in sys.stdin:
|
|
volume = int(volume)
|
|
hex_color = rgb_to_hex(volume,0,0)
|
|
send(hex_color)
|
|
print(hex_color)
|
|
sys.exit()
|
|
|
|
try:
|
|
opts, args = getopt.getopt(argv, "s:vh")
|
|
except getopt.GetoptError:
|
|
print(sys.argv[0], "invalid option")
|
|
print("Try", sys.argv[0], "-h for help")
|
|
sys.exit(1)
|
|
|
|
for opt, arg in opts:
|
|
if opt == "-h":
|
|
helpmenu()
|
|
sys.exit()
|
|
elif opt == "-s":
|
|
connect(server_IP)
|
|
send(arg)
|
|
sys.exit()
|
|
elif opt == "-v":
|
|
visualizer()
|
|
sys.exit()
|
|
|
|
helpmenu()
|
|
sys.exit()
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv[1:])
|