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-discid supports all features from libdiscid 0.6, but will also work with any earlier version. If a feature is unsupported in the libdiscid version used ruby-discid will just return a default value. The version required for a feature is documented in the API documentation.
- Ruby >= 2.0
- RubyGems >= 1.3.6
- Ruby-FFI >= 1.6.0
- libdiscid >= 0.1.0
Before installing ruby-discid make sure you have libdiscid installed. See http://musicbrainz.org/doc/libdiscid for more information on how to do this. For Windows see also the notes below.
Installing ruby-discid is best done using RubyGems:
gem install discid
For some Linux distributions packages are available:
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 etc.). rake install
will build the discid gem and install it.
On Windows you will need discid.dll
available in a place where Windows can
find it, see Search Path Used by Windows to Locate a DLL.
You can install the discid.dll
system wide, but it is recommended to place
it in the local working directory of your application.
Also the architecture (32 or 64 bit) of the DLL must match your Ruby version.
As the official build of libdiscid contains only a 32 bit version of discid.dll
it is recommended to use the 32 bit version of Ruby.
If you want or need to use 64 bit Ruby you will have to compile libdiscid yourself. Refer to the libdiscid install instructions for further details.
require 'discid'
# Specifying the device is optional. If omitted a platform
# specific default will be used.
device = "/dev/cdrom"
disc = DiscId.read(device)
puts disc.id
require 'discid'
device = "/dev/cdrom"
disc = DiscId.read(device, :mcn, :isrc)
# Print information about the disc:
puts "DiscID : #{disc.id}"
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
end
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 Copyright (c) 2007-2023 by Philipp Wolfer ph.wolfer@gmail.com
ruby-discid is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
See LICENSE for details.