CIS Basic classes are being implemented
authorCalin-Andrei Burloiu <calin.burloiu@gmail.com>
Tue, 15 Nov 2011 15:34:51 +0000 (17:34 +0200)
committerCalin-Andrei Burloiu <calin.burloiu@gmail.com>
Tue, 15 Nov 2011 15:34:51 +0000 (17:34 +0200)
cis/api/__init__.py [new file with mode: 0644]
cis/api/base.py [new file with mode: 0644]
cis/api/ffmpeg.py [new file with mode: 0644]
cis/cis_exceptions.py [new file with mode: 0644]
cis/cisd.py [new file with mode: 0755]
cis/config.py [new file with mode: 0644]

diff --git a/cis/api/__init__.py b/cis/api/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/cis/api/base.py b/cis/api/base.py
new file mode 100644 (file)
index 0000000..3e5f508
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+
+"""
+Base classes for the external programs API.
+"""
+
+import cis_exceptions
+
+class BaseTranscoder:
+    """
+    Abstractization of the API class for the transcoder program. 
+    """
+
+    prog_bin = None
+    input_file = None
+
+    # Recommended formats.
+    containers = {
+        "avi": None,
+        "flv": None,
+        "mp4": None,
+        "ogg": None,
+        "webm": None,
+        "mpegts": None
+    }
+    a_codecs = {
+        "mp3": None,
+        "vorbis": None
+    }
+    v_codecs = {
+        "h264": None,
+        "theora": None,
+        "vp8": None
+    }
+
+    def __init__(self, input_file, prog_bin=None):
+        self.input_file = input_file
+        self.prog_bin = prog_bin
+
+    def transcode(self, container, a_codec, v_codec,
+            a_bitrate=None, a_samplingrate=None, a_channels=None,
+            v_bitrate=None, v_fraterate=None, v_resolution=None, v_dar=None):
+        """
+        Transcodes the input file to an audio-video file.
+
+        container: possible values are listed in containers member as keys
+        a_codec: possible values are listed in a_codecs member as keys
+        v_codec: possible values are listed in v_codecs member as keys
+        """
+
+        pass
+
+    def transcode_audio(self, container, a_codec,
+            a_bitrate=None, a_samplingrate=None, a_channels=None):
+        pass
+
+    def transcode_video(self, container, v_codec,
+            v_bitrate=None, v_fraterate=None, v_resolution=None, v_dar=None):
+        pass
+
+    def tr_container(self, name):
+        """ Translates container API name into external program identifier."""
+
+        if not self.containers.has_key(name) or self.containers[name] == None:
+            raise cis_exceptions.NotImplementedException("Container " + name)
+
+        return self.containers[name]
diff --git a/cis/api/ffmpeg.py b/cis/api/ffmpeg.py
new file mode 100644 (file)
index 0000000..13a711e
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import base
+
+class FFmpegTranscoder(base.BaseTranscoder):
+    prog_bin = 'ffmpeg'
+    input_file = None
+
+    def transcode(self, container, a_codec, v_codec,
+            a_bitrate=None, a_samplingrate=None, a_channels=None,
+            v_bitrate=None, v_fraterate=None, v_resolution=None, v_dar=None):
+        pass
+
+    def transcode_audio(self, container, a_codec,
+            a_bitrate=None, a_samplingrate=None, a_channels=None):
+        pass
+
+    def transcode_video(self, container, v_codec,
+            v_bitrate=None, v_fraterate=None, v_resolution=None, v_dar=None):
+        pass
diff --git a/cis/cis_exceptions.py b/cis/cis_exceptions.py
new file mode 100644 (file)
index 0000000..7bf1266
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+
+"""
+This module implements exceptions raised in Content Ingestion Server.
+"""
+
+class NotImplementedException(Exception):
+    def __init__(self, value):
+        self.value = value
+
+    def __str__(self):
+        return repr(self.value)
diff --git a/cis/cisd.py b/cis/cisd.py
new file mode 100755 (executable)
index 0000000..09181f3
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+import sys
+import config
+import cis_exceptions
+
+
+if __name__ == '__main__':
+    transcoder = config.TRANSCODER_CLASS("file")
+#    transcoder.transcode()
+    try:
+        print transcoder.tr_container("avi")
+    except cis_exceptions.NotImplementedException as e:
+        sys.stderr.write(e.value)
diff --git a/cis/config.py b/cis/config.py
new file mode 100644 (file)
index 0000000..d21fb56
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+# Make here all necessary imports required for API classes.
+from api import ffmpeg
+
+# External programs API classes.
+TRANSCODER_CLASS = ffmpeg.FFmpegTranscoder
+THUMB_EXTRACTER_CLASS = None # TODO
+BT_CLIENT_CLASS = None # TODO
+FILE_TRANSFERER_CLASS = None # TODO
+
+# External programs binary file. None means default.
+TRANSCODER_BIN = None
+THUMB_EXTRACTER_BIN = None
+BT_CLIENT_BIN = None
+FILE_TRANSFERER_BIN = None