X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=cis%2Fapi%2Fbase.py;h=9e4ea5eeeb798ef86719e9658c4f013fe78a1af6;hb=refs%2Fheads%2Fmaster;hp=36d490b10f9f1fdbd2259a22a20a4af8a42937b1;hpb=820d45742df3bedbb0477e06cb651f5d328e5ab2;p=living-lab-site.git diff --git a/cis/api/base.py b/cis/api/base.py index 36d490b..9e4ea5e 100644 --- a/cis/api/base.py +++ b/cis/api/base.py @@ -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): """ @@ -85,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: @@ -109,20 +109,27 @@ class BaseTranscoder: raise ValueError('Video display aspect ratio must be a float or a string like :.') 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,8 @@ 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] @@ -158,7 +166,8 @@ 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] @@ -166,7 +175,8 @@ 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] @@ -228,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: @@ -242,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):