Python - 解析 Liquidsoap 元数据



我使用了出色的liquidsoap流引擎,但是从telnet服务器解析alsa.metadata命令的结果时遇到了一些麻烦。

下面是他的输出示例:

--- 10 ---
source_url="http://liquidsoap.local:8020/radio"
title="anastacia - lumere lumera"
--- 9 ---
source_url="http://liquidsoap.local:8020/radio"
title="bob tostes - strangers in the night"
--- 8 ---
source_url="http://liquidsoap.local:8020/radio"
title="lucio battisti - amarsi un po"
--- 7 ---
source_url="http://liquidsoap.local:8020/radio"
title="george white group - nothing compares to you"
--- 6 ---
source_url="http://liquidsoap.local:8020/radio"
title="olivia - true colors"
--- 5 ---
source_url="http://liquidsoap.local:8020/radio"
title="ritmo del mundo - what s love got to do with it"
--- 4 ---
source_url="http://liquidsoap.local:8020/radio"
title="tania maria - come with me"
--- 3 ---
source_url="http://liquidsoap.local:8020/radio"
title="antonio carlos jobim a sting - how insentive"
--- 2 ---
source_url="http://liquidsoap.local:8020/radio"
title="dht - driver s seat"
--- 1 ---
source_url="http://liquidsoap.local:8020/radio"
title="marg nelson - lady marmelade"

它看起来不像任何已知的格式..csv,json,xml...你能告诉我如何制作一个 Python 数组吗?

前任:

[10] => [source_url] => "http://liquidsoap.local:8020/radio", [title] => "anastacia - lumere lumera",
[9] => [source_url] => "http://liquidsoap.local:8020/radio", [title] => "bob tostes - strangers in the night"

谢谢

我使用该脚本来解析元数据:

url = 'http://localhost:8000/radio'
request = urllib2.Request(url, headers={'Icy-MetaData': 1})  # request metadata
response = urllib2.urlopen(request)
#print(response.headers, file=sys.stderr)
metaint = int(response.headers['icy-metaint'])
# title may be empty initially, try several times
response.read(metaint)  # skip to metadata
metadata_length = struct.unpack('B', response.read(1))[0] * 16  # length byte
metadata = response.read(metadata_length).rstrip(b'')

相关内容

  • 没有找到相关文章

最新更新