Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect and handle CD-R discs #154

Merged
merged 8 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions whipper/command/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ def do(self):
"--unknown not passed")
return -1

self.program.result.isCdr = cdrdao.DetectCdr(self.device)
if self.program.result.isCdr and \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if you break it like this:

        if (self.program.result.isCdr and
                not getattr(self.options, 'cdr', False)):

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else is OK

Copy link
Contributor Author

@gorgobacka gorgobacka Jun 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it looks better. Updated.

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
Expand Down Expand Up @@ -300,6 +307,11 @@ def add_arguments(self):
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(
Expand Down
13 changes: 13 additions & 0 deletions whipper/program/cdrdao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions whipper/result/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def logRip(self, ripResult, epoch):
# 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
Expand Down
1 change: 1 addition & 0 deletions whipper/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class RipResult:

offset = 0
overread = None
isCdr = None
logger = None
table = None
artist = None
Expand Down