Created
May 28, 2011 21:26
-
-
Save johncrisostomo/997245 to your computer and use it in GitHub Desktop.
MP3 ID3 Tag Reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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