package ca.carleton.gcrc.olkit.multimedia.utils;

import java.util.Properties;

import ca.carleton.gcrc.olkit.multimedia.ffmpeg.FFmpegProcessorDefault;
import ca.carleton.gcrc.olkit.multimedia.imageMagick.ImageMagickProcessorDefault;

public class MultimediaConfiguration {

	static public void configureFromProperties(Properties props) {
		// FFMpeg
		{
			String command = props.getProperty("ffmpegInfoCommand", null);
			if( null != command ) {
				FFmpegProcessorDefault.ffmpegInfoCommand = command;
			}
		}
		{
			String command = props.getProperty("ffmpegConvertVideoCommand", null);
			if( null != command ) {
				FFmpegProcessorDefault.ffmpegConvertVideoCommand = command;
			}
		}
		{
			String command = props.getProperty("ffmpegConvertAudioCommand", null);
			if( null != command ) {
				FFmpegProcessorDefault.ffmpegConvertAudioCommand = command;
			}
		}
		{
			String command = props.getProperty("ffmpegCreateThumbnailCommand", null);
			if( null != command ) {
				FFmpegProcessorDefault.ffmpegCreateThumbnailCommand = command;
			}
		}

		// ImageMagick
		{
			String command = props.getProperty("imageInfoCommand", null);
			if( null != command ) {
				ImageMagickProcessorDefault.imageInfoCommand = command;
			}
		}
		{
			String command = props.getProperty("imageConvertCommand", null);
			if( null != command ) {
				ImageMagickProcessorDefault.imageConvertCommand = command;
			}
		}
		{
			String command = props.getProperty("imageResizeCommand", null);
			if( null != command ) {
				ImageMagickProcessorDefault.imageResizeCommand = command;
			}
		}

		// Known MIME types
		{
			String typeString = props.getProperty("imageMimeTypes", null);
			if( null != typeString ) {
				String[] types = typeString.split(":");
				for(String type : types) {
					MimeUtils.addKnownImageMimeType(type.trim());
				}
			}
		}
		{
			String typeString = props.getProperty("audioMimeTypes", null);
			if( null != typeString ) {
				String[] types = typeString.split(";");
				for(String type : types) {
					MimeUtils.addKnownAudioMimeType(type.trim());
				}
			}
		}
		{
			String typeString = props.getProperty("videoMimeTypes", null);
			if( null != typeString ) {
				String[] types = typeString.split(";");
				for(String type : types) {
					MimeUtils.addKnownVideoMimeType(type.trim());
				}
			}
		}
	}
}
