upload facility now works in single CIS mode; some simple command-line video moderati...
[living-lab-site.git] / cis / api / base.py
index 500aada..9e4ea5e 100644 (file)
@@ -8,7 +8,7 @@ import os
 import re
 import random
 
-import api_exceptions
+import cis_exceptions
 import cis_util
 
 class BaseTranscoder:
@@ -61,7 +61,7 @@ class BaseTranscoder:
 
         self.name = name
 
-    def transcode(self, container, a_codec=None, v_codec=None,
+    def transcode(self, container, extension=None, a_codec=None, v_codec=None,
             a_bitrate=None, a_samplingrate=None, a_channels=None,
             v_bitrate=None, v_framerate=None, v_resolution=None, v_dar=None):
         """
@@ -109,20 +109,27 @@ class BaseTranscoder:
             raise ValueError('Video display aspect ratio must be a float or a string like <den>:<num>.')
 
         self.output_file = os.path.join(self.dest_path, self.name)
+        if os.path.exists(self.output_file):
+            raise cis_exceptions.FileAlreadyExistsException( \
+                    'file "%s" already exists' % self.output_file)
+        
         if v_resolution is not None:
             self.output_file += '_'
             self.output_file += v_resolution[(v_resolution.rindex('x')+1):]
             self.output_file += 'p'
-        ext = self.tr_extension(container, (v_codec is not None))
+        if extension == None:
+            ext = self.tr_extension(container, (v_codec is not None))
+        else:
+            ext = extension
         if ext is not None:
             self.output_file += '.' + ext
 
-        return self._transcode(self.tr_container(container),
+        return self._transcode(self.tr_container(container), ext,
                 self.tr_a_codec(a_codec), self.tr_v_codec(v_codec),
                 a_bitrate, a_samplingrate, a_channels,
                 v_bitrate, v_framerate, v_resolution, v_dar)
 
-    def _transcode(self, container, a_codec=None, v_codec=None,
+    def _transcode(self, container, extension=None, a_codec=None, v_codec=None,
             a_bitrate=None, a_samplingrate=None, a_channels=None,
             v_bitrate=None, v_framerate=None, v_resolution=None, v_dar=None):
         """
@@ -137,7 +144,7 @@ class BaseTranscoder:
         """ Translates container API name into external program identifier."""
 
         if not self.containers.has_key(name) or self.containers[name] is None:
-            raise api_exceptions.NotImplementedException("Container " + name \
+            raise cis_exceptions.NotImplementedException("Container " + name \
                     + "not implemented")
 
         return self.containers[name]
@@ -159,7 +166,7 @@ class BaseTranscoder:
         """ Translates audio codec API name into external program identifier."""
 
         if not self.a_codecs.has_key(name) or self.a_codecs[name] is None:
-            raise api_exceptions.NotImplementedException("Audio Codec " + name \
+            raise cis_exceptions.NotImplementedException("Audio Codec " + name \
                     + "not implemented")
 
         return self.a_codecs[name]
@@ -168,7 +175,7 @@ class BaseTranscoder:
         """ Translates video codec API name into external program identifier."""
 
         if not self.v_codecs.has_key(name) or self.v_codecs[name] is None:
-            raise api_exceptions.NotImplementedException("Video Codec " + name \
+            raise cis_exceptions.NotImplementedException("Video Codec " + name \
                     + "not implemented")
 
         return self.v_codecs[name]
@@ -231,7 +238,7 @@ class BaseThumbExtractor:
             thumb_extracted = True
             try:
                 self.extract_thumb(seek_pos, resolution, n_thumbs_extracted)
-            except api_exceptions.ThumbExtractionException as e:
+            except cis_exceptions.ThumbExtractionException as e:
                 thumb_extracted = False
 
             if thumb_extracted:
@@ -245,6 +252,11 @@ class BaseThumbExtractor:
         """ Returns the name required as output file name based on index. """
         output_file_name = os.path.join(self.dest_path, self.name) \
                 + '_t' + ("%02d" % index) + '.jpg'
+                
+        #if os.path.exists(output_file_name):
+            #raise cis_exceptions.FileAlreadyExistsException( \
+                    #'file "%s" already exists' % output_file_name)
+        
         return output_file_name
 
     def get_video_duration(self):