id3lib-ruby logo

Please note: Unfortunately, id3lib is no longer maintained and outdated (no support for ID3v2.4). Therefore id3lib-ruby is no longer actively developed. Have a look at taglib-ruby for a possible alternative (also from yours truly).

id3lib-ruby provides a Ruby interface to the id3lib C++ library for easily editing ID3 tags (v1 and v2) of MP3 audio files.

Note that id3lib has to be installed in order to use id3lib-ruby, unless you are on Windows and use the provided binary gem.



How to install id3lib-ruby and its prerequisites can be read about in the installation instructions.


See the documentation for further explanation.

require 'rubygems'
require 'id3lib'

# Load a tag from a file
tag ='talk.mp3')

# Get and set text frames with convenience methods
tag.title  #=> "Talk"
tag.album = 'X&Y'
tag.track = '5/13'

# Tag is a subclass of Array and each frame is a Hash
#=> { :id => :TPE1, :textenc => 0, :text => "Coldplay" }

# Get the number of frames
tag.length  #=> 7

# Remove all comment frames
tag.delete_if{ |frame| frame[:id] == :COMM }

# Get info about APIC frame to see which fields are allowed
#=> [ 2, :APIC, "Attached picture",
#=>   [:textenc, :mimetype, :picturetype, :description, :data] ]

# Add an attached picture frame
cover = {
  :id          => :APIC,
  :mimetype    => 'image/jpeg',
  :picturetype => 3,
  :description => 'A pretty picture',
  :textenc     => 0,
  :data        =>'cover.jpg')
tag << cover

# Last but not least, apply changes


For bug reports, support requests and feature requests, please use the appropriate tracker on RubyForge.

For comments or other things, don't hesitate to contact me:

Valid XHTML 1.0 Strict Valid CSS!