* morituri/image/image.py:
* morituri/test/test_image_image.py: AccurateRip binary files actually contain multiple responses, so parse all of them. * examples/ARcue.py: Handle case of not having a response, and having multiple responses.
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
2009-04-15 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/image/image.py:
|
||||
* morituri/test/test_image_image.py:
|
||||
AccurateRip binary files actually contain multiple responses, so
|
||||
parse all of them.
|
||||
* examples/ARcue.py:
|
||||
Handle case of not having a response, and having multiple responses.
|
||||
|
||||
2009-04-14 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/common/crc.py:
|
||||
|
||||
@@ -81,21 +81,61 @@ def main(argv):
|
||||
print "AccurateRip URL", url
|
||||
|
||||
# FIXME: download url as a task too
|
||||
import urllib
|
||||
(filename, headers) = urllib.urlretrieve(url)
|
||||
data = open(filename, 'rb').read()
|
||||
os.unlink(filename)
|
||||
response = image.AccurateRipResponse(data)
|
||||
responses = []
|
||||
import urllib2
|
||||
try:
|
||||
handle = urllib2.urlopen(url)
|
||||
data = handle.read()
|
||||
responses = image.getAccurateRipResponses(data)
|
||||
except urllib2.HTTPError, e:
|
||||
if e.code == 404:
|
||||
print 'Album not found in AccurateRip database'
|
||||
else:
|
||||
raise
|
||||
|
||||
if responses:
|
||||
print '%d AccurateRip reponses found' % len(responses)
|
||||
|
||||
if responses[0].cddbDiscId != cueImage.getCDDBDiscId():
|
||||
print "AccurateRip response discid different: %s" % \
|
||||
responses[0].cddbDiscId
|
||||
|
||||
function(runner, verifytask)
|
||||
function(runner, cuetask)
|
||||
|
||||
response = None
|
||||
|
||||
for i, crc in enumerate(cuetask.crcs):
|
||||
status = ' rip accurate '
|
||||
if "%08x" % crc != response.crcs[i]:
|
||||
status = '** rip not accurate **'
|
||||
print "Track %2d: %s (confidence %3d) mine [%08x] AR [%s]" % (
|
||||
i + 1, status, response.confidences[i], crc, response.crcs[i])
|
||||
status = '** rip not accurate **'
|
||||
|
||||
confidence = None
|
||||
arcrc = None
|
||||
|
||||
for j, r in enumerate(responses):
|
||||
if "%08x" % crc == r.crcs[i]:
|
||||
if not response:
|
||||
response = r
|
||||
else:
|
||||
assert r == response, \
|
||||
"CRC %s for %d matches wrong response %d, crc %s" % (
|
||||
crc, i + 1, j + 1, response.crcs[i])
|
||||
status = ' rip accurate '
|
||||
arcrc = crc
|
||||
confidence = response.confidences[i]
|
||||
|
||||
c = "(not found)"
|
||||
ar = ""
|
||||
if responses:
|
||||
maxConfidence = max(r.confidences[i] for r in responses)
|
||||
|
||||
c = "(confidence %3d)" % maxConfidence
|
||||
if confidence is not None:
|
||||
if confidence < maxConfidence:
|
||||
c = "(confidence %3d of %3d)" % (confidence, maxConfidence)
|
||||
|
||||
ar = " AR [%s]" % response.crcs[i]
|
||||
print "Track %2d: %s %s mine [%08x] %s" % (
|
||||
i + 1, status, c, crc, ar)
|
||||
|
||||
|
||||
main(sys.argv)
|
||||
|
||||
@@ -319,6 +319,19 @@ class ImageVerifyTask(MultiTask):
|
||||
|
||||
MultiTask.stop(self)
|
||||
|
||||
# FIXME: move this method to a different module ?
|
||||
def getAccurateRipResponses(data):
|
||||
ret = []
|
||||
|
||||
while data:
|
||||
trackCount = struct.unpack("B", data[0])[0]
|
||||
bytes = 1 + 12 + trackCount * (1 + 8)
|
||||
|
||||
ret.append(AccurateRipResponse(data[:bytes]))
|
||||
data = data[bytes:]
|
||||
|
||||
return ret
|
||||
|
||||
class AccurateRipResponse(object):
|
||||
"""
|
||||
I represent the response of the AccurateRip online database.
|
||||
|
||||
@@ -88,7 +88,12 @@ class AccurateRipResponseTestCase(unittest.TestCase):
|
||||
path = os.path.join(os.path.dirname(__file__),
|
||||
'dBAR-011-0010e284-009228a3-9809ff0b.bin')
|
||||
data = open(path, "rb").read()
|
||||
response = image.AccurateRipResponse(data)
|
||||
|
||||
responses = image.getAccurateRipResponses(data)
|
||||
self.assertEquals(len(responses), 3)
|
||||
|
||||
|
||||
response = responses[0]
|
||||
|
||||
self.assertEquals(response.trackCount, 11)
|
||||
self.assertEquals(response.discId1, "0010e284")
|
||||
|
||||
Reference in New Issue
Block a user