Module: Cdio

Defined in:
lib/cdio.rb

Defined Under Namespace

Classes: CDText, Device, DeviceException, DriverBadParameterError, DriverBadPointerError, DriverError, DriverNotPermittedError, DriverUninitError, DriverUnsupportedError, NoDriverError, Track, TrackError

Instance Method Summary collapse

Instance Method Details

#binfile?(binfile_name) ⇒ Boolean

FIXME ? is not quite right
 binfile?(binfile_name)->cue_name

++

Determine if +binfile_name+ is the BIN file part of a CDRWIN CD
disk image.

Return the corresponding CUE file if bin_name is a BIN file or
nil if not a BIN file.

Returns:

  • (Boolean)


239
240
241
# File 'lib/cdio.rb', line 239

def binfile?(binfile_name)
  return Rubycdio::is_binfile(binfile_name)
end

#close_tray(drive = nil, driver_id = Rubycdio::DRIVER_UNKNOWN) ⇒ Object

close media tray in CD drive if there is a routine to do so.

The +driver id +is returned. A DeviceException is thrown on error.


148
149
150
151
152
# File 'lib/cdio.rb', line 148

def close_tray(drive=nil, driver_id=Rubycdio::DRIVER_UNKNOWN)
  drc, found_driver_id = Rubycdio::close_tray(drive, driver_id)
  possibly_raise_exception__(drc)
  return found_driver_id
end

#convert_drive_cap_misc(bitmask) ⇒ Object

Convert bitmask for miscellaneous drive properties

into a dictionary of drive capabilities


281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/cdio.rb', line 281

def convert_drive_cap_misc(bitmask)
  result={}
  if bitmask & Rubycdio::DRIVE_CAP_ERROR
    result[:DRIVE_CAP_ERROR] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_UNKNOWN
    result[:DRIVE_CAP_UNKNOWN] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_CLOSE_TRAY
    result[:DRIVE_CAP_MISC_CLOSE_TRAY] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_EJECT
    result[:DRIVE_CAP_MISC_EJECT] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_LOCK
    result['DRIVE_CAP_MISC_LOCK'] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_SELECT_SPEED
    result[:DRIVE_CAP_MISC_SELECT_SPEED] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_SELECT_DISC
    result[:DRIVE_CAP_MISC_SELECT_DISC] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_MULTI_SESSION
    result[:DRIVE_CAP_MISC_MULTI_SESSION] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_MEDIA_CHANGED
    result[:DRIVE_CAP_MISC_MEDIA_CHANGED] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_RESET
    result[:DRIVE_CAP_MISC_RESET] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_MISC_FILE
    result[:DRIVE_CAP_MISC_FILE] = true
  end
  return result
end

#convert_drive_cap_read(bitmask) ⇒ Object

Convert bit mask for drive read properties

into a dictionary of drive capabilities


321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/cdio.rb', line 321

def convert_drive_cap_read(bitmask)
  result={}
  if bitmask & Rubycdio::DRIVE_CAP_READ_AUDIO
    result[:DRIVE_CAP_READ_AUDIO] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_CD_DA
    result[:DRIVE_CAP_READ_CD_DA] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_CD_G
    result[:DRIVE_CAP_READ_CD_G] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_CD_R
    result[:DRIVE_CAP_READ_CD_R] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_CD_RW
    result[:DRIVE_CAP_READ_CD_RW] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_R
    result[:DRIVE_CAP_READ_DVD_R] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_PR
    result[:DRIVE_CAP_READ_DVD_PR] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RAM
    result[:DRIVE_CAP_READ_DVD_RAM] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_ROM
    result[:DRIVE_CAP_READ_DVD_ROM] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RW
    result[:DRIVE_CAP_READ_DVD_RW] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_DVD_RPW
    result[:DRIVE_CAP_READ_DVD_RPW] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_C2_ERRS
    result[:DRIVE_CAP_READ_C2_ERRS] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_MODE2_FORM1
    result[:DRIVE_CAP_READ_MODE2_FORM1] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_MODE2_FORM2
    result[:DRIVE_CAP_READ_MODE2_FORM2] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_MCN
    result[:DRIVE_CAP_READ_MCN] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_READ_ISRC
    result[:DRIVE_CAP_READ_ISRC] = true
  end
  return result
end

#convert_drive_cap_write(bitmask) ⇒ Object

Convert bitmask for drive write properties

into a dictionary of drive capabilities


376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/cdio.rb', line 376

def convert_drive_cap_write(bitmask)
  result={}
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_CD_R
    result[:DRIVE_CAP_WRITE_CD_R] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_CD_RW
    result[:DRIVE_CAP_WRITE_CD_RW] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_R
    result[:DRIVE_CAP_WRITE_DVD_R] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_PR
    result[:DRIVE_CAP_WRITE_DVD_PR] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RAM
    result[:DRIVE_CAP_WRITE_DVD_RAM] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RW
    result[:DRIVE_CAP_WRITE_DVD_RW] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_DVD_RPW
    result[:DRIVE_CAP_WRITE_DVD_RPW] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_MT_RAINIER
    result[:DRIVE_CAP_WRITE_MT_RAINIER] = true
  end
  if bitmask & Rubycdio::DRIVE_CAP_WRITE_BURN_PROOF
    result[:DRIVE_CAP_WRITE_BURN_PROOF] = true
  end
  return result
end

#cuefile?(cuefile_name) ⇒ Boolean

FIXME ? is not quite right

++

return bin_name for a corresponding CUE file

Determine if cuefile_name is the CUE file part of a CDRWIN CD
disk image.

Return the corresponding BIN file if bin_name is a CUE file or
nil if not a CUE file.

Returns:

  • (Boolean)


253
254
255
# File 'lib/cdio.rb', line 253

def cuefile?(cuefile_name)
  return Rubycdio::is_cuefile(cuefile_name)
end

#default_device_driver(driver_id = Rubycdio::DRIVER_DEVICE) ⇒ Object

Returns: [device, driver]

Return a string containing the default CD device if none is
specified.  if +driver_id+ is DRIVER_UNKNOWN or DRIVER_DEVICE
then one set the default device for that.

nil is returned as the device if we couldn't get a default
device.


162
163
164
# File 'lib/cdio.rb', line 162

def default_device_driver(driver_id=Rubycdio::DRIVER_DEVICE)
  return Rubycdio::get_default_device_driver(driver_id)
end

#device?(source, driver_id = Rubycdio::DRIVER_UNKNOWN) ⇒ Boolean

Returns: bool

Return true if source refers to a real hardware CD-ROM.

Returns:

  • (Boolean)


260
261
262
263
# File 'lib/cdio.rb', line 260

def device?(source, driver_id=Rubycdio::DRIVER_UNKNOWN)
  if not driver_id then driver_id=Rubycdio::DRIVER_UNKNOWN end
  return Rubycdio::device?(source, driver_id)
end

#devices(driver_id = Rubycdio::DRIVER_UNKNOWN) ⇒ Object

Returns: [device1, device2, …]

Get an list of device names.


169
170
171
# File 'lib/cdio.rb', line 169

def devices(driver_id=Rubycdio::DRIVER_UNKNOWN)
  return Rubycdio::get_devices(driver_id)
end

#devices_ret(driver_id = Rubycdio::DRIVER_UNKNOWN) ⇒ Object

Returns: [device1, device2, … driver_id]

Like get_devices, but return the driver_id which may be different
from the passed-in driver_id if it was Rubycdio::DRIVER_DEVICE or
Rubycdio::DRIVER_UNKNOWN. The return +driver_id+ may be useful because
often one wants to get a drive name and then *open* it
afterwards. Giving the driver back facilitates this, and speeds things
up for libcdio as well.


181
182
183
# File 'lib/cdio.rb', line 181

def devices_ret(driver_id=Rubycdio::DRIVER_UNKNOWN)
  devices = Rubycdio::get_devices_ret(driver_id)
end

#devices_with_cap(capabilities, any = false) ⇒ Object

Get an array of device names in search_devices that have at least

the capabilities listed by the capabities parameter.  

If any is false then every capability listed in the
extended portion of capabilities (i.e. not the basic filesystem)
must be satisified. If any is true, then if any of the
capabilities matches, we call that a success.

To find a CD-drive of any type, use the mask Rubycdio::CDIO_FS_MATCH_ALL.

The array of device names is returned or nil if we couldn't get a
default device.  It is also possible to return a non nil but after
dereferencing the the value is nil. This also means nothing was
found.


199
200
201
# File 'lib/cdio.rb', line 199

def devices_with_cap(capabilities, any=false)
  return Rubycdio::get_devices_with_cap(capabilities, any)
end

#devices_with_cap_ret(capabilities, any = false) ⇒ Object

Returns: [device1, device2…, driver_id]

Like cdio_get_devices_with_cap but we return the driver we found
as well. This is because often one wants to search for kind of drive
and then *open* it afterwards. Giving the driver back facilitates this,
and speeds things up for libcdio as well.


209
210
211
# File 'lib/cdio.rb', line 209

def devices_with_cap_ret(capabilities, any=false)
  return Rubycdio::get_devices_with_cap_ret(capabilities, any)
end

#driver?(driver_id) ⇒ Boolean

return bool

Return true if we have driver driver_id.

Returns:

  • (Boolean)


216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/cdio.rb', line 216

def driver?(driver_id)
  if driver_id.class == Fixnum
    return Rubycdio::have_driver(driver_id) == 1
  elsif driver_id.class == Symbol and drivers.member?(driver_id)
    ret = Rubycdio::have_driver(drivers[driver_id])
    if ret == 0 then return false end
    if ret == 1 then return true end
    raise ArgumentError
  else
    raise ArgumentError
  end
end

#driversObject

Note: the keys below match those the names returned by cdio_get_driver_name().



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cdio.rb', line 118

def drivers()
  return {
    :Unknown     => Rubycdio::DRIVER_UNKNOWN,
    :AIX         => Rubycdio::DRIVER_AIX,
    :BSDI        => Rubycdio::DRIVER_BSDI,
    :FreeBSD     => Rubycdio::DRIVER_FREEBSD,
    :"GNU/Linux" => Rubycdio::DRIVER_LINUX,
    :Solaris     => Rubycdio::DRIVER_SOLARIS,
    :"OS X"      => Rubycdio::DRIVER_OSX,
    :WIN32       => Rubycdio::DRIVER_WIN32,
    :CDRDAO      => Rubycdio::DRIVER_CDRDAO,
    :"BIN/CUE"   => Rubycdio::DRIVER_BINCUE,
    :NRG         => Rubycdio::DRIVER_NRG,
    :device      => Rubycdio::DRIVER_DEVICE
  }
end

#nrg?(nrgfile_name) ⇒ Boolean

Returns: bool

Determine if nrgfile_name is a Nero CD disc image

Returns:

  • (Boolean)


268
269
270
# File 'lib/cdio.rb', line 268

def nrg?(nrgfile_name)
  return Rubycdio::nrg?(nrgfile_name)
end

#possibly_raise_exception__(drc, msg = nil) ⇒ Object

Raise a Driver Error exception on error as determined by drc



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cdio.rb', line 71

def possibly_raise_exception__(drc, msg=nil)
  if drc==Rubycdio::DRIVER_OP_SUCCESS
    return
  end
  if drc==Rubycdio::DRIVER_OP_ERROR
    raise DriverError
  end
  if drc==Rubycdio::DRIVER_OP_UNINIT
    raise DriverUninitError
  end
  if drc==Rubycdio::DRIVER_OP_UNSUPPORTED
    raise DriverUnsupportedError
  end
  if drc==Rubycdio::DRIVER_OP_NOT_PERMITTED
    raise DriverUnsupportedError
  end
  if drc==Rubycdio::DRIVER_OP_BAD_PARAMETER
    raise DriverBadParameterError
  end
  if drc==Rubycdio::DRIVER_OP_BAD_POINTER
    raise DriverBadPointerError
  end
  if drc==Rubycdio::DRIVER_OP_NO_DRIVER
    raise NoDriverError
  end
  raise DeviceException('unknown exception %d' % drc)
end

#read_mode2blocksizeObject



135
136
137
138
139
140
141
142
143
# File 'lib/cdio.rb', line 135

def read_mode2blocksize()
  return {
    Rubycdio::READ_MODE_AUDIO =>  Rubycdio::CD_FRAMESIZE_RAW,
    Rubycdio::READ_MODE_M1F1  =>  Rubycdio::M2RAW_SECTOR_SIZE,
    Rubycdio::READ_MODE_M1F2  =>  Rubycdio::CD_FRAMESIZE,
    Rubycdio::READ_MODE_M2F1  =>  Rubycdio::M2RAW_SECTOR_SIZE,
    Rubycdio::READ_MODE_M2F2  =>  Rubycdio::CD_FRAMESIZE
  }
end

#tocfile?(tocfile_name) ⇒ Boolean

tocfile?(tocfile_name)->bool

Determine if +tocfile_name+ is a cdrdao CD disc image

Returns:

  • (Boolean)


275
276
277
# File 'lib/cdio.rb', line 275

def tocfile?(tocfile_name)
  return Rubycdio::tocfile?(tocfile_name)
end