Skip to content

Instantly share code, notes, and snippets.

@johncrisostomo
Created May 28, 2011 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncrisostomo/997245 to your computer and use it in GitHub Desktop.
Save johncrisostomo/997245 to your computer and use it in GitHub Desktop.
MP3 ID3 Tag Reader
filename = ARGV
fields_and_sizes = [[:track_name, 30], [:artist_name, 30],[:album_name, 30], [:year, 4], [:comment, 30],
[:genre, 1]]
tag = Hash.new
File.open(filename.first) do |f|
f.seek(-128, IO::SEEK_END)
if f.read(3) == 'TAG'
fields_and_sizes.each do |field, size|
data = f.read(size).gsub(/\000.*/, '')
data = data.to_i if field == :genre
tag[field] = data
end
end
end
tag.each do |key, value|
puts "#{key} : #{value}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment