* morituri/image/image.py:

* morituri/test/test_image_image.py:
	  Add a task for calculating frame length of an audio file.
	  Add a test for it.
This commit is contained in:
Thomas Vander Stichele
2009-04-12 10:20:14 +00:00
parent b7eb47325e
commit 27fd2f16e6
3 changed files with 60 additions and 0 deletions

View File

@@ -1,3 +1,10 @@
2009-04-12 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/image/image.py:
* morituri/test/test_image_image.py:
Add a task for calculating frame length of an audio file.
Add a test for it.
2009-04-12 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/common/task.py:

View File

@@ -26,6 +26,8 @@ Wrap on-disk CD images based on the .cue file.
import os
import gst
from morituri.common import task, crc
from morituri.image import cue
@@ -120,3 +122,45 @@ class AudioRipCRCTask(task.Task):
# pick another
self.start(self.runner)
class AudioLengthTask(task.Task):
"""
I calculate the length of a track in audio frames.
@ivar length: length of the decoded audio file, in audio frames.
"""
length = None
def __init__(self, path):
self._path = path
def debug(self, *args, **kwargs):
return
print args, kwargs
def start(self, runner):
task.Task.start(self, runner)
self._pipeline = gst.parse_launch('''
filesrc location="%s" !
decodebin ! audio/x-raw-int !
fakesink name=sink''' % self._path)
self.debug('pausing')
self._pipeline.set_state(gst.STATE_PAUSED)
self._pipeline.get_state()
self.debug('paused')
self.debug('query duration')
sink = self._pipeline.get_by_name('sink')
assert sink, 'Error constructing pipeline'
length, format = sink.query_duration(gst.FORMAT_DEFAULT)
# wavparse 0.10.14 returns in bytes
if format == gst.FORMAT_BYTES:
self.debug('query returned in BYTES format')
length /= 4
self.debug('total length', length)
self.length = length
self._pipeline.set_state(gst.STATE_NULL)
self.stop()

View File

@@ -45,4 +45,13 @@ class KingsSeparateTestCase(unittest.TestCase):
self.assertEquals(h(crctask.crcs[2]), '0xd63dc2d2')
self.assertEquals(h(crctask.crcs[3]), '0x7271db39')
class AudioLengthTestCase(unittest.TestCase):
def testLength(self):
path = os.path.join(os.path.dirname(__file__), 'track.flac')
t = image.AudioLengthTask(path)
runner = task.SyncRunner()
runner.run(t, verbose=False)
self.assertEquals(t.length, 5880)