* 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.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
|||||||
|
2009-05-23 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||||
|
|
||||||
|
* 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 <thomas at apestaart dot org>
|
2009-05-23 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||||
|
|
||||||
* morituri/rip/Makefile.am:
|
* morituri/rip/Makefile.am:
|
||||||
|
|||||||
@@ -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
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
|
||||||
# Morituri - for those about to RIP
|
# Morituri - for those about to RIP
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
# along with morituri. If not, see <http://www.gnu.org/licenses/>.
|
# along with morituri. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import strct
|
||||||
import urlparse
|
import urlparse
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
from morituri.common import log
|
from morituri.common import log
|
||||||
from morituri.image import image
|
|
||||||
|
|
||||||
_CACHE_DIR = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
|
_CACHE_DIR = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ class AccuCache(log.Loggable):
|
|||||||
|
|
||||||
data = self._read(url)
|
data = self._read(url)
|
||||||
|
|
||||||
return image.getAccurateRipResponses(data)
|
return getAccurateRipResponses(data)
|
||||||
|
|
||||||
def download(self, url):
|
def download(self, url):
|
||||||
# FIXME: download url as a task too
|
# FIXME: download url as a task too
|
||||||
@@ -89,4 +89,44 @@ class AccuCache(log.Loggable):
|
|||||||
data = handle.read()
|
data = handle.read()
|
||||||
handle.close()
|
handle.close()
|
||||||
return data
|
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("<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.checksums = []
|
||||||
|
|
||||||
|
pos = 13
|
||||||
|
for _ in range(self.trackCount):
|
||||||
|
confidence = struct.unpack("B", data[pos])[0]
|
||||||
|
checksum = "%08x" % struct.unpack("<L", data[pos + 1:pos + 5])[0]
|
||||||
|
pos += 9
|
||||||
|
self.confidences.append(confidence)
|
||||||
|
self.checksums.append(checksum)
|
||||||
|
|||||||
@@ -197,45 +197,3 @@ class ImageVerifyTask(task.MultiSeparateTask):
|
|||||||
self.lengths[trackIndex] = end - index.relative
|
self.lengths[trackIndex] = end - index.relative
|
||||||
|
|
||||||
task.MultiSeparateTask.stop(self)
|
task.MultiSeparateTask.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.
|
|
||||||
"""
|
|
||||||
|
|
||||||
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("<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.checksums = []
|
|
||||||
|
|
||||||
pos = 13
|
|
||||||
for _ in range(self.trackCount):
|
|
||||||
confidence = struct.unpack("B", data[pos])[0]
|
|
||||||
checksum = "%08x" % struct.unpack("<L", data[pos + 1:pos + 5])[0]
|
|
||||||
pos += 9
|
|
||||||
self.confidences.append(confidence)
|
|
||||||
self.checksums.append(checksum)
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ CLEANFILES = *.py{c,o}
|
|||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
__init__.py \
|
__init__.py \
|
||||||
common.py \
|
common.py \
|
||||||
|
test_common_accurip.py \
|
||||||
test_common_renamer.py \
|
test_common_renamer.py \
|
||||||
test_image_cue.py \
|
test_image_cue.py \
|
||||||
test_image_image.py \
|
test_image_image.py \
|
||||||
|
|||||||
29
morituri/test/test_common_accurip.py
Normal file
29
morituri/test/test_common_accurip.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# -*- Mode: Python; test-case-name: morituri.test.test_common_accurip -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from morituri.common import accurip, common
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
responses = accurip.getAccurateRipResponses(data)
|
||||||
|
self.assertEquals(len(responses), 3)
|
||||||
|
|
||||||
|
|
||||||
|
response = responses[0]
|
||||||
|
|
||||||
|
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.checksums[0], "beea32c8")
|
||||||
|
self.assertEquals(response.checksums[10], "acee98ca")
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- Mode: Python; test-case-name: morituri.test.test_image_cue -*-
|
# -*- Mode: Python; test-case-name: morituri.test.test_image_image -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -80,25 +80,3 @@ class AudioLengthTestCase(unittest.TestCase):
|
|||||||
runner = task.SyncRunner()
|
runner = task.SyncRunner()
|
||||||
runner.run(t, verbose=False)
|
runner.run(t, verbose=False)
|
||||||
self.assertEquals(t.length, 10 * common.SAMPLES_PER_FRAME)
|
self.assertEquals(t.length, 10 * common.SAMPLES_PER_FRAME)
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
responses = image.getAccurateRipResponses(data)
|
|
||||||
self.assertEquals(len(responses), 3)
|
|
||||||
|
|
||||||
|
|
||||||
response = responses[0]
|
|
||||||
|
|
||||||
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.checksums[0], "beea32c8")
|
|
||||||
self.assertEquals(response.checksums[10], "acee98ca")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user