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);
}
}
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;
}
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;
}
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);
}
}
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");
}
Aggregations