I am trying to make a proxy for internet-radio in mp3. It is working fine when accessing mp3-files, but not for mp3-streams.
I suppose I am missing some very basic difference but could not find a hint.
Best regards, wolf
My test code:
#!/usr/local/bin/python2.5
import urllib;
import SocketServer, BaseHTTPServer
import subprocess
class Proxy:
def __init__(self, port=4500):
self.port = port
self.server = SocketServer.ThreadingTCPServer(('', self.port), self.Manager)
class Manager(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "audio/mpeg");
self.end_headers();
process = subprocess.Popen("lame --mp3input -m m --abr 128 -b 64 - -", shell=True, bufsize=64,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
(streamin, streamout) = (process.stdin, process.stdout)
# Does not work
url = urllib.urlopen("http://stream.srg-ssr.ch:80%s" % "/drs3/mp3_128.m3u")
# Does work
#url = urllib.urlopen("http://www.openbsd.org:80%s" % "/songs/song46.mp3")
buffer = url.read(4096)
while len(buffer) > 0:
streamin.streamout(buffer);
while 1:
data = select.select([streamout.fileno()], [],[],.1);
if len(data[0]) == 0:
break
mp3 = streamout.read(4096)
self.wfile.write(mp3)
buf = url.read(4096)