Search in sources :

Example 1 with VideoMetaImpl

use of org.olat.modules.video.model.VideoMetaImpl in project OpenOLAT by OpenOLAT.

the class VideoMetadataDAO method createVideoMetadata.

/**
 * Creates and persists the video metadata.
 *
 * @param videoResource
 * @param size
 * @param filename
 * @return metadata
 */
VideoMetaImpl createVideoMetadata(RepositoryEntry repoEntry, long size, String fileName) {
    VideoMetaImpl videometa = new VideoMetaImpl();
    OLATResource videoResource = repoEntry.getOlatResource();
    videometa.setVideoResource(videoResource);
    String format = FilenameUtils.getExtension(fileName);
    videometa.setFormat(format);
    videometa.setCreationDate(new Date());
    videometa.setLastModified(new Date());
    Size resolution = videoManager.getVideoResolutionFromOLATResource(videoResource);
    videometa.setHeight(resolution.getHeight());
    videometa.setWidth(resolution.getWidth());
    videometa.setSize(size);
    videometa.setLength(repoEntry.getExpenditureOfWork());
    dbInstance.getCurrentEntityManager().persist(videometa);
    return videometa;
}
Also used : Size(org.olat.core.commons.services.image.Size) VideoMetaImpl(org.olat.modules.video.model.VideoMetaImpl) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date)

Example 2 with VideoMetaImpl

use of org.olat.modules.video.model.VideoMetaImpl in project openolat by klemens.

the class VideoMetadataDAOTest method deleteVideoMetadata.

@Test
public void deleteVideoMetadata() {
    RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry3 = JunitTestHelper.createAndPersistRepositoryEntry();
    // create metadata entries
    VideoMeta meta0 = videoMetadataDao.createVideoMetadata(entry0, 1500, "vid.mp4");
    VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1100, "vide.mp4");
    VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 1200, "video.mov");
    VideoMeta meta3 = videoMetadataDao.createVideoMetadata(entry3, 4500, "videos.mp4");
    Assert.assertNotNull(meta1);
    Assert.assertNotNull(meta3);
    Assert.assertNotNull(meta2);
    Assert.assertNotNull(meta0);
    dbInstance.commitAndCloseSession();
    // retrieve list of entries
    List<VideoMetaImpl> metadata = videoMetadataDao.getAllVideoResourcesMetadata();
    Assert.assertTrue(metadata.contains(meta0));
    Assert.assertTrue(metadata.contains(meta1));
    Assert.assertTrue(metadata.contains(meta2));
    Assert.assertTrue(metadata.contains(meta3));
    // delete entries
    int deleted0 = videoMetadataDao.deleteVideoMetadata(entry0.getOlatResource());
    int deleted3 = videoMetadataDao.deleteVideoMetadata(entry3.getOlatResource());
    Assert.assertEquals(1, deleted0);
    Assert.assertNotEquals(0, deleted3);
    dbInstance.commitAndCloseSession();
    // retrieve new list
    List<VideoMetaImpl> deleteMetadata = videoMetadataDao.getAllVideoResourcesMetadata();
    Assert.assertFalse(deleteMetadata.contains(meta0));
    Assert.assertTrue(deleteMetadata.contains(meta1));
    Assert.assertTrue(deleteMetadata.contains(meta2));
    Assert.assertFalse(deleteMetadata.contains(meta3));
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) VideoMetaImpl(org.olat.modules.video.model.VideoMetaImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 3 with VideoMetaImpl

use of org.olat.modules.video.model.VideoMetaImpl in project openolat by klemens.

the class VideoMetadataDAO method createVideoMetadata.

/**
 * Creates and persists the video metadata.
 *
 * @param videoResource
 * @param size
 * @param filename
 * @return metadata
 */
VideoMetaImpl createVideoMetadata(RepositoryEntry repoEntry, long size, String fileName) {
    VideoMetaImpl videometa = new VideoMetaImpl();
    OLATResource videoResource = repoEntry.getOlatResource();
    videometa.setVideoResource(videoResource);
    String format = FilenameUtils.getExtension(fileName);
    videometa.setFormat(format);
    videometa.setCreationDate(new Date());
    videometa.setLastModified(new Date());
    Size resolution = videoManager.getVideoResolutionFromOLATResource(videoResource);
    videometa.setHeight(resolution.getHeight());
    videometa.setWidth(resolution.getWidth());
    videometa.setSize(size);
    videometa.setLength(repoEntry.getExpenditureOfWork());
    dbInstance.getCurrentEntityManager().persist(videometa);
    return videometa;
}
Also used : Size(org.olat.core.commons.services.image.Size) VideoMetaImpl(org.olat.modules.video.model.VideoMetaImpl) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date)

Example 4 with VideoMetaImpl

use of org.olat.modules.video.model.VideoMetaImpl in project OpenOLAT by OpenOLAT.

the class VideoMetadataDAOTest method deleteVideoMetadata.

@Test
public void deleteVideoMetadata() {
    RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry3 = JunitTestHelper.createAndPersistRepositoryEntry();
    // create metadata entries
    VideoMeta meta0 = videoMetadataDao.createVideoMetadata(entry0, 1500, "vid.mp4");
    VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1100, "vide.mp4");
    VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 1200, "video.mov");
    VideoMeta meta3 = videoMetadataDao.createVideoMetadata(entry3, 4500, "videos.mp4");
    Assert.assertNotNull(meta1);
    Assert.assertNotNull(meta3);
    Assert.assertNotNull(meta2);
    Assert.assertNotNull(meta0);
    dbInstance.commitAndCloseSession();
    // retrieve list of entries
    List<VideoMetaImpl> metadata = videoMetadataDao.getAllVideoResourcesMetadata();
    Assert.assertTrue(metadata.contains(meta0));
    Assert.assertTrue(metadata.contains(meta1));
    Assert.assertTrue(metadata.contains(meta2));
    Assert.assertTrue(metadata.contains(meta3));
    // delete entries
    int deleted0 = videoMetadataDao.deleteVideoMetadata(entry0.getOlatResource());
    int deleted3 = videoMetadataDao.deleteVideoMetadata(entry3.getOlatResource());
    Assert.assertEquals(1, deleted0);
    Assert.assertNotEquals(0, deleted3);
    dbInstance.commitAndCloseSession();
    // retrieve new list
    List<VideoMetaImpl> deleteMetadata = videoMetadataDao.getAllVideoResourcesMetadata();
    Assert.assertFalse(deleteMetadata.contains(meta0));
    Assert.assertTrue(deleteMetadata.contains(meta1));
    Assert.assertTrue(deleteMetadata.contains(meta2));
    Assert.assertFalse(deleteMetadata.contains(meta3));
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) VideoMetaImpl(org.olat.modules.video.model.VideoMetaImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 5 with VideoMetaImpl

use of org.olat.modules.video.model.VideoMetaImpl in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_11_3_0 method processVideoResource.

private boolean processVideoResource(RepositoryEntry entry) {
    try {
        OLATResource videoResource = entry.getOlatResource();
        if (!videoManager.hasMasterContainer(videoResource)) {
            log.error("RepoEntry: " + entry.getKey() + " has no valid master container.");
            // log error but return true to proceed
            return true;
        }
        // update track files on file system
        VFSContainer masterContainer = videoManager.getMasterContainer(videoResource);
        if (videoManager.isMetadataFileValid(videoResource)) {
            VideoMetadata metafromXML = videoManager.readVideoMetadataFile(videoResource);
            for (Entry<String, String> track : metafromXML.getAllTracks().entrySet()) {
                VFSItem item = masterContainer.resolve(track.getValue());
                if (item != null && item instanceof VFSLeaf) {
                    String path = VideoManagerImpl.TRACK + track.getKey() + VideoManagerImpl.DOT + FilenameUtils.getExtension(track.getValue());
                    // check if modified track file already exists
                    if (masterContainer.resolve(path) == null) {
                        VFSLeaf target = masterContainer.createChildLeaf(path);
                        VFSManager.copyContent((VFSLeaf) item, target);
                    }
                }
            }
        } else {
            log.error("RepoEntry: " + entry.getKey() + " has no valid Video Metadata XML file.");
        }
        // create meta data entries on database
        if (videoManager.hasVideoFile(videoResource)) {
            File videoFile = videoManager.getVideoFile(videoResource);
            String fileName = videoFile.getName();
            long size = videoFile.length();
            String format = FilenameUtils.getExtension(fileName);
            if (videoManager.hasVideoMetadata(videoResource)) {
                VideoMetaImpl entity = new VideoMetaImpl();
                entity.setVideoResource(videoResource);
                entity.setFormat(format);
                entity.setCreationDate(new Date());
                entity.setLastModified(new Date());
                Size resolution = videoManager.getVideoResolutionFromOLATResource(videoResource);
                entity.setHeight(resolution.getHeight());
                entity.setWidth(resolution.getWidth());
                entity.setSize(size);
                entity.setLength(entry.getExpenditureOfWork());
                dbInstance.getCurrentEntityManager().persist(entity);
            }
        } else {
            log.error("RepoEntry: " + entry.getKey() + " has no valid resource.");
        }
        return true;
    } catch (Exception e) {
        log.error("Update Metadata failed", e);
        return false;
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) VFSItem(org.olat.core.util.vfs.VFSItem) VideoMetadata(org.olat.modules.video.VideoMetadata) Date(java.util.Date) VideoMetaImpl(org.olat.modules.video.model.VideoMetaImpl) File(java.io.File)

Aggregations

VideoMetaImpl (org.olat.modules.video.model.VideoMetaImpl)6 Date (java.util.Date)4 Size (org.olat.core.commons.services.image.Size)4 OLATResource (org.olat.resource.OLATResource)4 File (java.io.File)2 Test (org.junit.Test)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 VideoMeta (org.olat.modules.video.VideoMeta)2 VideoMetadata (org.olat.modules.video.VideoMetadata)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2