Commit b177b693 authored by Priscila Manhaes's avatar Priscila Manhaes

Refactor code for not only expecting video but also audio

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@45139 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2a06ea34
......@@ -34,7 +34,7 @@ from tempfile import mktemp
class Handler(object):
"""FFMPEG Handler is used to handler inputed video files"""
"""FFMPEG Handler is used to handler inputed audio and video files"""
implements(IHandler)
......@@ -43,15 +43,15 @@ class Handler(object):
base_folder_url(string)
The requested url for data base folder
data(string)
The opened and readed video into a string
The opened and readed file into a string
source_format(string)
The source format of the inputed video"""
The source format of the inputed file"""
self.base_folder_url = base_folder_url
self.input = File(base_folder_url, data, source_format)
self.environment = kw.get("env", {})
def convert(self, destination_format):
""" Convert the inputed video to output as format that were informed """
""" Convert the inputed file to output as format that were informed """
# XXX This implementation could use ffmpeg -i pipe:0, but
# XXX seems super unreliable currently and it generates currupted files in
# the end
......@@ -74,7 +74,7 @@ class Handler(object):
self.input.trash()
def getMetadata(self, base_document=False):
"""Returns a dictionary with all metadata of the video.
"""Returns a dictionary with all metadata of the file.
Keywords Arguments:"""
command = ["ffprobe",self.input.getUrl()]
stdout, stderr = Popen(command,
......@@ -91,7 +91,7 @@ class Handler(object):
self.input.trash()
return metadata_dict
def setMetadata(self, metadata={}):
def setMetadata(self, metadata_dict={}):
"""Returns a document with new metadata.
Keyword arguments:
metadata -- expected an dictionary with metadata.
......
......@@ -26,10 +26,11 @@
#
##############################################################################
import magic
from magic import Magic
from cloudooo.handler.ffmpeg.handler import Handler
from cloudooo.handler.tests.handlerTestCase import HandlerTestCase, make_suite
file_detector = Magic(mime=True)
class TestHandler(HandlerTestCase):
......@@ -40,7 +41,6 @@ class TestHandler(HandlerTestCase):
def testConvertVideo(self):
"""Test coversion of video to another format"""
file_detector = magic.Magic(mime=True)
output_data = self.input.convert("mpeg")
file_format = file_detector.from_buffer(output_data)
self.assertEquals(file_format, 'video/mpeg')
......@@ -54,6 +54,16 @@ class TestHandler(HandlerTestCase):
""" Test if metadata are inserted correclty """
self.assertRaises(NotImplementedError, self.input.setMetadata)
def testConvertAudio(self):
"""Test coversion of audio to another format"""
self.data = open("./data/test.ogg").read()
kw = dict(env=dict(PATH=self.env_path))
self.input = Handler(self.tmp_url, self.data, "ogg", **kw)
output_data = self.input.convert("wav")
file_format = file_detector.from_buffer(output_data)
# XXX this might expect 'audio/vnd.wave' but magic only got 'audio/x-wav'
self.assertEquals(file_format, 'audio/x-wav')
def test_suite():
return make_suite(TestHandler)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment