Module: DiscId
- Defined in:
- lib/discid.rb,
lib/discid/lib.rb,
lib/discid/disc.rb,
lib/discid/track.rb,
lib/discid/version.rb,
lib/discid/disc_error.rb
Overview
The DiscId module allows calculating DiscIDs (MusicBrainz and freedb) for Audio CDs. Additionally the library can extract the MCN/UPC/EAN and the ISRCs from disc.
The main interface for using this module are the DiscId.read and DiscId.put methods which both return an instance of Disc. DiscId.read allows you to read the data from an actual CD drive while DiscId.put allows you to calculate the DiscID for a previously read CD TOC.
Depending on the version of libdiscid and the operating system used additional features like reading the MCN or ISRCs from the disc might be available. You can check for supported features with DiscId.feature?.
Defined Under Namespace
Classes: Disc, DiscError, Track
Constant Summary collapse
- LIBDISCID_VERSION =
Note:
This will only give meaningful results for libdiscid 0.4.0 and higher. For lower versions this constant will always have the value "libdiscid < 0.4.0".
The libdiscid version.
Lib.get_version_string
- VERSION =
The version of ruby-discid.
'1.7.0'.freeze
Class Method Summary collapse
-
.default_device ⇒ String
Return the name of the default disc drive for this operating system.
-
.feature?(feature) ⇒ Boolean
(also: has_feature?)
Check if a certain feature is implemented on the current platform.
-
.feature_list ⇒ Array<Symbol>
A list of features supported by the current platform.
-
.parse(toc) ⇒ Disc
Parses a TOC string and returns a [Disc] instance for it.
-
.put(first_track, sectors, offsets) ⇒ Disc
Provides the TOC of a known CD.
-
.read(device = nil, *features) ⇒ Disc
Read the disc in the given CD-ROM/DVD-ROM drive extracting only the TOC and additionally specified features.
Class Method Details
.default_device ⇒ String
Return the name of the default disc drive for this operating system.
148 149 150 |
# File 'lib/discid.rb', line 148 def self.default_device Lib.default_device end |
.feature?(feature) ⇒ Boolean Also known as: has_feature?
libdiscid >= 0.5.0 required. Older versions will return true
for :read and false for anything else.
Before version 1.7 this method was called has_feature?, which is
deprecated but still available as an alias.
Check if a certain feature is implemented on the current platform.
You can obtain a list of supported features with feature_list.
166 167 168 169 |
# File 'lib/discid.rb', line 166 def self.feature?(feature) feature = feature.to_sym if feature.respond_to? :to_sym feature_list.include? feature end |
.feature_list ⇒ Array<Symbol>
libdiscid >= 0.5.0 required. Older versions will return only [:read].
A list of features supported by the current platform.
Currently the following features are available:
- :read
- :mcn
- :isrc
188 189 190 |
# File 'lib/discid.rb', line 188 def self.feature_list Lib::Features.symbols.select { |f| Lib.has_feature(f) == 1 } end |
.parse(toc) ⇒ Disc
Parses a TOC string and returns a [Disc] instance for it.
This function can be used if you already have a TOC string like e.g.
1 4 78615 150 20971 36350 54056.
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/discid.rb', line 131 def self.parse(toc) raise DiscError, "Invalid TOC #{toc.inspect}" if toc.nil? || toc.empty? begin parts = toc.split(' ') first_track = Integer(parts[0]) sectors = Integer(parts[2]) offsets = parts[3..-1].map{|i| Integer(i)} rescue ArgumentError, TypeError => e raise DiscError, e end put(first_track, sectors, offsets) end |
.put(first_track, sectors, offsets) ⇒ Disc
Provides the TOC of a known CD.
This function may be used if the TOC has been read earlier and you want to calculate the disc ID afterwards, without accessing the disc drive.
117 118 119 120 121 |
# File 'lib/discid.rb', line 117 def self.put(first_track, sectors, offsets) disc = Disc.new disc.put first_track, sectors, offsets disc end |
.read(device = nil, *features) ⇒ Disc
libdiscid >= 0.5.0 is required for the feature selection to work. Older versions will allways read MCN and ISRCs when supported. See https://musicbrainz.org/doc/libdiscid#Feature_Matrix for a list of supported features by version and platform.
Read the disc in the given CD-ROM/DVD-ROM drive extracting only the TOC and additionally specified features.
This function reads the disc in the drive specified by the given device
identifier. If the device is nil, the default device, as returned by
default_device, is used.
This function will always read the TOC, but additional features like :mcn
and :isrc can be set using the features parameter. You can set multiple
features.
99 100 101 102 103 |
# File 'lib/discid.rb', line 99 def self.read(device = nil, *features) disc = Disc.new disc.read device, *features disc end |