.createStringParameter("Encoding output format.")
.addAliases("-o", "--output-format").setMandatory();
- NullParameter terminalParameter = parser.createNullParameter(
- "Enable popup terminal.").addAliases("--terminal");
-
NullParameter deinterlaceParameter = parser.createNullParameter(
"Deinterlace video.").addAliases("--deinterlace", "-d");
if (deinterlaceParameter.isParameterSpecified())
options.deinterlace = true;
- if (terminalParameter.isParameterSpecified())
- options.terminal = true;
-
if (testParameter.isParameterSpecified())
options.testOnly = true;
public class EncodingPlan {
- public ArrayList<EncodingTask> encodingTasks = new ArrayList<EncodingTask>();
+ public ArrayList<EncodingTask> encodingTasks = new ArrayList<EncodingTask>();
- public void execute(final EncodingOptions encodingOptions) throws IOException {
- for (final EncodingTask task : encodingTasks) {
+ public void execute(final EncodingOptions encodingOptions)
+ throws IOException {
- try {
- String command = task.getCommand(encodingOptions);
+ for (final EncodingTask task : encodingTasks)
+ task.execute(encodingOptions);
- if (task.doUseTerminal()) {
- command = "xterm -e '" + 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();
- }
-
- }
-
- }
-
- public void scheduleTask(final EncodingTask encodingTask) {
- encodingTasks.add(encodingTask);
- };
+ public void scheduleTask(final EncodingTask encodingTask) {
+ encodingTasks.add(encodingTask);
+ };
}
public class EncodingTask {
- /**
- * Source file to encode
- */
- private final File source;
-
- /**
- * Target file.
- */
- private final File target;
-
- private final Converter converter;
-
- private boolean useTerminal;
-
- public EncodingTask(final File source, final File destination,
- final eu.svjatoslav.meviz.encoder.converters.Converter converter) {
-
- this.source = source;
- target = destination;
- this.converter = converter;
-
- }
-
- /**
- * @return the useTerminal
- */
- public boolean doUseTerminal() {
- return useTerminal;
- }
-
- public String getCommand(final EncodingOptions encodingOptions) {
- return converter.getCommand(source, target, encodingOptions);
- }
-
- /**
- * @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 Converter converter;
+
+ private boolean useTerminal;
+
+ public EncodingTask(final File source, final File destination,
+ final eu.svjatoslav.meviz.encoder.converters.Converter 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();
+ }
+
+ }
+
+ public String getCommand(final EncodingOptions encodingOptions) {
+ return converter.getCommand(source, target, encodingOptions);
+ }
+
+ /**
+ * @param useTerminal
+ * the useTerminal to set
+ */
+ public void setUseTerminal(final boolean useTerminal) {
+ this.useTerminal = useTerminal;
+ }
}