7

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.

Community
  • 1
  • 1
yujas
  • 71
  • 1
  • 2

3 Answers3

6
#!/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

dbogdan
  • 99
  • 1
  • 5
0

I used a bit of @dbogdan's code and created a library I use for over 4 thousands streams daily. It works good and is stable and support metadata such as song title, artist name, bitrate and content-type.

you can find it at https://github.com/Dirble/streamscrobbler-python

Håkan Nylén
  • 142
  • 1
  • 10
-1

Since mp3 is a proprietary format, the specification is not so easy to come by. This website gives a good overview, I think.

In normal mp3 files, the ID3v1 metadata tag goes at the very end of the file, it makes up the last 128 bytes. This is actually a bad design. The ID3 system was added as an afterthought to mp3, so I guess there was no other way to do it without breaking backward-compatibility. This means that if the radio stream is provided like a never-ending mp3 file, there can be no ID3 tag in the normal sense.

I would check with the people who run the radio station; perhaps they put the ID3 tag in a non-standard place?

jforberg
  • 6,537
  • 3
  • 29
  • 47
  • Thanks for the info. I should have mentioned that I am trying to do this with Shoutcast/Icecast and Live365 streams, which most likely have standardized their metadata format in some way, I just haven't been able to find it yet. – yujas Jul 07 '11 at 21:52
  • @jforberg Internet radio streams do not use ID3 tags. SHOUTcast/Icecast-style streams use metadata interleaved into the audio data. On the receiving end, this is split out. – Brad Nov 09 '14 at 17:56