[SCM] morituri/master: * 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.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:08:45 UTC 2014


The following commit has been merged in the master branch:
commit 27fd2f16e6e777de85ec081abbe78c6ddaae72ab
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sun Apr 12 10:20:14 2009 +0000

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

diff --git a/ChangeLog b/ChangeLog
index dce906b..e1c94a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 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:
 	  Schedule the start from the main loop, otherwise the
 	  task might complete before we're in the main loop,
diff --git a/morituri/image/image.py b/morituri/image/image.py
index 05641ad..6a6ce73 100644
--- a/morituri/image/image.py
+++ b/morituri/image/image.py
@@ -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()
diff --git a/morituri/test/test_image_image.py b/morituri/test/test_image_image.py
index 112b8b5..37ba006 100644
--- a/morituri/test/test_image_image.py
+++ b/morituri/test/test_image_image.py
@@ -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)
+        
+
 

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list