From 0a7c6bdea0eb481cab530d6168c5c1a8d942c012 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 29 Oct 2013 18:51:08 +0200 Subject: [PATCH] updated commandline handler --- .../eu/svjatoslav/meviz/encoder/Bitrate.java | 35 --------------- .../meviz/encoder/BitrateParameter.java | 44 +++++++++++++++++++ .../meviz/encoder/CommandlineHandler.java | 32 +++----------- .../eu/svjatoslav/meviz/encoder/Encoder.java | 2 +- .../meviz/encoder/EncodingOptions.java | 2 +- 5 files changed, 51 insertions(+), 64 deletions(-) delete mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/Bitrate.java create mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/Bitrate.java b/src/main/java/eu/svjatoslav/meviz/encoder/Bitrate.java deleted file mode 100755 index fb1481d..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/Bitrate.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Meviz - Various tools collection to work with multimedia. - * Copyright (C) 2012, 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. - */ - -package eu.svjatoslav.meviz.encoder; - -import eu.svjatoslav.commons.commandline.parameterparser.Argument; - -public class Bitrate implements Argument { - @Override - public String describeFormat() { - return "Target bitrate [LOW / MEDIUM / HIGH]"; - } - - @Override - public boolean validate(final String value) { - try { - bitrate.valueOf(value); - } catch (final IllegalArgumentException exception) { - return false; - } - - return true; - } - - static public enum bitrate { - LOW, MEDIUM, HIGH - }; - -} diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java b/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java new file mode 100755 index 0000000..3ab0fe1 --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java @@ -0,0 +1,44 @@ +/* + * Meviz - Various tools collection to work with multimedia. + * Copyright (C) 2012, 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. + */ + +package eu.svjatoslav.meviz.encoder; + +import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount; +import eu.svjatoslav.commons.commandline.parameterparser.Parameter; + +public class BitrateParameter extends Parameter { + + public BitrateParameter(String description) { + super(description, ArgumentCount.SINGLE); + } + + @Override + public String describeFormat() { + return "Target bitrate [LOW / MEDIUM / HIGH]"; + } + + @Override + public boolean validate(final String value) { + try { + bitrate.valueOf(value); + } catch (final IllegalArgumentException exception) { + return false; + } + + return true; + } + + static public enum bitrate { + LOW, MEDIUM, HIGH + }; + + public bitrate getValue() { + return bitrate.valueOf(getArgumentsAsStrings().get(0).toUpperCase()); + } +} diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index 9b32ebd..870d476 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -9,7 +9,6 @@ package eu.svjatoslav.meviz.encoder; -import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter; @@ -43,30 +42,12 @@ public class CommandlineHandler { .createDirectoryParameter("Working directory.") .addAliases("-w", "--working-directory").mustExist(); - Parameter videoBitrateParameter = parser.createCustomParameter( - new Bitrate(), "Video bitrate.") - .addAliases("-v", "--video-bitrate"); - - public Parser initParser() { - final Parser parser = new Parser(); - - parser.addParameter(recursiveParameter); - - parser.addParameter(deinterlaceParameter); - - parser.addParameter(testParameter); - - parser.addParameter(terminalParameter); - - parser.addParameter(outputFormatParameter); - - parser.addParameter(inputPatternParameter); - - parser.addParameter(workingDirectoryParameter); + BitrateParameter videoBitrateParameter = new BitrateParameter( + "Video bitrate"); + public CommandlineHandler() { + videoBitrateParameter.addAliases("-v", "--video-bitrate"); parser.addParameter(videoBitrateParameter); - - return parser; } /** @@ -78,7 +59,6 @@ public class CommandlineHandler { final EncodingOptions options = new EncodingOptions(); - final Parser parser = initParser(); parser.parse(args); if (recursiveParameter.isParameterSpecified()) @@ -107,9 +87,7 @@ public class CommandlineHandler { if (videoBitrateParameter.isParameterSpecified()) try { - options.videoBitrate = Bitrate.bitrate - .valueOf(videoBitrateParameter.getArgumentsAsStrings() - .get(0).toUpperCase()); + options.videoBitrate = videoBitrateParameter.getValue(); } catch (final Exception e) { System.out .println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH."); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java index 3b2f043..420fa49 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java @@ -166,7 +166,7 @@ public class Encoder implements Module { @Override public void showCommandlineHelp() { - commandlineHandler.initParser().showHelp(); + commandlineHandler.parser.showHelp(); System.out.println("Example commands:"); System.out .println(" Convert all MTS files in the current directory into MP4's."); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java index a2f09d8..9f14546 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java @@ -15,7 +15,7 @@ import java.util.List; public class EncodingOptions { - public Bitrate.bitrate videoBitrate = Bitrate.bitrate.MEDIUM; + public BitrateParameter.bitrate videoBitrate = BitrateParameter.bitrate.MEDIUM; // public Bitrate audioBitrate; -- 2.20.1