I have a list of files on a server and would like to load and parse only the ID3 from each file.
The code below loads the entire file, which is (obviously) very time consuming when batched.
require 'mp3info'
require 'open-uri'
uri = "http://blah.com/blah.mp3"
Mp3Info.open(open(uri)) do |mp3|
puts mp3.tag.title
puts mp3.tag.artist
puts mp3.tag.album
puts mp3.tag.tracknum
end
Well this solution works for id3v2 (the current standard). ID3V1 doesn’t have the metadata at the beginning of the file, so it wouldn’t work in those cases.
This reads the first 4096 bytes of the file, which is arbitrary. As far as I could tell from the ID3 documentation, there is no limit to the size, but 4kb was when I stopped getting parsing errors in my library.
I was able to build a simple dropbox audio player, which can be seen here:
soundstash.heroku.com
and open-sourced the code here: github.com/miketucker/Dropbox-Audio-Player