def setUp(self): self.portal = self.layer['portal'] self.request = self.layer['request'] self.request['ACTUAL_URL'] = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ['Manager']) settings = GlobalSettings(self.portal) settings.additional_video_formats = []
def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] settings = GlobalSettings(self.portal) settings.additional_video_formats = [] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) )
def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] settings = GlobalSettings(self.portal) settings.additional_video_formats = [] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, ))
def convert(self, filepath, outputfilepath, video_type, video): portal = getSite() settings = GlobalSettings(portal) params = self.get_avconv_params(settings, video_type, video) cmd = [self.binary] + params['in'] + ['-i', filepath] + params['out'] + [outputfilepath] self._run_command(cmd)
def upgrade_to_2003(context): portal = getToolByName(context, 'portal_url').getPortalObject() settings = GlobalSettings(portal) # Apply old in/outfile options to each new format specific option old_outfileopt = settings.convert_outfile_options old_infileopt = settings.convert_infile_options if old_outfileopt: settings.avconv_out_mp4 = old_outfileopt settings.avconv_out_ogg = old_outfileopt settings.avconv_out_webm = old_outfileopt if old_infileopt: settings.avconv_in_mp4 = old_infileopt settings.avconv_in_ogg = old_infileopt settings.avconv_in_webm = old_infileopt
def set_quota(self): """ Set quota for document viewer jobs """ settings = GlobalSettings(self.portal) size = settings.async_quota_size if QUOTA_NAME in self.queue.quotas: if self.queue.quotas[QUOTA_NAME].size != size: self.queue.quotas[QUOTA_NAME].size = size logger.info("quota %r configured in queue %r", QUOTA_NAME, self.queue.name) else: self.queue.quotas.create(QUOTA_NAME, size=size) logger.info("quota %r added to queue %r", QUOTA_NAME, self.queue.name)
def get_avconv_params(self, settings, video_type, video): portal = getSite() settings = GlobalSettings(portal) params = {} for op in ('in', 'out'): option = getattr(settings, 'avconv_%s_%s' % (op, video_type)) or '' # replace width/height if set width = getattr(aq_base(video), 'width', settings.default_video_width) height = getattr(aq_base(video), 'height', settings.default_video_height) option = option.replace('{width}', str(width)) option = option.replace('{height}', str(height)) params[op] = shlex.split(option) return params
def videos(self): types = [('mp4', 'video_file')] settings = GlobalSettings( getToolByName(self.context, 'portal_url').getPortalObject()) for type_ in settings.additional_video_formats: format = getFormat(type_) if format: types.append((format.type_, 'video_file_' + format.extension)) videos = [] for (_type, fieldname) in types: file = getattr(self.context, fieldname, None) if file: videos.append({ 'type': _type, 'url': self.base_furl + fieldname + '/@@stream' }) return videos
def __call__(self): context = self.context self.setUp() self.base_furl = self.base_wurl + 'IVideo.' types = [('mp4', 'video_file')] settings = GlobalSettings(self.portal) for type_ in settings.additional_video_formats: format = getFormat(type_) if format: types.append((format.type_, 'video_file_' + format.extension)) self.videos = [] for (_type, fieldname) in types: file = getattr(context, fieldname, None) if file: self.videos.append({ 'type': _type, 'url': self.base_furl + fieldname + '/@@stream' }) if self.videos: self.mp4_url = self.videos[0]['url'] else: self.mp4_url = None image = getattr(self.context, 'image', None) if image: self.image_url = '%s/@@images/image' % ( self.base_url ) else: self.image_url = None subtitles = getattr(self.context, 'subtitle_file', None) if subtitles: self.subtitles_url = '%ssubtitle_file/@@download/%s' % ( self.base_furl, subtitles.filename ) else: self.subtitles_url = None self.width = getattr(context, 'width', 640) self.height = getattr(context, 'height', 320) return self.index()
def settings(self): return GlobalSettings(getSite())
def getDefaultHeight(): portal = getSite() settings = GlobalSettings(portal) return settings.default_video_height
def getDefaultWidth(): portal = getSite() settings = GlobalSettings(portal) return settings.default_video_width
def _convertFormat(context): # reset these... context.video_file_ogv = None context.video_file_webm = None video = context.video_file context.video_converted = True try: opened = openBlob(video._blob) bfilepath = opened.name opened.close() except IOError: logger.warn('error opening blob file') return tmpdir = mkdtemp() tmpfilepath = os.path.join(tmpdir, video.filename) copyfile(bfilepath, tmpfilepath) try: metadata = avprobe.info(tmpfilepath) except: logger.warn('not a valid video format') return context.metadata = metadata conversion_types = { 'mp4': 'video_file' } portal = getToolByName(context, 'portal_url').getPortalObject() settings = GlobalSettings(portal) for type_ in settings.additional_video_formats: format = getFormat(type_) if format: conversion_types[format.extension] = 'video_file_%s' % ( format.extension ) # sometimes force full video conversion force = settings.force for video_type, fieldname in conversion_types.items(): if video_type == video.contentType.split('/')[-1] and not force: setattr(context, fieldname, video) else: output_filepath = os.path.join(tmpdir, 'output.' + video_type) try: avconv.convert(tmpfilepath, output_filepath, video_type, context) except: logger.warn('error converting to %s' % video_type) continue if os.path.exists(output_filepath): fi = open(output_filepath) namedblob = NamedBlobFile( fi, filename=switchFileExt(video.filename, video_type)) setattr(context, fieldname, namedblob) fi.close() # try and grab one from video output_filepath = os.path.join(tmpdir, u'screengrab.png') try: avconv.grab_frame(tmpfilepath, output_filepath) if os.path.exists(output_filepath): with open(output_filepath, 'rb') as fi: data = fi.read() context.image = NamedBlobImage(data, filename=u'screengrab.png') fi.close() except: logger.warn('error getting thumbnail from video') rmtree(tmpdir)