use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class VideoManagerImpl method getFrame.
/**
* write the the given frame at frameNumber in the frame leaf
* @param videoResource videoresource
* @param frameNumber the frameNumber at which the frame should be taken from
* @param frame the VFSLeaf to write the picked image to
*/
@Override
public boolean getFrame(OLATResource videoResource, int frameNumber, VFSLeaf frame) {
File videoFile = ((LocalFileImpl) getMasterVideoFile(videoResource)).getBasefile();
try (RandomAccessFile randomAccessFile = new RandomAccessFile(videoFile, "r")) {
FileChannel ch = randomAccessFile.getChannel();
FileChannelWrapper in = new FileChannelWrapper(ch);
FrameGrab frameGrab = new FrameGrab(in).seekToFrameSloppy(frameNumber);
OutputStream frameOutputStream = frame.getOutputStream(false);
BufferedImage bufImg = frameGrab.getFrame();
ImageIO.write(bufImg, "JPG", frameOutputStream);
// close everything to prevent resource leaks
frameOutputStream.close();
in.close();
ch.close();
return true;
} catch (Exception | AssertionError e) {
log.error("Could not get frame::" + frameNumber + " for video::" + videoFile.getAbsolutePath(), e);
return false;
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class VideoManagerImpl method hasVideoFile.
@Override
public boolean hasVideoFile(OLATResource videoResource) {
VFSContainer masterContainer = getMasterContainer(videoResource);
LocalFileImpl videoFile = (LocalFileImpl) masterContainer.resolve(FILENAME_VIDEO_MP4);
return videoFile != null && videoFile.exists();
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CourseHandler method importGlossary.
private void importGlossary(ICourse course, Identity owner) {
GlossaryManager gm = GlossaryManager.getInstance();
RepositoryEntryImportExport importExport = gm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
GlossaryResource resource = gm.createGlossary();
if (resource == null) {
log.error("Error adding glossary directry during repository reference import: " + importExport.getDisplayName());
return;
}
// unzip contents
VFSContainer glossaryContainer = gm.getGlossaryRootFolder(resource);
File fExportedFile = importExport.importGetExportedFile();
if (fExportedFile.exists()) {
ZipUtil.unzip(new LocalFileImpl(fExportedFile), glossaryContainer);
} else {
log.warn("The actual contents of the glossary were not found in the export.");
}
// create repository entry
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
// set the new glossary reference
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
courseConfig.setGlossarySoftKey(importedRepositoryEntry.getSoftkey());
CoreSpringFactory.getImpl(ReferenceManager.class).addReference(course, importedRepositoryEntry.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);
CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class CourseHandler method importSharedFolder.
private void importSharedFolder(ICourse course, Identity owner) {
SharedFolderManager sfm = SharedFolderManager.getInstance();
RepositoryEntryImportExport importExport = sfm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
SharedFolderFileResource resource = sfm.createSharedFolder();
if (resource == null) {
log.error("Error adding file resource during repository reference import: " + importExport.getDisplayName());
}
// unzip contents
VFSContainer sfContainer = sfm.getSharedFolder(resource);
File fExportedFile = importExport.importGetExportedFile();
if (fExportedFile.exists()) {
ZipUtil.unzip(new LocalFileImpl(fExportedFile), sfContainer);
} else {
log.warn("The actual contents of the shared folder were not found in the export.");
}
// create repository entry
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
// set the new shared folder reference
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
courseConfig.setSharedFolderSoftkey(importedRepositoryEntry.getSoftkey());
CoreSpringFactory.getImpl(ReferenceManager.class).addReference(importedRepositoryEntry.getOlatResource(), course, SharedFolderManager.SHAREDFOLDERREF);
CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
Aggregations