Search in sources :

Example 46 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.

the class VideoManagerImpl method setPosterframeResizeUploadfile.

/**
 * Sets the posterframe resize uploadfile. Tries to fit image to dimensions of video.
 *
 * @param videoResource the video resource
 * @param posterframe the newPosterFile
 */
@Override
public void setPosterframeResizeUploadfile(OLATResource videoResource, VFSLeaf newPosterFile) {
    VideoMeta videoMetadata = getVideoMetadata(videoResource);
    Size posterRes = imageHelper.getSize(newPosterFile, FILETYPE_JPG);
    // file size needs to be bigger than target resolution, otherwise use image as it comes
    if (posterRes != null && posterRes.getHeight() != 0 && posterRes.getWidth() != 0 && posterRes.getHeight() >= videoMetadata.getHeight() && posterRes.getWidth() >= videoMetadata.getWidth()) {
        VFSLeaf oldPosterFile = getPosterframe(videoResource);
        oldPosterFile.delete();
        VFSContainer masterContainer = getMasterContainer(videoResource);
        LocalFileImpl newPoster = (LocalFileImpl) masterContainer.createChildLeaf(FILENAME_POSTER_JPG);
        // to shrink image file, resolution ratio needs to be equal, otherwise crop from top left corner
        if (posterRes.getHeight() / posterRes.getWidth() == videoMetadata.getHeight() / videoMetadata.getWidth()) {
            imageHelper.scaleImage(newPosterFile, newPoster, videoMetadata.getWidth(), videoMetadata.getHeight(), true);
        } else {
            Crop cropSelection = new Crop(0, 0, videoMetadata.getHeight(), videoMetadata.getWidth());
            imageHelper.cropImage(((LocalFileImpl) newPosterFile).getBasefile(), newPoster.getBasefile(), cropSelection);
        }
    } else {
        setPosterframe(videoResource, newPosterFile);
    }
}
Also used : Crop(org.olat.core.commons.services.image.Crop) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VideoMeta(org.olat.modules.video.VideoMeta) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 47 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.

the class VideoTranscodingJob method updateStatus.

private boolean updateStatus(VideoTranscoding videoTranscoding, File transcodedFile, int exitCode) {
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    MovieService movieService = CoreSpringFactory.getImpl(MovieService.class);
    videoTranscoding = videoManager.getVideoTranscoding(videoTranscoding.getKey());
    Size videoSize = movieService.getSize(new LocalFileImpl(transcodedFile), VideoManagerImpl.FILETYPE_MP4);
    if (videoSize != null) {
        videoTranscoding.setWidth(videoSize.getWidth());
        videoTranscoding.setHeight(videoSize.getHeight());
    } else {
        videoTranscoding.setWidth(0);
        videoTranscoding.setHeight(0);
    }
    if (transcodedFile.exists()) {
        videoTranscoding.setSize(transcodedFile.length());
    } else {
        videoTranscoding.setSize(0);
    }
    if (exitCode == 0) {
        videoTranscoding.setStatus(VideoTranscoding.TRANSCODING_STATUS_DONE);
    } else {
        log.error("Exit code " + videoTranscoding + ":" + exitCode);
        videoTranscoding.setStatus(VideoTranscoding.TRANSCODING_STATUS_ERROR);
    }
    videoTranscoding = videoManager.updateVideoTranscoding(videoTranscoding);
    DBFactory.getInstance().commitAndCloseSession();
    return exitCode == 0;
}
Also used : MovieService(org.olat.core.commons.services.video.MovieService) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VideoManager(org.olat.modules.video.VideoManager)

Example 48 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.

the class WebDocumentRunController method getWebDocument.

private LocalFileImpl getWebDocument(RepositoryEntry entry) {
    OLATResource resource = entry.getOlatResource();
    VFSContainer fResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
    LocalFileImpl document = null;
    for (VFSItem item : fResourceFileroot.getItems()) {
        if (item instanceof VFSLeaf && item instanceof LocalImpl) {
            LocalFileImpl localItem = (LocalFileImpl) item;
            if (localItem != null && !localItem.getBasefile().isHidden()) {
                document = (LocalFileImpl) item;
            }
        }
    }
    return document;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VFSItem(org.olat.core.util.vfs.VFSItem) LocalImpl(org.olat.core.util.vfs.LocalImpl)

Example 49 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.

the class VideoFileResource method validate.

/**
 * @param file
 *            file to validate
 * @param fileName
 *            name of the file. Necessary since the file.filename contains
 *            gliberish during upload
 * @param eval the resource validation. Is set to valid if file is accepted
 */
public static void validate(File file, String fileName, ResourceEvaluation eval) {
    if (!videomodule.isEnabled()) {
        return;
    }
    // accept raw mp4 files
    // accept also mov files as iOS saves mp4 movis as mov, but check if the file can be parsed as mp4 file
    boolean isMP4 = movieService.isMP4(new LocalFileImpl(file), fileName);
    if (isMP4) {
        eval.setValid(true);
        eval.setDisplayname(fileName + " - " + Formatter.formatShortDateFilesystem(new Date()));
    } else if (fileName.endsWith(".zip")) {
        // check if zip contains an exported video resource
        videoManager.validateVideoExportArchive(file, eval);
    }
}
Also used : LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Date(java.util.Date)

Example 50 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.

the class CPOfflineReadableManager method writeOfflineCPStartHTMLFile.

/**
 * generates a html-file (_START_.html) that presents the given cp-content
 * (specified by its "_unzipped_"-dir). The resulting file is suitable for
 * offline reading of the cp.
 *
 * @param unzippedDir
 *            the directory that contains the unzipped CP
 */
private void writeOfflineCPStartHTMLFile(File unzippedDir) throws IOException {
    /* first, we do the menu-tree */
    File mani = new File(unzippedDir, FILENAME_IMSMANIFEST);
    LocalFileImpl vfsMani = new LocalFileImpl(mani);
    CPManifestTreeModel ctm = new CPManifestTreeModel(vfsMani, "");
    TreeNode root = ctm.getRootNode();
    // let's take the rootnode title as  page title
    this.rootTitle = root.getTitle();
    StringBuilder menuTreeSB = new StringBuilder();
    renderMenuTreeNodeRecursively(root, menuTreeSB, 0);
    // now put values to velocityContext
    VelocityContext ctx = new VelocityContext();
    ctx.put("menutree", menuTreeSB.toString());
    ctx.put("rootTitle", this.rootTitle);
    ctx.put("cpoff", DIRNAME_CPOFFLINEMENUMAT);
    StringWriter sw = new StringWriter();
    try {
        String template = FileUtils.load(CPOfflineReadableManager.class.getResourceAsStream("_content/cpofflinereadable.html"), "utf-8");
        boolean evalResult = velocityEngine.evaluate(ctx, sw, "cpexport", template);
        if (!evalResult)
            log.error("Could not evaluate velocity template for CP Export");
    } catch (Exception e) {
        log.error("Error while evaluating velovity template for CP Export", e);
    }
    File f = new File(unzippedDir, FILENAME_START);
    if (f.exists()) {
        FileUtils.deleteDirsAndFiles(f, false, true);
    }
    ExportUtil.writeContentToFile(FILENAME_START, sw.toString(), unzippedDir, "utf-8");
}
Also used : StringWriter(java.io.StringWriter) TreeNode(org.olat.core.gui.components.tree.TreeNode) VelocityContext(org.apache.velocity.VelocityContext) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File) IOException(java.io.IOException)

Aggregations

LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)126 File (java.io.File)70 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 Size (org.olat.core.commons.services.image.Size)22 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 RandomAccessFile (java.io.RandomAccessFile)14 FileChannel (java.nio.channels.FileChannel)12 FileChannelWrapper (org.jcodec.common.FileChannelWrapper)12 CannotGenerateThumbnailException (org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)12 OLATResource (org.olat.resource.OLATResource)10 Date (java.util.Date)8 MP4Demuxer (org.jcodec.containers.mp4.demuxer.MP4Demuxer)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)8 VFSCPNamedItem (org.olat.ims.cp.ui.VFSCPNamedItem)8 BufferedImage (java.awt.image.BufferedImage)6 InputStream (java.io.InputStream)6