001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger 016 */ 017 018package org.nuxeo.ecm.platform.video.rendition; 019 020import java.util.ArrayList; 021import java.util.Collections; 022import java.util.List; 023 024import org.nuxeo.ecm.core.api.Blob; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeEntry; 027import org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeRegistry; 028import org.nuxeo.ecm.platform.rendition.service.RenditionDefinition; 029import org.nuxeo.ecm.platform.rendition.service.RenditionDefinitionProvider; 030import org.nuxeo.ecm.platform.video.TranscodedVideo; 031import org.nuxeo.ecm.platform.video.VideoDocument; 032import org.nuxeo.ecm.platform.video.service.VideoConversion; 033import org.nuxeo.ecm.platform.video.service.VideoService; 034import org.nuxeo.runtime.api.Framework; 035 036/** 037 * Provides rendition definitions based on the existing transcoded videos. 038 * 039 * @since 7.2 040 */ 041public class VideoRenditionDefinitionProvider implements RenditionDefinitionProvider { 042 043 public static final String VIDEO_RENDITION_KIND = "nuxeo:video:conversion"; 044 045 @Override 046 public List<RenditionDefinition> getRenditionDefinitions(DocumentModel doc) { 047 VideoDocument videoDocument = doc.getAdapter(VideoDocument.class); 048 if (videoDocument == null) { 049 return Collections.emptyList(); 050 } 051 052 List<RenditionDefinition> renditionDefinitions = new ArrayList<>(); 053 MimetypeRegistry mimetypeRegistry = Framework.getService(MimetypeRegistry.class); 054 VideoService videoService = Framework.getService(VideoService.class); 055 for (TranscodedVideo transcodedVideo : videoDocument.getTranscodedVideos()) { 056 VideoConversion videoConversion = videoService.getVideoConversion(transcodedVideo.getName()); 057 if (videoConversion != null && videoConversion.isRendition()) { 058 Blob blob = transcodedVideo.getBlob(); 059 if (blob != null) { 060 RenditionDefinition renditionDefinition = new RenditionDefinition(); 061 renditionDefinition.setEnabled(true); 062 renditionDefinition.setName(transcodedVideo.getName()); 063 renditionDefinition.setKind(VIDEO_RENDITION_KIND); 064 renditionDefinition.setProvider(new VideoRenditionProvider()); 065 renditionDefinition.setVisible(videoConversion.isRenditionVisible()); 066 renditionDefinition.setLabel(transcodedVideo.getName()); 067 MimetypeEntry mimeType = mimetypeRegistry.getMimetypeEntryByMimeType(blob.getMimeType()); 068 renditionDefinition.setIcon("/icons/" + mimeType.getIconPath()); 069 renditionDefinitions.add(renditionDefinition); 070 } 071 } 072 } 073 return renditionDefinitions; 074 } 075 076}