def __call__(self, value, *args, **kw): registry = getUtility(IRegistry) settings = registry.forInterface(ITranscodeSetings) valid_content_types = settings.video_valid_content_types content_type="" #import pdb; pdb.set_trace() content_types=tuple(valid_content_types.split()) error = translate(_('contenttype_error', default=_(u"File has to be of one of the following content-types '${types}'."), mapping={'types': ', '.join(content_types)}), context=kw['instance'].REQUEST) if value and not value == 'DELETE_FILE': try: if kw['REQUEST'].form.get('%s_delete' % kw['field'].getName(), None) == 'delete': return 1 if kw['REQUEST'].form.get('%s_delete' % kw['field'].getName(), None) == 'nochange': type = kw['field'].getContentType(kw['instance']) else: mimetypes = getToolByName(kw['instance'], 'mimetypes_registry') type = mimetypes.lookupExtension(value.filename.lower()) if type is None: type = mimetypes.globFilename(value.filename) try: type = type.mimetypes[0] except: # wasn't able to parse mimetype type = None if not type in content_types: return error except: return error return 1
def PlayingVideoType(self): #import pdb; pdb.set_trace() registry = getUtility(IRegistry) settings = registry.forInterface(ITranscodeSetings) self.SERVER = self.RemoveSlash(settings.adress_of_streaming_server) VIDEO_PARAMETRES_TRANSCODE = settings.ffmpeg_parameters_video_line AUDIO_PARAMETRES_TRANSCODE = settings.ffmpeg_parameters_audio_line audio_content_types=settings.audio_valid_content_types video_content_types=settings.video_valid_content_types portal = getSite() self.STORAGE=ZCONFIG.storagePathForSite(portal) self.MyTitle = self.context.Title() idvideo=self.context.getId() self.MyTitleWhitOutSpace = MFNI.DeleteSpaceinNameOfFolderFile(MFNI.TitleDeleteSpace(self.MyTitle)) self.PathOfFile = self.context._getURL() virtualobject=self.context.getVideo() self.filenamesaved=virtualobject.filename self.extension=MTDI.CheckExtension(self.filenamesaved) if self.extension=="ogg" or self.extension=="ogv" or self.extension=="OGG" or self.extension=="OGV": self.folderfileOGG=path.join(self.PathOfFile,quote(self.filenamesaved)) self.prefiletranscoded=path.join(self.STORAGE,self.PathOfFile,self.filenamesaved) if path.isfile(self.prefiletranscoded)==True: self.StatusOfFile=ServiceList.available(idvideo,self.prefiletranscoded) if self.StatusOfFile == False: ServiceList.AddReadyElement(idvideo,self.prefiletranscoded) self.StatusOfFile=True ServiceList.SaveInZODB() self.AbsoluteServerPath = path.join(self.SERVER,self.folderfileOGG) else: self.AbsoluteServerPath = path.join(self.SERVER,self.folderfileOGG) else: print _("File not found "+self.prefiletranscoded) self.Error=True self.ErrorSituation() else: newtrans_init_(self.STORAGE, self.PathOfFile, self.filenamesaved, idvideo, VIDEO_PARAMETRES_TRANSCODE, AUDIO_PARAMETRES_TRANSCODE, audio_content_types, video_content_types) self.folderfileOGG=MTDI.newname(path.join(self.PathOfFile,self.filenamesaved)) self.AbsoluteServerPath = path.join(self.SERVER,MTDI.nginxpath(self.folderfileOGG)) self.newfiletranscoded=MTDI.nginxpath(path.join(self.STORAGE,self.folderfileOGG)) self.StatusOfFile = ServiceList.available(idvideo,self.newfiletranscoded) #import pdb;pdb.set_trace() if self.StatusOfFile == True: self.newfilename=MTDI.newname(self.filenamesaved) else: self.newfilename=_('The file is not ready yet, please contact site administration') return
def __call__(self, value, *args, **kw): instance = kw.get('instance', None) field = kw.get('field', None) registry = getUtility(IRegistry) settings = registry.forInterface(ITranscodeSetings) transcode_status = settings.transcode_switch valid_types=('video/ogg', 'video/x-theora+ogg', 'application/ogg') error = translate(_('contenttype_error_transcode_service', default=_(u"We sorry but in this moment, the transcode is out of service. To load your file must to be one of the following content-types '${types}'."), mapping={'types': ', '.join(valid_types)}), context=kw['instance'].REQUEST) if value and not value == 'DELETE_FILE': try: if kw['REQUEST'].form.get('%s_delete' % kw['field'].getName(), None) == 'delete': return 1 if kw['REQUEST'].form.get('%s_delete' % kw['field'].getName(), None) == 'nochange': type = kw['field'].getContentType(kw['instance']) else: my_mime_types = getToolByName(kw['instance'], 'mimetypes_registry') type = my_mime_types.lookupExtension(value.filename.lower()) #pdb.set_trace() if type is None: type = my_mime_types.globFilename(value.filename) try: file_type = type.my_mime_types[0] except: # wasn't able to parse mimetype try: file_type=str(type) #pdb.set_trace() except: file_type = None if file_type in valid_types: return 1 elif ((file_type not in valid_types) or (file_type in valid_types)) and (transcode_status == True): return 1 elif file_type not in valid_types and transcode_status == False: return error except: return error return 1
def __call__(self, value, *args, **kwargs): instance = kwargs.get('instance', None) field = kwargs.get('field', None) # get max size if kwargs.has_key('maxsize'): maxsize = kwargs.get('maxsize') elif hasattr(aq_base(instance), 'getMaxSizeFor'): maxsize = instance.getMaxSizeFor(field.getName()) elif hasattr(field, 'maxsize'): maxsize = field.maxsize else: # set to given default value (default defaults to 0) registry = getUtility(IRegistry) settings = registry.forInterface(ITranscodeSetings) maxsize = settings.max_file_size if not maxsize: return True # calculate size elif (isinstance(value, FileUpload) or isinstance(value, file) or hasattr(aq_base(value), 'tell')): value.seek(0, 2) # eof size = value.tell() value.seek(0) else: try: size = len(value) except TypeError: size = 0 size = float(size) sizeMB = (size / (1024 * 1024)) if sizeMB > maxsize: msg = _("Validation failed(Uploaded data is too large: ${size}MB (max ${max}MB))", mapping = { 'size' : safe_unicode("%.3f" % sizeMB), 'max' : safe_unicode("%.3f" % maxsize) }) return recursiveTranslate(msg, **kwargs) else: return True
# -*- FileSystemStorage Import here -*- from iw.fss.FileSystemStorage import FileSystemStorage #validator imports from Products.validation.config import validation from Products.validation import V_REQUIRED from cenditel.video.validators import ContentTypeValidator, TranscodeVideoValidator videoSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema(( # -*- Your Archetypes field definitions here ... -*- atapi.FileField( name='video', widget=atapi.FileWidget( label=_(u"Video"), description=_(u"The File to be uploaded") ), required=True, searchable=True, storage=FileSystemStorage(), validators=( ('checkFileMaxSize',V_REQUIRED), (ContentTypeValidator()), (TranscodeVideoValidator()), ), ) )) # Set storage on fields copied from ATContentTypeSchema, making sure # they work well with the python bridge properties.