* morituri/program/cdparanoia.py:
Add table to __init__, so we can correctly calculate cdparanoia's strange ripping regions. * examples/ARcalibrate.py: When we found a positive match on a first track, match all the other tracks too for confirmation.
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
2009-05-03 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/program/cdparanoia.py:
|
||||
Add table to __init__, so we can correctly calculate cdparanoia's
|
||||
strange ripping regions.
|
||||
* examples/ARcalibrate.py:
|
||||
When we found a positive match on a first track, match all the other
|
||||
tracks too for confirmation.
|
||||
|
||||
2009-05-03 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/common/taskgtk.py:
|
||||
|
||||
@@ -55,6 +55,26 @@ def climain(runner, taskk):
|
||||
runner.run(taskk)
|
||||
|
||||
|
||||
def arcs(runner, function, table, track, offset):
|
||||
# rips the track with the given offset, return the arcs checksum
|
||||
print 'ripping track %r with offset %d' % (track, offset)
|
||||
|
||||
fd, path = tempfile.mkstemp(suffix='.track%02d.offset%d.morituri.wav' % (
|
||||
track, offset))
|
||||
os.close(fd)
|
||||
|
||||
track = table.tracks[track - 1]
|
||||
t = cdparanoia.ReadTrackTask(path, table, track.start, track.end, offset)
|
||||
t.description = 'Ripping with offset %d' % offset
|
||||
function(runner, t)
|
||||
|
||||
t = checksum.AccurateRipChecksumTask(path, trackNumber=track,
|
||||
trackCount=len(table.tracks))
|
||||
function(runner, t)
|
||||
|
||||
# os.unlink(path)
|
||||
return "%08x" % t.checksum
|
||||
|
||||
def main(argv):
|
||||
parser = optparse.OptionParser()
|
||||
|
||||
@@ -122,30 +142,43 @@ def main(argv):
|
||||
print "AccurateRip response discid different: %s" % \
|
||||
responses[0].cddbDiscId
|
||||
|
||||
response = None
|
||||
|
||||
# now rip the first track at various offsets, calculating AccurateRip
|
||||
# CRC, and matching it against the retrieved ones
|
||||
for offset in offsets:
|
||||
fd, path = tempfile.mkstemp(suffix='.morituri')
|
||||
os.close(fd)
|
||||
|
||||
print 'ripping track 1 with offset', offset
|
||||
track = table.tracks[0]
|
||||
t = cdparanoia.ReadTrackTask(path, track.start, track.end, offset)
|
||||
t.description = 'Ripping with offset %d' % offset
|
||||
function(runner, t)
|
||||
|
||||
t = checksum.AccurateRipChecksumTask(path, trackNumber=1,
|
||||
trackCount = len(table.tracks))
|
||||
function(runner, t)
|
||||
arcs = "%08x" % t.checksum
|
||||
print 'AR checksum calculated: %s' % arcs
|
||||
|
||||
|
||||
def match(archecksum, track, responses):
|
||||
for i, r in enumerate(responses):
|
||||
if arcs == r.checksums[0]:
|
||||
print 'MATCHED against response %d' % i
|
||||
print 'offset of device is', offset
|
||||
if archecksum == r.checksums[track - 1]:
|
||||
return archecksum, i
|
||||
|
||||
return None, None
|
||||
|
||||
for offset in offsets:
|
||||
archecksum = arcs(runner, function, table, 1, offset)
|
||||
|
||||
print 'AR checksum calculated: %s' % archecksum
|
||||
|
||||
c, i = match(archecksum, 1, responses)
|
||||
if c:
|
||||
count = 1
|
||||
print 'MATCHED against response %d' % i
|
||||
print 'offset of device is likely', offset
|
||||
# now try and rip all other tracks as well
|
||||
for track in range(2, len(table.tracks) + 1):
|
||||
archecksum = arcs(runner, function, table, track, offset)
|
||||
c, i = match(archecksum, track, responses)
|
||||
if c:
|
||||
print 'MATCHED track %d against response %d' % (track, i)
|
||||
count += 1
|
||||
|
||||
if count == len(table.tracks):
|
||||
print 'OFFSET of device is', offset
|
||||
return
|
||||
else:
|
||||
print 'not all tracks matched, continuing'
|
||||
|
||||
print 'no matching offset found.'
|
||||
|
||||
|
||||
|
||||
|
||||
main(sys.argv)
|
||||
|
||||
@@ -62,20 +62,23 @@ class ReadTrackTask(task.Task):
|
||||
description = "Reading Track..."
|
||||
|
||||
|
||||
def __init__(self, path, start, stop, offset=0):
|
||||
def __init__(self, path, table, start, stop, offset=0):
|
||||
"""
|
||||
Read the given track.
|
||||
|
||||
@param path: where to store the ripped track
|
||||
@type path: str
|
||||
@param start: first frame to rip
|
||||
@type start: int
|
||||
@param table: table of contents of CD
|
||||
@type table: L{table.Table}
|
||||
@param start: first frame to rip, in cdparanoia notation
|
||||
@type start: str
|
||||
@param stop: last frame to rip (inclusive)
|
||||
@type stop: int
|
||||
@param offset: read offset, in samples
|
||||
@type offset: int
|
||||
"""
|
||||
self.path = path
|
||||
self._table = table
|
||||
self._start = start
|
||||
self._stop = stop
|
||||
self._offset = offset
|
||||
@@ -87,13 +90,32 @@ class ReadTrackTask(task.Task):
|
||||
def start(self, runner):
|
||||
task.Task.start(self, runner)
|
||||
|
||||
# find on which track the range starts and stops
|
||||
startTrack = 0
|
||||
startOffset = 0
|
||||
stopTrack = 0
|
||||
stopOffset = 0
|
||||
|
||||
for i, t in enumerate(self._table.tracks):
|
||||
if t.start <= self._start:
|
||||
startTrack = i + 1
|
||||
startOffset = self._start - t.start
|
||||
if t.end <= self._stop:
|
||||
stopTrack = i + 1
|
||||
stopOffset = self._stop - t.start
|
||||
|
||||
self.debug('Ripping from %d to %d (inclusive)', self._start, self._stop)
|
||||
self.debug('Starting at track %d, offset %d', startTrack, startOffset)
|
||||
self.debug('Stopping at track %d, offset %d', stopTrack, stopOffset)
|
||||
|
||||
bufsize = 1024
|
||||
argv = ["cdparanoia",
|
||||
"--sample-offset=%d" % self._offset,
|
||||
"--stderr-progress",
|
||||
"[%s]-[%s]" % (
|
||||
common.framesToHMSF(self._start),
|
||||
common.framesToHMSF(self._stop)), self.path]
|
||||
"%d[%s]-%d[%s]" % (
|
||||
startTrack, common.framesToHMSF(startOffset),
|
||||
stopTrack, common.framesToHMSF(stopOffset)),
|
||||
self.path]
|
||||
self.debug('Running %s' % (" ".join(argv), ))
|
||||
self._popen = asyncsub.Popen(argv,
|
||||
bufsize=bufsize,
|
||||
|
||||
Reference in New Issue
Block a user