# Read mp3 tags

**URL:** <https://www.ruby-forum.com/t/read-mp3-tags/118017>\
**Category:** Ruby\
**Created:** [October 23, 2007, 11:28am UTC](https://www.ruby-forum.com/t/read-mp3-tags/118017 "2007-10-23T11:28:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![freedom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bc8723/32.png) [@freedom](https://www.ruby-forum.com/u/freedom)\
**Post date:** [October 23, 2007, 11:28am UTC](https://www.ruby-forum.com/t/read-mp3-tags/118017/1 "2007-10-23T11:28:04Z")

</div>

I’m a newbie for Ruby. I am reading an application to read mp3 tags.  
I’ve below code to read Binary file, please help me to make full code  
and rhtml viewing file when submit a form and show data on browser.

=====================

def parse\_id3(mp3\_file)  
fields\_and\_sizes = [[:track\_name, 30], [:artist\_name, 30],  
[:album\_name, 30], [:year, 4], [:comment, 30],  
[:genre, 1]]  
tag = {}  
open(mp3\_file) do |f|  
f.seek(-128, File::SEEK\_END)  
if f.read(3) == ‘TAG’ # An ID3 tag is present  
fields\_and\_sizes.each do |field, size|  
# Read the field and strip off anything after the first null  
# character.  
data = f.read(size).gsub(/\000.\*/, ‘’)  
# Convert the genre string to a number.  
data = data[0] if field == :genre  
tag[field] = data  
end  
end  
end  
return tag  
end
