Class: DiscId::Disc

Inherits:
Object
  • Object
show all
Defined in:
lib/discid/disc.rb

Overview

This class holds information about a disc (TOC, MCN, ISRCs).

Use #read or #put to initialize an instance of Disc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deviceObject (readonly)

The device from which this disc object was read.


29
30
31
# File 'lib/discid/disc.rb', line 29

def device
  @device
end

Instance Method Details

#first_track_numberInteger

The number of the first track on this disc.

Returns:

  • (Integer)

    The number of the first track or nil if no ID was yet read.


95
96
97
# File 'lib/discid/disc.rb', line 95

def first_track_number
  return Lib.get_first_track_num @handle if @read
end

#freedb_idString

The FreeDB DiscID.

Returns:

  • (String)

    The DiscID or nil if no ID was yet read.


88
89
90
# File 'lib/discid/disc.rb', line 88

def freedb_id
  return Lib.get_freedb_id @handle if @read
end

#idString

The MusicBrainz DiscID.

Returns:

  • (String)

    The DiscID or nil if no ID was yet read.


81
82
83
# File 'lib/discid/disc.rb', line 81

def id
  return Lib.get_id @handle if @read
end

#last_track_numberInteger

The number of the last track on this disc.

Returns:

  • (Integer)

    The number of the last track or nil if no ID was yet read.


102
103
104
# File 'lib/discid/disc.rb', line 102

def last_track_number
  return Lib.get_last_track_num @handle if @read
end

#mcnString

Note:

libdiscid >= 0.3.0 required. Older versions will always return nil. Not available on all platforms, see http://musicbrainz.org/doc/libdiscid#Feature_Matrix.

The media catalogue number on the disc, if present.

Requires libdiscid >= 0.5. If not supported this method will always return nil.

Returns:

  • (String)

    MCN or nil if no ID was yet read.


130
131
132
# File 'lib/discid/disc.rb', line 130

def mcn
  return Lib.get_mcn @handle if @read
end

#secondsInteger

The length of the disc in seconds.

Returns:

  • (Integer)

    Seconds or nil if no ID was yet read.


116
117
118
# File 'lib/discid/disc.rb', line 116

def seconds
  DiscId.sectors_to_seconds(sectors) if @read
end

#sectorsInteger

The length of the disc in sectors.

Returns:

  • (Integer)

    Sectors or nil if no ID was yet read.


109
110
111
# File 'lib/discid/disc.rb', line 109

def sectors
  return Lib.get_sectors @handle if @read
end

#submission_urlString

An URL for submitting the DiscID to MusicBrainz.

The URL leads to an interactive disc submission wizard that guides the user through the process of associating this disc's DiscID with a release in the MusicBrainz database.

Returns:

  • (String)

    Submission URL


174
175
176
# File 'lib/discid/disc.rb', line 174

def submission_url
  return Lib.get_submission_url @handle if @read
end

#to_sString

DiscID to String conversion. Same as calling the method #id but guaranteed to return a string.

Returns:

  • (String)

    The disc ID as a string or an empty string if no ID was yet read.


183
184
185
# File 'lib/discid/disc.rb', line 183

def to_s
  id.to_s
end

#toc_stringString

Return a string representing CD Table Of Contents (TOC).

The TOC suitable as a value of the toc parameter when accessing the MusicBrainz Web Service. This enables fuzzy searching when the actual DiscID is not found.

Note that this is the unencoded value, which still contains spaces.

For libdiscid >= 0.6 the native implementation will be used. For older versions falls back to extract the TOC from #submission_url.

Returns:

  • (String)

    The TOC string or nil if no ID was yet read.

Raises:

  • (RuntimeError)

    get_toc_string is unsupported by libdiscid and could not get extracted from #submission_url

Since:

  • 1.3


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/discid/disc.rb', line 150

def toc_string
  return nil if not @read
  result = Lib.get_toc_string @handle
  if not result
    # probably an old version of libdiscid (< 0.6.0)
    # gather toc string from submission_url
    match = /toc=([0-9+]+)/.match self.submission_url
    if match
      result = match[1].tr("+", " ")
    else
      raise "can't get toc string from submission url"
    end
  end

  return result
end

#tracks {|Track| ... } ⇒ Array<Track>

Returns an array of Track objects. Each Track object contains detailed information about the track.

Returns always nil if no ID was yet read. The block won't be called in this case.

Yields:

  • (Track)

    If a block is given this method returns nil and instead iterates over the block calling the block with one argument.

Yield Returns:

  • (nil)

Returns:


197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/discid/disc.rb', line 197

def tracks
  if @read
    read_tracks if @tracks.nil?

    if block_given?
      @tracks.each(&Proc.new)
      return nil
    else
      return @tracks
    end
  end
end