2016-01-29 33 views
2

如何使用urllib3读取关于播放歌曲的信息?我应该使用哪些标题?Python 3 - Urllib3读取互联网广播元数据

import urllib3 
http = urllib3.PoolManager() 
response = http.request("GET", "http://pool.cdn.lagardere.cz/fm-evropa2-128", headers={ 
     'User-Agent': 'User-Agent: VLC/2.0.5 LibVLC/2.0.5', 
     'Icy-MetaData': '1', 
     'Range': 'bytes=0-', 
    }) 
print(response.data) 

我试过了。但它发送请求。谁能帮我?感谢您的回答。

+1

也许这有助于http://docs.python-requests.org/en/latest/user/advanced/ –

+0

感谢它看起来很好! –

回答

1

以下代码返回给定流的所有标头数据。不幸的是,我无法通过这种方式获得歌曲名称。

import requests 

url = 'http://pool.cdn.lagardere.cz/fm-evropa2-128' 

def print_url(r, *args, **kwargs): 
    print(r.headers) 

requests.get(url, hooks=dict(response=print_url)) 

输出如下:

{'icy-description': 'Evropa 2', 'Via': '1.1 s670-6.noc.rwth-aachen.de:80 (Cisco-WSA/8.8.0-085)', 'icy-genre': 'Various', 'icy-url': 'http://www.evropa2.cz', 'icy-pub': '0', 'ice-audio-info': 'ice-samplerate=44100;ice-bitrate=128;ice-channels=2', 'Date': 'Fri, 29 Jan 2016 17:24:20 GMT', 'icy-br': '128, 128', 'Content-Type': 'audio/mpeg', 'Connection': 'keep-alive', 'Transfer-Encoding': 'chunked', 'icy-name': 'Evropa 2', 'Server': 'Icecast 2.3.2', 'Cache-Control': 'no-cache'} 
+0

非常感谢! –