X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=meviz.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fmeviz%2Fencoder%2FEncodingTask.java;h=ae7e8a07eca9d0209e891c39c65e56aa16943183;hp=535f8f7c897e4222a2af8705fe0b4b139d4cb59f;hb=cf6e4ace4972f24f40f88ea12fcf99c763e4e40a;hpb=565d9c726de9b50709027f9455d39499a17f4b25 diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java index 535f8f7..ae7e8a0 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java @@ -1,7 +1,7 @@ /* * Meviz - Various tools collection to work with multimedia. - * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * Copyright (C) 2012 -- 2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. @@ -9,87 +9,85 @@ package eu.svjatoslav.meviz.encoder; -import java.io.File; - import eu.svjatoslav.meviz.encoder.converters.AbstractConverter; -public class EncodingTask { - - /** - * Source file to encode - */ - private final File source; - - /** - * Target file. - */ - private final File target; - - private final AbstractConverter converter; - - private boolean useTerminal; - - public EncodingTask(final File source, final File destination, - final eu.svjatoslav.meviz.encoder.converters.AbstractConverter converter) { - - this.source = source; - target = destination; - this.converter = converter; - - } - - /** - * @return the useTerminal - */ - public boolean doUseTerminal() { - return useTerminal; - } - - public String encodeApostrophes(final String input) { - final StringBuffer result = new StringBuffer(); - - for (final char c : input.toCharArray()) { - if (c == '\'') { - result.append("'\\''"); - continue; - } - result.append(c); - } - - return result.toString(); - } - - public void execute(final EncodingOptions encodingOptions) { - try { - String command = getCommand(encodingOptions); - - if (doUseTerminal()) - command = "xterm -e '" + encodeApostrophes(command) + "'"; - - System.out.println("Executing command: " + command); - - final Runtime run = Runtime.getRuntime(); - Process pr; - pr = run.exec(new String[] { "/bin/bash", "-c", command }); - - pr.waitFor(); - - } catch (final Exception e) { - System.out.println(e.toString()); - e.printStackTrace(); - } - - } +import java.io.File; - public String getCommand(final EncodingOptions encodingOptions) { - return converter.getCommand(source, target, encodingOptions); - } +public class EncodingTask { - /** - * @param useTerminal - * the useTerminal to set - */ - public void setUseTerminal(final boolean useTerminal) { - this.useTerminal = useTerminal; - } + /** + * Source file to encode + */ + private final File source; + + /** + * Target file. + */ + private final File target; + + private final AbstractConverter converter; + private final String targetFormat; + private boolean useTerminal; + + public EncodingTask(final File source, final File target, final AbstractConverter converter, + final String targetFormat) { + + this.source = source; + this.target = target; + this.converter = converter; + this.targetFormat = targetFormat; + } + + /** + * @return the useTerminal + */ + private boolean doUseTerminal() { + return useTerminal; + } + + private String encodeApostrophes(final String input) { + final StringBuilder result = new StringBuilder(); + + for (final char c : input.toCharArray()) { + if (c == '\'') { + result.append("'\\''"); + continue; + } + result.append(c); + } + + return result.toString(); + } + + public void execute(final EncodingOptions encodingOptions) { + try { + String command = getCommand(encodingOptions); + + if (doUseTerminal()) + command = "xterm -e '" + encodeApostrophes(command) + "'"; + + System.out.println("Executing command: " + command); + + final Runtime runtime = Runtime.getRuntime(); + final Process process = runtime.exec(new String[]{"/bin/bash", "-c", command}); + + process.waitFor(); + + } catch (final Exception e) { + System.out.println(e.toString()); + e.printStackTrace(); + } + + } + + private String getCommand(final EncodingOptions encodingOptions) { + return converter.getCommand(source, target, encodingOptions, targetFormat); + } + + /** + * @param useTerminal the useTerminal to set + */ + public void setUseTerminal(final boolean useTerminal) { + this.useTerminal = useTerminal; + } }