Ruby bindings for MusicBrainz libdiscid

Build Status Code Climate Code Climate Gem Version


ruby-discid provides Ruby bindings for the MusicBrainz DiscID library libdiscid. It allows calculating DiscIDs (MusicBrainz and freedb) for Audio CDs. Additionally the library can extract the MCN/UPC/EAN and the ISRCs from disc.


  • Ruby >= 1.8.7
  • RubyGems >= 1.3.6
  • Ruby-FFI >= 1.6.0
  • libdiscid >= 0.1.0


Before installing ruby-discid make sure you have libdiscid installed. See for more information on how to do this.

Installing ruby-discid is best done using RubyGems:

gem install discid

You can also install from source. This requires RubyGems and Bundler installed. First make sure you have installed bundler:

gem install bundler

Then inside the ruby-discid source directory run:

bundle install
rake install

bundle install will install additional development dependencies (Rake, Yard and Kramdown). rake install will build the discid gem and install it.


Read only the TOC

require 'discid'

device = "/dev/cdrom"
disc =

Read the TOC, MCN and ISRCs

require 'discid'

device = "/dev/cdrom"
disc =, :mcn, :isrc)

# Print information about the disc:
puts "DiscID      : #{}"
puts "FreeDB ID   : #{disc.freedb_id}"
puts "Total length: #{disc.seconds} seconds"
puts "MCN         : #{disc.mcn}"

# Print information about individual tracks:
disc.tracks do |track|
  puts "Track ##{track.number}"
  puts "  Length: %02d:%02d (%i sectors)" %
      [track.seconds / 60, track.seconds % 60, track.sectors]
  puts "  ISRC  : %s" % track.isrc

See the API documentation of DiscId or the files in the examples directory for more usage information.


The source code for ruby-discid is available on GitHub.

Please report any issues on the issue tracker.


ruby-discid is released under the GNU Lesser General Public License Version 3. See LICENSE for details.