gpt4 book ai didi

Python:使用 mplayer 解析流标题

转载 作者:太空狗 更新时间:2023-10-30 02:35:13 25 4
gpt4 key购买 nike

我正在用 Python 编写一个简单的前端来使用 mplayer(在子进程中)播放和录制互联网广播 channel (例如来自 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:8010MPlayer 1.0rc4-4.4.5 (C) 2000-2010 MPlayer Teammplayer: could not connect to socketmplayer: No such file or directoryFailed 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.131Connecting to server 77.111.88.131[77.111.88.131]: 8010...Name   : Justmusic.FmGenre  : HouseWebsite: http://www.justmusic.fmPublic : yesBitrate: 192kbit/sCache size set to 320 KBytesCache 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() 实际上存储了输出,但我可能错了。非常感谢任何帮助:)

最佳答案

stdout 参数设置为 PIPE,您将能够收听命令的输出:

p= subprocess.Popen(['mplayer', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout:
if line.startswith('ICY Info:'):
info = line.split(':', 1)[1].strip()
attrs = dict(re.findall("(\w+)='([^']*)'", info))
print 'Stream title: '+attrs.get('StreamTitle', '(none)')

关于Python:使用 mplayer 解析流标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3929318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com