* morituri/image/image.py:
Add an object to parse the response of AccurateRip. * morituri/test/test_image_image.py: * morituri/test/dBAR-011-0010e284-009228a3-9809ff0b.bin (added): Add a test for it, based on my Kings Of Leon CD.
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
2009-04-13 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/image/image.py:
|
||||
Add an object to parse the response of AccurateRip.
|
||||
* morituri/test/test_image_image.py:
|
||||
* morituri/test/dBAR-011-0010e284-009228a3-9809ff0b.bin (added):
|
||||
Add a test for it, based on my Kings Of Leon CD.
|
||||
|
||||
2009-04-13 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/image/image.py:
|
||||
|
||||
@@ -25,6 +25,7 @@ Wrap on-disk CD images based on the .cue file.
|
||||
"""
|
||||
|
||||
import os
|
||||
import struct
|
||||
|
||||
import gst
|
||||
|
||||
@@ -307,3 +308,32 @@ class ImageVerifyTask(MultiTask):
|
||||
self.lengths[trackIndex] = end - offset
|
||||
|
||||
MultiTask.stop(self)
|
||||
|
||||
class AccurateRipResponse(object):
|
||||
"""
|
||||
I represent the response of the AccurateRip online database.
|
||||
"""
|
||||
|
||||
trackCount = None
|
||||
discId1 = ""
|
||||
discId2 = ""
|
||||
cddbDiscId = ""
|
||||
confidences = None
|
||||
crcs = None
|
||||
|
||||
def __init__(self, data):
|
||||
self.trackCount = struct.unpack("B", data[0])[0]
|
||||
self.discId1 = "%08x" % struct.unpack("<L", data[1:5])[0]
|
||||
self.discId2 = "%08x" % struct.unpack("<L", data[5:9])[0]
|
||||
self.cddbDiscId = "%08x" % struct.unpack("<L", data[9:13])[0]
|
||||
|
||||
self.confidences = []
|
||||
self.crcs = []
|
||||
|
||||
pos = 13
|
||||
for i in range(self.trackCount):
|
||||
confidence = struct.unpack("B", data[pos])[0]
|
||||
crc = "%08x" % struct.unpack("<L", data[pos + 1:pos + 5])[0]
|
||||
pos += 9
|
||||
self.confidences.append(confidence)
|
||||
self.crcs.append(crc)
|
||||
|
||||
BIN
morituri/test/dBAR-011-0010e284-009228a3-9809ff0b.bin
Normal file
BIN
morituri/test/dBAR-011-0010e284-009228a3-9809ff0b.bin
Normal file
Binary file not shown.
@@ -82,6 +82,20 @@ class AudioLengthTestCase(unittest.TestCase):
|
||||
runner = task.SyncRunner()
|
||||
runner.run(t, verbose=False)
|
||||
self.assertEquals(t.length, 5880)
|
||||
|
||||
|
||||
class AccurateRipResponseTestCase(unittest.TestCase):
|
||||
def testResponse(self):
|
||||
path = os.path.join(os.path.dirname(__file__),
|
||||
'dBAR-011-0010e284-009228a3-9809ff0b.bin')
|
||||
data = open(path, "rb").read()
|
||||
response = image.AccurateRipResponse(data)
|
||||
|
||||
self.assertEquals(response.trackCount, 11)
|
||||
self.assertEquals(response.discId1, "0010e284")
|
||||
self.assertEquals(response.discId2, "009228a3")
|
||||
self.assertEquals(response.cddbDiscId, "9809ff0b")
|
||||
|
||||
for i in range(11):
|
||||
self.assertEquals(response.confidences[i], 35)
|
||||
self.assertEquals(response.crcs[0], "beea32c8")
|
||||
self.assertEquals(response.crcs[10], "acee98ca")
|
||||
|
||||
Reference in New Issue
Block a user