Has anyone had success with reading SHOUTcast/Icecast metadata from a remote radio stream?
There are several libraries that can read metadata from a local MP3 file, but none seem designed to work with a radio stream (which is essentially a never-ending MP3 file on a remote server).
Other recommendations suggest to download a finite number of bits from the beginning of the mp3 stream, but this often leads to a bunch of hex output with nothing resembling text metadata.
Anyone know of a more successful solution? Thanks.
#!/usr/bin/env python
import urllib2
stream_url = 'http://pub1.di.fm/di_classictrance'
request = urllib2.Request(stream_url)
try:
request.add_header('Icy-MetaData', 1)
response = urllib2.urlopen(request)
icy_metaint_header = response.headers.get('icy-metaint')
if icy_metaint_header is not None:
metaint = int(icy_metaint_header)
read_buffer = metaint+255
content = response.read(read_buffer)
title = content[metaint:].split("'")[1]
print title
except:
print 'Error'
For more details check this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With