diff --git a/ChangeLog b/ChangeLog index 73ac580..43d2857 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-05-15 Thomas Vander Stichele + + * morituri/image/toc.py: + Calculate the leadout from the sum of the track lengths. + * morituri/test/breeders.cue: + * morituri/test/cure.cue: + Adapt expected results for DISCID. + * morituri/image/table.py: + Add an assert for hasTOC() when doing .cue() + * morituri/test/test_image_toc.py: + * morituri/test/test_image_cue.py: + absolutize before cue() + 2009-05-15 Thomas Vander Stichele * morituri/image/table.py: diff --git a/morituri/image/table.py b/morituri/image/table.py index 1f08055..2847067 100644 --- a/morituri/image/table.py +++ b/morituri/image/table.py @@ -334,10 +334,8 @@ class IndexTable(object, log.Loggable): if key not in main and self.cdtext.has_key(key): lines.append(" %s %s" % (key, track.cdtext[key])) - if self.hasTOC(): - lines.append('REM DISCID %s' % self.getCDDBDiscId().upper()) - else: - self.warning("Cannot write disc id, not a TOC") + assert self.hasTOC(), "Table does not represent a full CD TOC" + lines.append('REM DISCID %s' % self.getCDDBDiscId().upper()) lines.append('REM COMMENT "%s"' % program) if self.catalog: diff --git a/morituri/image/toc.py b/morituri/image/toc.py index 52e887b..a879b63 100644 --- a/morituri/image/toc.py +++ b/morituri/image/toc.py @@ -85,6 +85,7 @@ class TocFile(object, log.Loggable): indexNumber = 0 currentOffset = 0 # running absolute offset of where each track starts currentLength = 0 # accrued during TRACK record parsing, current track + totalLength = 0 # accrued during TRACK record parsing, total disc pregapLength = 0 # length of the pre-gap, current track @@ -134,6 +135,7 @@ class TocFile(object, log.Loggable): trackNumber += 1 currentOffset += currentLength + totalLength += currentLength currentLength = 0 indexNumber = 1 trackMode = m.group('mode') @@ -217,6 +219,10 @@ class TocFile(object, log.Loggable): self.debug('track %d, added index %r', currentTrack.number, currentTrack.getIndex(1)) + # totalLength was added up to the penultimate track + self.table.leadout = totalLength + currentLength + self.debug('leadout: %r', self.table.leadout) + def message(self, number, message): """ Add a message about a given line in the cue file. diff --git a/morituri/test/breeders.cue b/morituri/test/breeders.cue index 2db081b..457f913 100644 --- a/morituri/test/breeders.cue +++ b/morituri/test/breeders.cue @@ -1,3 +1,4 @@ +REM DISCID BE08990D REM COMMENT "Morituri" CATALOG 0652637280326 PERFORMER "THE BREEDERS" diff --git a/morituri/test/cure.cue b/morituri/test/cure.cue index 52d211a..834b8e2 100644 --- a/morituri/test/cure.cue +++ b/morituri/test/cure.cue @@ -1,3 +1,4 @@ +REM DISCID B90C650D REM COMMENT "Morituri" CATALOG 0602517642256 FILE "data.wav" WAVE diff --git a/morituri/test/test_image_cue.py b/morituri/test/test_image_cue.py index fbe8579..6d00df9 100644 --- a/morituri/test/test_image_cue.py +++ b/morituri/test/test_image_cue.py @@ -65,8 +65,11 @@ class WriteCueFileTestCase(unittest.TestCase): t.index(0, path='track01.wav', relative=1000, counter=1) t.index(1, path='track02.wav', relative=0, counter=2) it.tracks.append(t) + it.absolutize() + it.leadout = 2000 - self.assertEquals(it.cue(), """REM COMMENT "Morituri" + self.assertEquals(it.cue(), """REM DISCID 04001A02 +REM COMMENT "Morituri" FILE "track01.wav" WAVE TRACK 01 AUDIO INDEX 01 00:00:00 diff --git a/morituri/test/test_image_toc.py b/morituri/test/test_image_toc.py index b5047b5..3323a46 100644 --- a/morituri/test/test_image_toc.py +++ b/morituri/test/test_image_toc.py @@ -6,6 +6,8 @@ import unittest from morituri.image import toc +from morituri.test import common + class CureTestCase(unittest.TestCase): def setUp(self): self.toc = toc.TocFile(os.path.join(os.path.dirname(__file__), @@ -81,6 +83,7 @@ class CureTestCase(unittest.TestCase): self._assertRelative(2, 1, None) def testConvertCue(self): + self.toc.table.absolutize() cue = self.toc.table.cue() ref = open(os.path.join(os.path.dirname(__file__), 'cure.cue')).read() self.assertEquals(cue, ref) @@ -127,6 +130,9 @@ class BreedersTestCase(unittest.TestCase): self.assertEquals(cdt['TITLE'], 'OVERGLAZED') def testConvertCue(self): + self.failIf(self.toc.table.hasTOC()) + self.toc.table.absolutize() + self.failUnless(self.toc.table.hasTOC()) cue = self.toc.table.cue() ref = open(os.path.join(os.path.dirname(__file__), 'breeders.cue')).read()