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.
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:
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):]
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
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