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

Add config file option to set cdparanoia command #571

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ defeats_cache = True ; whether the drive is capable of defeating the audio cac
read_offset = 6 ; drive read offset in positive/negative frames (no leading +)
# do not edit the values 'vendor', 'model', and 'release'; they are used by whipper to match the drive

[drive:PIONEER%20%3ABD-RW%20%20%20BDR-209D%3A1.10]
defeats_cache = True
read_offset = 667
cdparanoia = cdparanoia ; cdparanoia executable to use. Default is cd-paranoia
; cd-paranoia has a bug that makes drives with large read_offset
; unusable, see https://github.com/whipper-team/whipper/issues/234


# command line defaults for `whipper cd rip`
[whipper.cd.rip]
unknown = True
Expand Down
16 changes: 13 additions & 3 deletions whipper/command/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,26 @@ def do(self):

# result

self.program.result.cdrdaoVersion = cdrdao.version()
self.program.result.cdparanoiaVersion = \
cdparanoia.getCdParanoiaVersion()

info = drive.getDeviceInfo(self.device)
if info:
try:
cdparanoia_cmd = self.config.getCdparanoia(*info)
logger.info("using configured cdparanoia command %s", cdparanoia_cmd)
cdparanoia.setCdParanoiaCommand(cdparanoia_cmd)
except KeyError:
pass

try:
self.program.result.cdparanoiaDefeatsCache = \
self.config.getDefeatsCache(*info)
except KeyError as e:
logger.debug('got key error: %r', (e, ))

self.program.result.cdrdaoVersion = cdrdao.version()
self.program.result.cdparanoiaVersion = \
cdparanoia.getCdParanoiaVersion()

self.program.result.artist = self.program.metadata \
and self.program.metadata.artist \
or 'Unknown Artist'
Expand Down
5 changes: 5 additions & 0 deletions whipper/command/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
from whipper.common import common, directory, config
from whipper.extern.task import task
from whipper.program.utils import eject_device
from whipper.program import cdparanoia

import logging
logger = logging.getLogger(__name__)


def main():
cdparanoia_cmd = config.Config().get('main', 'cdparanoia')
if cdparanoia_cmd:
cdparanoia.setCdParanoiaCommand(cdparanoia_cmd)

server = config.Config().get_musicbrainz_server()
https_enabled = server['scheme'] == 'https'
try:
Expand Down
4 changes: 4 additions & 0 deletions whipper/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def getDefeatsCache(self, vendor, model, release):
option = self._getDriveOption(vendor, model, release, 'defeats_cache')
return option == 'True'

def getCdparanoia(self, vendor, model, release):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def getCdparanoia(self, vendor, model, release):
def getCdParanoia(self, vendor, model, release):

Same casing as other instances.

"""Get the cdparanoia command for the given drive."""
return self._getDriveOption(vendor, model, release, 'cdparanoia')

def _findDriveSection(self, vendor, model, release):
for name in self._parser.sections():
if not name.startswith('drive:'):
Expand Down
15 changes: 11 additions & 4 deletions whipper/program/cdparanoia.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import logging
logger = logging.getLogger(__name__)

cdparanoia = 'cd-paranoia'

class FileSizeError(Exception):
"""The given path does not have the expected size."""
Expand Down Expand Up @@ -69,6 +70,12 @@ class ChecksumException(Exception):

_ERROR_RE = re.compile("^scsi_read error:")


def setCdParanoiaCommand(cmd):
global cdparanoia
cdparanoia = cmd


# from reading cdparanoia source code, it looks like offset is reported in
# number of single-channel samples, ie. 2 bytes (word) per unit, and absolute

Expand Down Expand Up @@ -271,10 +278,10 @@ def start(self, runner):

bufsize = 1024
if self._overread:
argv = ["cd-paranoia", "--stderr-progress",
argv = [cdparanoia, "--stderr-progress",
"--sample-offset=%d" % self._offset, "--force-overread", ]
else:
argv = ["cd-paranoia", "--stderr-progress",
argv = [cdparanoia, "--stderr-progress",
"--sample-offset=%d" % self._offset, ]
if self._device:
argv.extend(["--force-cdrom-device", self._device, ])
Expand Down Expand Up @@ -573,7 +580,7 @@ def stop(self):

def getCdParanoiaVersion():
getter = common.VersionGetter('cd-paranoia',
["cd-paranoia", "-V"],
[cdparanoia, "-V"],
_VERSION_RE,
"%(version)s %(release)s")

Expand All @@ -599,7 +606,7 @@ class AnalyzeTask(ctask.PopenTask):
def __init__(self, device=None):
# cdparanoia -A *always* writes cdparanoia.log
self.cwd = tempfile.mkdtemp(suffix='.whipper.cache')
self.command = ['cd-paranoia', '-A']
self.command = [cdparanoia, '-A']
if device:
self.command += ['-d', device]

Expand Down