FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit d1dd48e2 authored by Silas S. Brown's avatar Silas S. Brown
Browse files

player utility Python3 compat

parent 00e87b27
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python2
#!/usr/bin/env python
# (should work in both Python 2 and Python 3)
# Simple sound-playing server
# Silas S. Brown - public domain - no warranty
......@@ -14,19 +15,27 @@ os.environ["PATH"] += ":/usr/local/bin"
s=socket.socket()
s.bind(('',8124))
s.listen(5)
if type(b"")==type(""): S=lambda x:x # Python 2
else: S=lambda x:x.decode("latin1") # Python 3
while True:
c,a = s.accept()
d = c.recv(4)
if d=='RIFF': player = "play - 2>/dev/null" # WAV
d = S(c.recv(4))
if d=='RIFF': # WAV
player = "play - 2>/dev/null"
elif d=='STOP':
c.close()
while not d=='START':
c,a = s.accept() ; d = c.recv(5) ; c.close()
c,a = s.accept()
d = S(c.recv(5)) ; c.close()
continue
else: player = "mpg123 - 2>/dev/null" # MP3
player = os.popen(player,"w")
d = d.encode("latin1") # no-op on Python 2
while d:
try: player.write(d)
try:
try: player.write(d)
except TypeError: # Python 3
player.buffer.write(d)
except IOError: break # it was probably killed
d = c.recv(4096)
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment