From 6e2e58a373892bd235808e6af2f1fe40f452c5d4 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 3 May 2009 19:18:26 +0000 Subject: [PATCH] * morituri/image/cue.py: * morituri/test/test_image_cue.py: Add dumping of .cue files. --- ChangeLog | 6 ++++++ morituri/image/cue.py | 27 +++++++++++++++++++++++++++ morituri/test/test_image_cue.py | 23 +++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/ChangeLog b/ChangeLog index 198fc41..a7d6baf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-05-03 Thomas Vander Stichele + + * morituri/image/cue.py: + * morituri/test/test_image_cue.py: + Add dumping of .cue files. + 2009-05-03 Thomas Vander Stichele * morituri/program/cdparanoia.py: diff --git a/morituri/image/cue.py b/morituri/image/cue.py index c4162d8..5e1ba7b 100644 --- a/morituri/image/cue.py +++ b/morituri/image/cue.py @@ -29,6 +29,8 @@ See http://digitalx.org/cuesheetsyntax.php import os import re +from morituri.common import common + _REM_RE = re.compile("^REM\s(\w+)\s(.*)$") _PERFORMER_RE = re.compile("^PERFORMER\s(.*)$") _TITLE_RE = re.compile("^TITLE\s(.*)$") @@ -122,6 +124,31 @@ class Cue: # print 'index %d, offset %d of track %r' % (indexNumber, frameOffset, currentTrack) continue + def dump(self): + """ + Dump our internal representation to a .cue file content. + """ + lines = [] + currentFile = None + + for i, track in enumerate(self.tracks): + indexes = track._indexes.keys() + indexes.sort() + index, file = track._indexes[indexes[0]] + if file != currentFile: + lines.append('FILE "%s" WAVE' % file.path) + currentFile = file + lines.append(" TRACK %02d %s" % (i + 1, 'AUDIO')) + for index in indexes: + (offset, file) = track._indexes[index] + if file != currentFile: + lines.append('FILE "%s" WAVE' % file.path) + lines.append( + " INDEX %02d %s" % (index, common.framesToMSF(offset))) + + lines.append("") + return "\n".join(lines) + def message(self, number, message): """ Add a message about a given line in the cue file. diff --git a/morituri/test/test_image_cue.py b/morituri/test/test_image_cue.py index d05553f..66598ba 100644 --- a/morituri/test/test_image_cue.py +++ b/morituri/test/test_image_cue.py @@ -2,6 +2,7 @@ # vi:si:et:sw=4:sts=4:ts=4 import os +import tempfile import unittest from morituri.image import cue @@ -44,3 +45,25 @@ class KanyeMixedTestCase(unittest.TestCase): def testGetTrackLength(self): t = self.cue.tracks[0] self.assertEquals(self.cue.getTrackLength(t), -1) + + +class WriteCueTestCase(unittest.TestCase): + def testWrite(self): + fd, path = tempfile.mkstemp(suffix='morituri.test.cue') + os.close(fd) + c = cue.Cue(path) + + f = cue.File('track01.wav', 'AUDIO') + t = cue.Track(1) + t.index(1, 0, f) + c.tracks.append(t) + + t = cue.Track(2) + t.index(0, 1000, f) + f = cue.File('track02.wav', 'AUDIO') + t.index(1, 1100, f) + c.tracks.append(t) + + print c.dump() + +