All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.structr.media.GetMetadataProcess Maven / Gradle / Ivy

Go to download

Structr is an open source framework based on the popular Neo4j graph database.

The newest version!
/**
 * Copyright (C) 2010-2016 Structr GmbH
 *
 * This file is part of Structr .
 *
 * Structr is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Structr is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Structr.  If not, see .
 */
package org.structr.media;

import org.structr.util.AbstractProcess;
import java.io.IOException;
import java.io.StringReader;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.structr.common.SecurityContext;
import org.structr.web.entity.VideoFile;

/**
 *
 *
 */

public class GetMetadataProcess extends AbstractProcess> {

	private static final Logger logger = Logger.getLogger(GetMetadataProcess.class.getName());

	private VideoFile inputVideo = null;

	public GetMetadataProcess(final SecurityContext securityContext, final VideoFile inputVideo) {

		super(securityContext);

		this.inputVideo = inputVideo;
	}

	@Override
	public void preprocess() {
	}

	@Override
	public StringBuilder getCommandLine() {

		StringBuilder commandLine = new StringBuilder("avconv -y -loglevel quiet -i ");

		// build command line from builder options
		commandLine.append(inputVideo.getDiskFilePath(securityContext));
		commandLine.append(" -f ffmetadata -");

		return commandLine;
	}

	@Override
	public Map processExited(int exitCode) {

		if (exitCode == 0) {

			final Map map = new LinkedHashMap<>();
			final Properties properties   = new Properties();

			try {
				properties.load(new StringReader(outputStream()));

				// convert entries to 
				for (final Entry entry : properties.entrySet()) {

					final String key   = entry.getKey().toString();
					final String value = entry.getValue().toString();

					if (accept(key, value)) {
						map.put(key, value);
					}
				}

			} catch (IOException ioex) {
				logger.log(Level.WARNING, "", ioex);
			}

			return map;
		}

		return null;
	}

	protected boolean accept(final String key, final String value) {
		return key != null && !key.startsWith(";");
	}
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy