diff --git a/ChangeLog b/ChangeLog index 0559922..db2878e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-05-23 Thomas Vander Stichele + + * morituri/common/accurip.py: + * morituri/image/image.py: + * morituri/test/Makefile.am: + * morituri/test/test_image_image.py: + * morituri/test/test_common_accurip.py (added): + Move accuraterip stuff to the accurip module. + Move/create new test file. + 2009-05-23 Thomas Vander Stichele * morituri/rip/Makefile.am: diff --git a/morituri/common/accurip.py b/morituri/common/accurip.py index 7b9c16b..9f94baf 100644 --- a/morituri/common/accurip.py +++ b/morituri/common/accurip.py @@ -1,4 +1,4 @@ -# -*- Mode: Python -*- +# -*- Mode: Python; test-case-name: morituri.test.test_common_accurip -*- # vi:si:et:sw=4:sts=4:ts=4 # Morituri - for those about to RIP @@ -21,11 +21,11 @@ # along with morituri. If not, see . import os +import strct import urlparse import urllib2 from morituri.common import log -from morituri.image import image _CACHE_DIR = os.path.join(os.path.expanduser('~'), '.morituri', 'cache') @@ -56,7 +56,7 @@ class AccuCache(log.Loggable): data = self._read(url) - return image.getAccurateRipResponses(data) + return getAccurateRipResponses(data) def download(self, url): # FIXME: download url as a task too @@ -89,4 +89,44 @@ class AccuCache(log.Loggable): data = handle.read() handle.close() return data - + +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. + """ + + trackCount = None + discId1 = "" + discId2 = "" + cddbDiscId = "" + confidences = None + checksums = None + + def __init__(self, data): + self.trackCount = struct.unpack("B", data[0])[0] + self.discId1 = "%08x" % struct.unpack("