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; 029/** 030 * Factorize common code for video converter implementations. 031 * 032 * @author ogrisel 033 */ 034public abstract class BaseVideoConverter { 035 036 protected static final Pattern DURATION_PATTERN = Pattern.compile("Duration: (\\d\\d):(\\d\\d):(\\d\\d)\\.(\\d+)"); 037 038 /** 039 * @deprecated since 5.5. The duration is now extracted with the other information stored in the VideoInfo. 040 */ 041 @Deprecated 042 protected static Double extractDuration(List<String> output) throws ConversionException { 043 for (String line : output) { 044 Matcher matcher = DURATION_PATTERN.matcher(line); 045 if (matcher.find()) { 046 return Double.parseDouble(matcher.group(1)) * 3600 + Double.parseDouble(matcher.group(2)) * 60 047 + Double.parseDouble(matcher.group(3)) + Double.parseDouble(matcher.group(3)) / 100; 048 } 049 } 050 // could not find the duration 051 throw new ConversionException("failed to extract the duration from output: " + StringUtils.join(output, " ")); 052 } 053 054 /** 055 * @deprecated since 5.5. 056 */ 057 @Deprecated 058 public static String quoteFilePath(String filePath) { 059 return String.format("\"%s\"", filePath); 060 } 061 062}