def handleMediaUpload(self, file): """ Handle upload of a media file. A B{File} object will be created inside the B{NyMediafile} object. """ if file == '': return if not hasattr(file, 'filename'): return if file.filename == '': return self.manage_delObjects(self.objectIds()) ctype = file.headers.get("content-type") filename = ntpath.basename(getattr(file, 'filename', '')) filename = os.path.splitext(filename) if filename[1] != '.mp3': file.filename = filename[0] + ".mp4" file.headers["content-type"] = MP4_HEADERS[0] mid = self.manage_addFile('', file) mediafile = self.getSingleMediaObject() filepath = mediafile.get_filename() resolution = get_resolution(filepath) # for valid mp3 or mp4 audio files and for mp4 video files with # valid resolutions of max 720p we skip re-encoding if is_valid_audio(filepath) or ( filename[1] == '.mp4' and resolution[1] <= 720 and int(resolution[0]) / 16 * 16 == resolution[0] and int(resolution[1]) / 16 * 16 == resolution[1]): mediafile._conversion_log = '' mediafile._p_changed = True else: self._processFile(mid, ctype)
def handleMediaUpload(self, file): """ Handle upload of a media file. A B{File} object will be created inside the B{NyMediafile} object. """ if file == '': return if not hasattr(file, 'filename'): return if file.filename == '': return self.manage_delObjects(self.objectIds()) ctype = file.headers.get("content-type") filename = ntpath.basename(getattr(file, 'filename', '')) filename = os.path.splitext(filename) if filename[1] != '.mp3': file.filename = filename[0] + ".mp4" file.headers["content-type"] = MP4_HEADERS[0] mid = self.manage_addFile('', file) mediafile = self.getSingleMediaObject() filepath = mediafile.get_filename() resolution = get_resolution(filepath) # for valid mp3 or mp4 audio files and for mp4 video files with # valid resolutions of max 720p we skip re-encoding if is_valid_audio(filepath) or ( filename[1] == '.mp4' and resolution[1] <= 720 and int(resolution[0])/16*16 == resolution[0] and int(resolution[1])/16*16 == resolution[1]): mediafile._conversion_log = '' mediafile._p_changed = True else: self._processFile(mid, ctype)
def index_html(self, REQUEST=None, RESPONSE=None): """ """ mediafile = self.getSingleMediaObject() if self.mediaReady(): if not getattr(mediafile, 'aspect_ratio', None): filepath = mediafile.get_filename() width, height = get_resolution(filepath) mediafile.aspect_ratio = width/height mediafile._p_changed = True return self.getFormsTool().getContent({'here': self}, 'mediafile_index')
def _update(self, portal): for ob in portal.getCatalogedObjects(meta_type="Naaya Media File"): media = ob.getSingleMediaObject() if not media or hasattr(media.aq_base, "aspect_ratio") or ob.is_audio(): continue file_path = media.get_filename() try: resolution = get_resolution(file_path) aspect_ratio = resolution[0] / resolution[1] media.aspect_ratio = aspect_ratio self.log.debug("Aspect ratio %s saved for %s" % (aspect_ratio, ob.absolute_url())) except ValueError: self.log.error("Media file not found for %s" % ob.absolute_url()) return True
def _update(self, portal): for ob in portal.getCatalogedObjects(meta_type="Naaya Media File"): media = ob.getSingleMediaObject() if not media or hasattr(media.aq_base, 'aspect_ratio') or ob.is_audio(): continue file_path = media.get_filename() try: if file_path: resolution = get_resolution(file_path) aspect_ratio = resolution[0]/resolution[1] media.aspect_ratio = aspect_ratio self.log.debug('Aspect ratio %s saved for %s' % (aspect_ratio, ob.absolute_url())) else: self.log.debug('Media file %s missing' % ob.absolute_url()) except ValueError: self.log.error('Media file not found for %s' % ob.absolute_url()) return True