paper: Abstract, Introduction and Next-Share sections completed
[living-lab-site.git] / cis / api / base.py
index 6f41275..0b30bc9 100644 (file)
@@ -4,11 +4,13 @@
 Base classes for the external programs API.
 """
 
-import api_exceptions
+import os
 import re
-import cis_util
 import random
 
+import api_exceptions
+import cis_util
+
 class BaseTranscoder:
     """
     Abstraction of the API class for the transcoder program. 
@@ -83,10 +85,10 @@ class BaseTranscoder:
         if a_codec is None and v_codec is None:
             raise ValueError('No audio or video codec specified.')
 
-        if a_codec is not None and type(a_codec) is not str:
+        if a_codec is not None and type(a_codec) not in [str, unicode]:
             raise TypeError('Audio codec must be string.')
 
-        if v_codec is not None and type(v_codec) is not str:
+        if v_codec is not None and type(v_codec) not in [str, unicode]:
             raise TypeError('Video codec must be string.')
 
         if a_samplingrate is not None and type(a_samplingrate) is not int:
@@ -106,7 +108,7 @@ class BaseTranscoder:
                 and re.match('[\d]+:[\d]+', v_dar) is None):
             raise ValueError('Video display aspect ratio must be a float or a string like <den>:<num>.')
 
-        self.output_file = self.dest_path + self.name
+        self.output_file = os.path.join(self.dest_path, self.name)
         if v_resolution is not None:
             self.output_file += '_'
             self.output_file += v_resolution[(v_resolution.rindex('x')+1):]
@@ -225,7 +227,7 @@ class BaseThumbExtractor:
         for index in range (0, count):
             thumb_extracted = True
             try:
-                self.extract_thumb(seek_pos, resolution, index)
+                self.extract_thumb(seek_pos, resolution, n_thumbs_extracted)
             except api_exceptions.ThumbExtractionException as e:
                 thumb_extracted = False
 
@@ -238,7 +240,7 @@ class BaseThumbExtractor:
 
     def get_output_file_name(self, index):
         """ Returns the name required as output file name based on index. """
-        output_file_name = self.dest_path + self.name \
+        output_file_name = os.path.join(self.dest_path, self.name) \
                 + '_t' + ("%02d" % index) + '.jpg'
         return output_file_name