Parser parser = new Parser();
- NullParameter recursiveParameter = parser.createNullParameter(
- "Enable recursive mode.").addAliases("-r", "--recursive");
+ NullParameter recursiveParameter = parser.add(
+ new NullParameter("Enable recursive mode.")).addAliases("-r",
+ "--recursive");
- StringParameters inputPatternParameter = parser.createStringParameters(
- "File input pattern.").addAliases("-i", "--input-pattern");
+ StringParameters inputPatternParameter = parser.add(
+ new StringParameters("File input pattern.")).addAliases("-i",
+ "--input-pattern");
DirectoryParameter workingDirectoryParameter = parser
- .createDirectoryParameter("Working directory.")
+ .add(new DirectoryParameter("Working directory."))
.addAliases("-w", "--working-directory").mustExist();
- public Parser initParser() {
-
- final Parser parser = new Parser();
- parser.addParameter(recursiveParameter);
- parser.addParameter(inputPatternParameter);
- parser.addParameter(workingDirectoryParameter);
-
- return parser;
- }
-
public BomStrippingOptions parseCommandlineArguments(final String[] args) {
final BomStrippingOptions options = new BomStrippingOptions();
- final Parser parser = initParser();
if (!parser.parse(args))
return null;
@Override
public void showCommandlineHelp() {
- commandlineHandler.initParser().showHelp();
+ commandlineHandler.parser.showHelp();
}
public void stripFileFromHeader(final File file)
import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-public class BitrateParameter extends Parameter {
+public class BitrateParameter extends Parameter<BitrateParameter> {
static public enum bitrate {
LOW, MEDIUM, HIGH, COPY
super(description, ArgumentCount.SINGLE);
}
- @Override
- public BitrateParameter addAliases(final String... aliasArray) {
- addAliasesProtected(aliasArray);
- return this;
- }
-
@Override
public String describeFormat() {
return "Target bitrate [LOW / MEDIUM / HIGH / COPY]";
return bitrate.valueOf(arguments.get(0).toUpperCase());
}
- @Override
- public BitrateParameter setMandatory() {
- setMandatoryProtected();
- return this;
- }
-
@Override
public boolean validate(final String value) {
try {
Parser parser = new Parser();
StringParameters outputFormatParameter = parser
- .createStringParameters("Encoding output format.")
+ .add(new StringParameters("Encoding output format."))
.addAliases("-o", "--output-format").setMandatory();
- NullParameter deinterlaceParameter = parser.createNullParameter(
- "Deinterlace video.").addAliases("--deinterlace", "-d");
+ NullParameter deinterlaceParameter = parser.add(
+ new NullParameter("Deinterlace video.")).addAliases(
+ "--deinterlace", "-d");
- NullParameter testParameter = parser.createNullParameter(
- "Simulate file encoding.").addAliases("-t", "--test");
+ NullParameter testParameter = parser.add(
+ new NullParameter("Simulate file encoding.")).addAliases("-t",
+ "--test");
- NullParameter recursiveParameter = parser.createNullParameter(
- "Enable recursive mode.").addAliases("-r", "--recursive");
+ NullParameter recursiveParameter = parser.add(
+ new NullParameter("Enable recursive mode.")).addAliases("-r",
+ "--recursive");
- NullParameter forPortableParameter = parser.createNullParameter(
- "Encode for portable player.").addAliases("-p", "--portable");
+ NullParameter forPortableParameter = parser.add(
+ new NullParameter("Encode for portable player.")).addAliases("-p",
+ "--portable");
StringParameters inputPatternParameter = parser
- .createStringParameters("File input pattern.")
+ .add(new StringParameters("File input pattern."))
.addAliases("-i", "--input-pattern").setMandatory();
DirectoryParameter workingDirectoryParameter = parser
- .createDirectoryParameter("Working directory.")
+ .add(new DirectoryParameter("Working directory."))
.addAliases("-w", "--working-directory").mustExist();
- BitrateParameter videoBitrateParameter = new BitrateParameter(
- "Video bitrate");
+ BitrateParameter videoBitrateParameter = parser.add(
+ new BitrateParameter("Video bitrate")).addAliases("-v",
+ "--video-bitrate");
- public CommandlineHandler() {
- videoBitrateParameter.addAliases("-v", "--video-bitrate");
- parser.addParameter(videoBitrateParameter);
- }
+ BitrateParameter audioBitrateParameter = parser.add(
+ new BitrateParameter("Audio bitrate")).addAliases("-a",
+ "--audio-bitrate");
/**
* @return {@link EncodingOptions} if commandline arguments were
if (videoBitrateParameter.isParameterSpecified())
try {
- options.videoBitrate = videoBitrateParameter.getValue();
+ options.setVideoBitrate(videoBitrateParameter.getValue());
} catch (final Exception e) {
System.out
.println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH.");
/*
* 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.
public class EncodingOptions {
- public BitrateParameter.bitrate videoBitrate = BitrateParameter.bitrate.MEDIUM;
+ private BitrateParameter.bitrate videoBitrate = BitrateParameter.bitrate.MEDIUM;
+
+ private BitrateParameter.bitrate audioBitrate = BitrateParameter.bitrate.MEDIUM;
// public Bitrate audioBitrate;
List<String> inputPatterns = new ArrayList<String>();
+ public BitrateParameter.bitrate getAudioBitrate() {
+ return audioBitrate;
+ }
+
+ public BitrateParameter.bitrate getVideoBitrate() {
+ return videoBitrate;
+ }
+
+ public void setAudioBitrate(final BitrateParameter.bitrate audioBitrate) {
+ this.audioBitrate = audioBitrate;
+ }
+
+ public void setVideoBitrate(final BitrateParameter.bitrate videoBitrate) {
+ this.videoBitrate = videoBitrate;
+ }
+
}
int videoBitrate = -1;
int audioBitrate = -1;
- switch (options.videoBitrate) {
+ switch (options.getVideoBitrate()) {
case LOW:
videoBitrate = 1000;
audioBitrate = 128;
break;
default:
- throw new RuntimeException("Video bitrate: " + options.videoBitrate
+ throw new RuntimeException("Video bitrate: " + options.getVideoBitrate()
+ " is not supported.");
}
String videoCodec = "libx264";
String audioCodec = "libmp3lame";
- if (options.videoBitrate == bitrate.COPY) {
+ if (options.getVideoBitrate() == bitrate.COPY) {
videoCodec = "copy";
audioCodec = "copy";
}
codecParams, videoCodec, audioCodec);
return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
- + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
- + "\"";
+ + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
+ + "\"";
}
@Override
@Override
public List<String> getTargetFileExtensions() {
- return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob");
+ return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v");
}
@Override
}
final EncodingOptions options = new EncodingOptions();
- options.videoBitrate = BitrateParameter.bitrate.COPY;
+ options.setVideoBitrate(BitrateParameter.bitrate.COPY);
encodingPlan.execute(options);
}
/*
* 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.
Parser parser = new Parser();
- StringParameter galleryNameParameter = parser.createStringParameter(
- "Gallery title. (default is: " + Constants.DEFAULT_GALLERY_TITLE
- + ").").addAliases("-t", "--gallery-title");
+ StringParameter galleryNameParameter = parser.add(
+ new StringParameter("Gallery title. (default is: "
+ + Constants.DEFAULT_GALLERY_TITLE + ").")).addAliases("-t",
+ "--gallery-title");
DirectoryParameter workingDirectoryParameter = parser
- .createDirectoryParameter("Working directory.")
+ .add(new DirectoryParameter("Working directory."))
.addAliases("-w", "--working-directory").mustExist();
- NullParameter removeIndex = parser.createNullParameter(
- "Remove generated index").addAliases("-r", "--remove");
+ NullParameter removeIndex = parser.add(
+ new NullParameter("Remove generated index")).addAliases("-r",
+ "--remove");
public String getGalleryTitle() {
if (galleryNameParameter.isParameterSpecified())
Parser parser = new Parser();
- NullParameter recursiveParameter = parser.createNullParameter(
- "Enable recursive mode.").addAliases("-r", "--recursive");
+ NullParameter recursiveParameter = parser.add(
+ new NullParameter("Enable recursive mode.")).addAliases("-r",
+ "--recursive");
- NullParameter testParameter = parser.createNullParameter(
- "Simulate renaming (no changes will be actually done).")
+ NullParameter testParameter = parser.add(
+ new NullParameter(
+ "Simulate renaming (no changes will be actually done)."))
.addAliases("-t", "--test");
- StringParameter outputPatternParameter = parser.createStringParameter(
- "Output pattern.").addAliases("-o", "--output-pattern");
+ StringParameter outputPatternParameter = parser.add(
+ new StringParameter("Output pattern.")).addAliases("-o",
+ "--output-pattern");
- StringParameters inputPatternParameter = parser.createStringParameters(
- "File input pattern.").addAliases("-i", "--input-pattern");
+ StringParameters inputPatternParameter = parser.add(
+ new StringParameters("File input pattern.")).addAliases("-i",
+ "--input-pattern");
DirectoryParameter workingDirectoryParameter = parser
- .createDirectoryParameter("Working directory.")
+ .add(new DirectoryParameter("Working directory."))
.addAliases("-w", "--working-directory").mustExist();
/**
/*
* 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.
Parser parser = new Parser();
- NullParameter recursiveParameter = parser.createNullParameter(
- "Enable recursive mode.").addAliases("-r", "--recursive");
+ NullParameter recursiveParameter = parser.add(
+ new NullParameter("Enable recursive mode.")).addAliases("-r",
+ "--recursive");
StringParameter searchForPattern = parser
- .createStringParameter("String to search for")
+ .add(new StringParameter("String to search for"))
.addAliases("-s", "--search-pattern").setMandatory();
- StringParameter replaceWithPattern = parser.createStringParameter(
- "String to place instead").addAliases("-p", "--replace-pattern");
+ StringParameter replaceWithPattern = parser.add(
+ new StringParameter("String to place instead")).addAliases("-p",
+ "--replace-pattern");
DirectoryParameter directoryParameter = parser
- .createDirectoryParameter("Working directory.")
+ .add(new DirectoryParameter("Working directory."))
.addAliases("-w", "--working-directory").mustExist();
public CommandlineOptions parseCommandlineArguments(final String[] args) {
Parser parser = new Parser();
- NullParameter recursiveParameter = parser.createNullParameter(
- "Enable recursive mode.").addAliases("-r", "--recursive");
+ NullParameter recursiveParameter = parser.add(
+ new NullParameter("Enable recursive mode.")).addAliases("-r",
+ "--recursive");
- StringParameters fileInputPatternsParameter = parser
- .createStringParameters("File input pattern.")
- .addAliases("-i", "--input-pattern").setMandatory();
+ StringParameters fileInputPatternsParameter = parser.add(
+ new StringParameters("File input pattern.").addAliases("-i",
+ "--input-pattern")).setMandatory();
StringParameters splitPatternsParameter = parser
- .createStringParameters("File split regular expression.")
+ .add(new StringParameters("File split regular expression."))
.addAliases("-s", "--split-pattern").setMandatory();
- DirectoryParameter workingDirectoryParameter = parser
- .createDirectoryParameter("Working directory.").addAliases("-w",
- "--working-directory");
+ DirectoryParameter workingDirectoryParameter = parser.add(
+ new DirectoryParameter("Working directory.")).addAliases("-w",
+ "--working-directory");
public TextSplittingOptions parseCommandlineArguments(final String[] args) {
Parser parser = new Parser();
- NullParameter recursiveParameter = parser.createNullParameter(
- "Enable recursive mode.").addAliases("-r", "--recursive");
+ NullParameter recursiveParameter = parser.add(
+ new NullParameter("Enable recursive mode.")).addAliases("-r",
+ "--recursive");
- StringParameters inputPatternParameter = parser.createStringParameters(
- "File input pattern.").addAliases("-i", "--input-pattern");
+ StringParameters inputPatternParameter = parser.add(
+ new StringParameters("File input pattern.")).addAliases("-i",
+ "--input-pattern");
- DirectoryParameter workingDirectoryParameter = parser
- .createDirectoryParameter("Working directory.").addAliases("-w",
- "--working-directory");
+ DirectoryParameter workingDirectoryParameter = parser.add(
+ new DirectoryParameter("Working directory.")).addAliases("-w",
+ "--working-directory");
public TextTruncatingOptions parseCommandlineArguments(final String[] args) {