Read mp3 tags

G

Gosho Thao

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,235
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top