Detect and handle CD-R discs (#154)

* Use cdrdao to detect CD-Rs and continue ripping only if the argument --cdr is passed.

* Get and display disc format from MusicBrainz.

* Add info about CD-R detection to logger

* Remove Musicbrainz medium format info

* add cdrdao command to logger

* Fix for PEP8

* Fix line break
This commit is contained in:
gorgobacka
2017-06-06 11:12:00 +02:00
committed by JoeLametta
parent fe4cf1a745
commit 4b3d462b16
4 changed files with 31 additions and 0 deletions

View File

@@ -143,6 +143,13 @@ class _CD(BaseCommand):
"--unknown not passed")
return -1
self.program.result.isCdr = cdrdao.DetectCdr(self.device)
if (self.program.result.isCdr and
not getattr(self.options, 'cdr', False)):
logger.critical("inserted disc seems to be a CD-R, "
"--cdr not passed")
return -1
# FIXME ?????
# Hackish fix for broken commit
offset = 0
@@ -300,6 +307,11 @@ Log files will log the path to tracks relative to this directory.
action="store_true", dest="unknown",
help="whether to continue ripping if "
"the CD is unknown", default=False)
self.parser.add_argument('--cdr',
action="store_true", dest="cdr",
help="whether to continue ripping if "
"the disc is a CD-R",
default=False)
def handle_arguments(self):
self.options.output_directory = os.path.expanduser(

View File

@@ -47,6 +47,19 @@ def read_toc(device, fast_toc=False):
return toc
def DetectCdr(device):
"""
Return whether cdrdao detects a CD-R for 'device'.
"""
cmd = [CDRDAO, 'disk-info', '-v1', '--device', device]
logger.debug("executing %r", cmd)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
if 'CD-R medium : n/a' in p.stdout.read():
return False
else:
return True
def version():
"""
Return cdrdao version as a string.

View File

@@ -54,6 +54,11 @@ class WhipperLogger(result.Logger):
# Next one fully works only using the patched cdparanoia package
# lines.append("Fill up missing offset samples with silence: Yes")
lines.append(" Gap detection: cdrdao %s" % ripResult.cdrdaoVersion)
if ripResult.isCdr:
isCdr = "Yes"
else:
isCdr = "No"
lines.append(" CD-R detected: %s" % isCdr)
lines.append("")
# CD metadata

View File

@@ -93,6 +93,7 @@ class RipResult:
offset = 0
overread = None
isCdr = None
logger = None
table = None
artist = None