예제 #1
0
 def videos(self):
     base_url = self.context.absolute_url()
     base_wurl = base_url + '/@@view/++widget++form.widgets.'
     base_furl = base_wurl + 'IVideo.'
     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': base_furl + fieldname + '/@@stream'
             })
     for i in videos:
         if i['type'] == 'ogg':
             videos.remove(i)
             videos.insert(len(videos), i)
     return videos
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
    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()
예제 #6
0
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
            )

    for video_type, fieldname in conversion_types.items():
        if video_type == video.contentType.split('/')[-1]:
            setattr(context, fieldname, video)
        else:
            output_filepath = os.path.join(tmpdir, 'output.' + video_type)
            try:
                avconv.convert(tmpfilepath, output_filepath)
            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):
            fi = open(output_filepath)
            context.image = NamedBlobImage(fi, filename=u'screengrab.png')
            fi.close()
    except:
        logger.warn('error getting thumbnail from video')
    rmtree(tmpdir)
예제 #7
0
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)