import re
import random
-import api_exceptions
+import cis_exceptions
import cis_util
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):
"""
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:
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):
"""
""" 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]
""" 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]
""" 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]
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:
""" 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):