0

我使用了出色的 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"

谢谢,

4

1 回答 1

0

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

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'\0')
于 2018-03-19T14:04:57.837 回答