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!
I think the id3 tag is stored at the beginning of an mp3 file, you'd likely want to first learn the mp3 fileformat so you know how the data is stored. Then you'd begin downloading the file, and close the connection when you have enough data to read the bitrate.
Here's a link to the fileformat spec: http://www.mpgedit.org/mpgedit/mpeg_format/MP3Format.html
You'll just need to download the first 30 bits or so, and then parse it out. Not too hard.
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
Download the file and use your favorite id3 bindings for Python.
精彩评论