Search code examples
pythonaudioffmpegmp3metadata

Reading metadata from online mp3-file


I would like to read the mp3 bitrate of an online MP3 file, f.e. this one, preferrably without downloading it in its entirety.

I've been able to find out that ffmpeg allows one to do this, f.e. like so:

ffmpeg -i http://physics.ujep.cz/~mmaly/mp3/Mozart/Mass_in_C_Minor_New_by_Levin/sbory_vyssi_kvalita/01_Kyrie.mp3

but I wasn't able to find a portable way to do this. (pyffmpeg requires a C compiler as well as Cython and keeps throwing new error messages at me every time I resolve one)

If anyone has any tips/links/knows where to get further ideas, I'd be very grateful!


Solution

  • Turns out - if you have the length of the track - you can estimate the bitrate like so:

    u = urllib2.urlopen(url)
    
    meta = u.info()
    file_size = int(meta.getheaders('Content-Length')[0])
    
    estimated_bitrate = file_size/length_secs/1000*8
    

    for checking after the fact I use mutagen