Reading SHOUTcast / Icecast metadata from a radio stream using Python

Has anyone been successful in reading SHOUTcast / Icecast metadata from a remote radio stream?

There are several libraries that can read metadata from a local MP3 file, but none of them are designed to work with a radio stream (which is essentially an infinite MP3 file on a remote server).

Other recommendations suggest downloading a finite number of bits from the beginning of the mp3 stream, but this often leads to a bunch of hexadecimal output that doesn't look like text metadata.

Does anyone know of a more successful solution? Thanks.

+6
source share
3 answers
#!/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' 

Read more ... this link

+5
source

I used the @dbogdan code bit and created a library that I use for more than 4 thousand threads daily. It works well and is stable and supports metadata such as song title, artist name, bit rate and content type.

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

0
source

Since mp3 is a proprietary format, the specification is not so simple. This site gives a good overview, I think.

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

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

-1
source

Source: https://habr.com/ru/post/892249/


All Articles