* morituri/image/cue.py:

* morituri/test/test_image_cue.py:
	  Add dumping of .cue files.
This commit is contained in:
Thomas Vander Stichele
2009-05-03 19:18:26 +00:00
parent bdf1d0b90c
commit 6e2e58a373
3 changed files with 56 additions and 0 deletions

View File

@@ -1,3 +1,9 @@
2009-05-03 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/image/cue.py:
* morituri/test/test_image_cue.py:
Add dumping of .cue files.
2009-05-03 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/program/cdparanoia.py:

View File

@@ -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.

View File

@@ -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()