Python:使用 mplayer 解析流标题
我正在用Python编写一个简单的前端,以使用mplayer(在子进程中)播放和录制网络广播频道(例如来自shoutcast)。当用户单击某个电台时,将运行以下代码:
url = http://77.111.88.131:8010 # only an example
cmd = "mplayer %s" % url
p = subprocess.Popen(cmd.split(), shell=False)
wait = os.waitpid(p.pid, 1)
return int(p.pid)
这工作正常,流开始按预期播放。尽管我想以某种方式解析流的标题。看来我需要从 mplayer 输出中获取标题。这是我在终端中播放流时的输出:
$ mplayer http://77.111.88.131:8010 MPlayer 1.0rc4-4.4.5 (C) 2000-2010 MPlayer Team mplayer: could not connect to socket mplayer: No such file or directory Failed to open LIRC support. You will not be able to use your remote control. Playing http://77.111.88.131:8010. Resolving 77.111.88.131 for AF_INET6... Couldn't resolve name for AF_INET6: 77.111.88.131 Connecting to server 77.111.88.131[77.111.88.131]: 8010... Name : Justmusic.Fm Genre : House Website: http://www.justmusic.fm Public : yes Bitrate: 192kbit/s Cache size set to 320 KBytes Cache fill: 0.00% (0 bytes) ICY Info: StreamTitle='(JustMusic.FM) Basement - Zajac, Migren live at Justmusic 2010-10-09';StreamUrl='http://www.justmusic.fm'; Cache fill: 17.50% (57344 bytes) Audio only file format detected.
然后它会运行直到停止。所以问题是,我如何检索“(JustMusic.FM) Basement - Zajac, Migren live at Justmusic 2010-10-09”并仍然让进程运行?我不认为 subprocess() 实际上存储输出,但我可能是错的。非常感谢任何帮助:)
I'm writing a simple frontend in Python to play and record internet radio channels (e.g. from shoutcast) using mplayer (in a subprocess). When a user clicks a station the following code is run:
url = http://77.111.88.131:8010 # only an example
cmd = "mplayer %s" % url
p = subprocess.Popen(cmd.split(), shell=False)
wait = os.waitpid(p.pid, 1)
return int(p.pid)
This works perfectly, the stream starts playing as it should. Although I would like to somehow parse the title of the stream. It seems that I need to fetch the title from the mplayer output. This is the output when I play the stream in a terminal:
$ mplayer http://77.111.88.131:8010 MPlayer 1.0rc4-4.4.5 (C) 2000-2010 MPlayer Team mplayer: could not connect to socket mplayer: No such file or directory Failed to open LIRC support. You will not be able to use your remote control. Playing http://77.111.88.131:8010. Resolving 77.111.88.131 for AF_INET6... Couldn't resolve name for AF_INET6: 77.111.88.131 Connecting to server 77.111.88.131[77.111.88.131]: 8010... Name : Justmusic.Fm Genre : House Website: http://www.justmusic.fm Public : yes Bitrate: 192kbit/s Cache size set to 320 KBytes Cache fill: 0.00% (0 bytes) ICY Info: StreamTitle='(JustMusic.FM) Basement - Zajac, Migren live at Justmusic 2010-10-09';StreamUrl='http://www.justmusic.fm'; Cache fill: 17.50% (57344 bytes) Audio only file format detected.
It then runs until it's stopped. So the question is, how can I retrieve "(JustMusic.FM) Basement - Zajac, Migren live at Justmusic 2010-10-09" and still let the process run? I don't think subprocess() actually stores the output, but I might be mistaken. Any help is deeply appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
stdout
参数设置为PIPE
,您将能够收听命令的输出:Set the
stdout
argument toPIPE
and you'll be able to listen to the output of the command:编辑:我在这里有一个不同的(更简单的)解决方案,但它停止工作,所以我更新了我的解决方案。想法:mplayer 在 1 秒后停止。 (
-endpos 1
)。Edit: I had a different (simpler) solution here that stopped working so I updated my solution. The idea: mplayer stops after 1 sec. (
-endpos 1
).