001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021package org.nuxeo.ecm.platform.video.convert; 022 023import java.util.List; 024import java.util.regex.Matcher; 025import java.util.regex.Pattern; 026 027import org.nuxeo.common.utils.StringUtils; 028import org.nuxeo.ecm.core.convert.api.ConversionException; 029import org.nuxeo.ecm.platform.commandline.executor.api.CommandLineExecutorService; 030 031/** 032 * Factorize common code for video converter implementations. 033 * 034 * @author ogrisel 035 */ 036public abstract class BaseVideoConverter { 037 038 protected static final Pattern DURATION_PATTERN = Pattern.compile("Duration: (\\d\\d):(\\d\\d):(\\d\\d)\\.(\\d+)"); 039 040 /** 041 * @deprecated since 5.5. The duration is now extracted with the other information stored in the VideoInfo. 042 */ 043 @Deprecated 044 protected static Double extractDuration(List<String> output) throws ConversionException { 045 for (String line : output) { 046 Matcher matcher = DURATION_PATTERN.matcher(line); 047 if (matcher.find()) { 048 return Double.parseDouble(matcher.group(1)) * 3600 + Double.parseDouble(matcher.group(2)) * 60 049 + Double.parseDouble(matcher.group(3)) + Double.parseDouble(matcher.group(3)) / 100; 050 } 051 } 052 // could not find the duration 053 throw new ConversionException("failed to extract the duration from output: " + StringUtils.join(output, " ")); 054 } 055 056 /** 057 * @deprecated since 5.5. 058 */ 059 @Deprecated 060 public static String quoteFilePath(String filePath) { 061 return String.format("\"%s\"", filePath); 062 } 063 064}