From 362d835829d82c27e8a0ad94598edefc6a8e9af5 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 13 Apr 2009 18:13:32 +0000 Subject: [PATCH] * 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. --- ChangeLog | 8 +++++ morituri/image/image.py | 30 ++++++++++++++++++ .../dBAR-011-0010e284-009228a3-9809ff0b.bin | Bin 0 -> 336 bytes morituri/test/test_image_image.py | 16 +++++++++- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 morituri/test/dBAR-011-0010e284-009228a3-9809ff0b.bin diff --git a/ChangeLog b/ChangeLog index d1302ff..848bf76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-04-13 Thomas Vander Stichele + + * 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 * morituri/image/image.py: diff --git a/morituri/image/image.py b/morituri/image/image.py index 45f5193..bdd36e8 100644 --- a/morituri/image/image.py +++ b/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("T>fvOfUA+S@|`ntrC-;}C@SBX&8Q!B=ctpir*_Zw@)O;sm1R}0SudP-LrVF? zvov6rl^fYUrujQ;{^zgRz{K?P-sQSCES$TT%nmhlU*FeZ&y?bF zzgsQd*PQ9qpC8_bDt?wR#kJj1=jr~shDqc9rG!@hB`r*f9@am%?A0-5Y7RIug`Z73 zjj6|C^_SGO-{YB5*fdSwuH$@&VxO2+W9xc}g(j?G516(~n@@kKC&svEPwkhUBL-q3 zE1$Zmv~BJXo4VP6q%yS(IM@ literal 0 HcmV?d00001 diff --git a/morituri/test/test_image_image.py b/morituri/test/test_image_image.py index 9a872f5..d803fca 100644 --- a/morituri/test/test_image_image.py +++ b/morituri/test/test_image_image.py @@ -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")