【问题标题】:Problem with python-proxy for mp3-streamsmp3-streams 的 python-proxy 问题
【发布时间】:2010-12-30 11:44:35
【问题描述】:

我正在尝试为 mp3 中的 Internet-radio 制作代理。它在访问 mp3 文件时工作正常,但不适用于 mp3 流。

我想我遗漏了一些非常基本的区别,但找不到提示。

最好的问候, 狼

我的测试代码:

#!/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)

【问题讨论】:

    标签: python audio mp3 stream


    【解决方案1】:

    问题是您阅读的不是 mp3 流,而是 M3U playlist file。此文件本身不包含任何 mp3 数据。

    你的文件内容是简单的文本:

    http://zlz-stream10.streamserver.ch/1/drs3/mp3_128
    http://glb-stream12.streamserver.ch/1/drs3/mp3_128
    http://zlz-stream13.streamserver.ch/1/drs3/mp3_128
    http://zlz-stream11.streamserver.ch/1/drs3/mp3_128
    http://glb-stream10.streamserver.ch/1/drs3/mp3_128
    http://zlz-stream12.streamserver.ch/1/drs3/mp3_128
    http://glb-stream13.streamserver.ch/1/drs3/mp3_128
    http://glb-stream11.streamserver.ch/1/drs3/mp3_128
    

    每一行都是流本身的 URL。读取 M3U 文件,解析并从这些 URL 下载流数据。

    【讨论】:

      猜你喜欢
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2021-11-06
      • 2020-04-28
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多