From 1323513e461d6210f253690e42a18a7d37da3fe8 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 9 Oct 2022 23:53:39 +0200 Subject: [PATCH] Adds ability to force-select specific audio and subtitle streams for the anime converter --- manifest.mf | 1 - .../net/knarcraft/ffmpegconverter/Main.java | 27 ++++++++++++++---- .../converter/AbstractConverter.java | 24 ++++++++++------ .../converter/AnimeConverter.java | 15 ++++++++-- .../converter/AudioConverter.java | 3 +- .../ffmpegconverter/converter/Converter.java | 1 + .../converter/WebVideoConverter.java | 7 +++-- .../parser/ConverterArgument.java | 23 ++++++++++----- .../parser/ConverterArgumentValue.java | 8 ------ .../parser/ConverterArgumentValueType.java | 28 +++++++++++++++++++ .../streams/AbstractStream.java | 1 + .../ffmpegconverter/streams/AudioStream.java | 7 ++++- .../ffmpegconverter/streams/StreamObject.java | 7 +++-- .../streams/SubtitleStream.java | 2 ++ .../ffmpegconverter/streams/VideoStream.java | 2 ++ .../ffmpegconverter/utility/FFMpegHelper.java | 2 ++ .../ffmpegconverter/utility/FileUtil.java | 1 + .../ffmpegconverter/utility/ListUtil.java | 2 ++ .../ffmpegconverter/utility/OutputUtil.java | 3 ++ .../ffmpegconverter/utility/Parser.java | 7 +++-- .../ffmpegconverter/utility/StringUtil.java | 2 ++ .../converter/AnimeConverterTest.java | 6 ++-- .../ffmpegconverter/utility/ParserTest.java | 14 +++++----- 23 files changed, 144 insertions(+), 49 deletions(-) delete mode 100644 src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java create mode 100644 src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValueType.java diff --git a/manifest.mf b/manifest.mf index 328e8e5..59499bc 100644 --- a/manifest.mf +++ b/manifest.mf @@ -1,3 +1,2 @@ Manifest-Version: 1.0 -X-COMMENT: Main-Class will be added automatically by build diff --git a/src/main/java/net/knarcraft/ffmpegconverter/Main.java b/src/main/java/net/knarcraft/ffmpegconverter/Main.java index 03ca7c0..caed55b 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/Main.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/Main.java @@ -20,6 +20,7 @@ import static net.knarcraft.ffmpegconverter.utility.Parser.tokenize; * The main class for starting the software */ class Main { + private static final String FFPROBE_PATH = "ffprobe"; //Can be just ffprobe if it's in the path private static final String FFMPEG_PATH = "ffmpeg"; //Can be just ffmpeg if it's in the path private static final Scanner READER = new Scanner(System.in, "UTF-8"); @@ -107,16 +108,19 @@ class Main { */ private static void animeConverter() throws IOException { OutputUtil.println("[Audio languages jpn,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if " + - "necessary true/false] [Prevent signs&songs subtitles true/false]\nYour input: "); - List input = readInput(4); + "necessary true/false] [Prevent signs&songs subtitles true/false] [Forced audio index 0-n] " + + "[Forced subtitle index 0-n]\nYour input: "); + List input = readInput(6); String[] audioLanguage = new String[]{"jpn", "0"}; String[] subtitleLanguage = new String[]{"eng", "0"}; boolean toStereo = true; boolean preventSigns = true; - if (input.size() > 0 && ListUtil.getListFromCommaSeparatedString(input.get(0)) != null) { + int forcedAudioIndex = -1; + int forcedSubtitleIndex = -1; + if (input.size() > 0) { audioLanguage = ListUtil.getListFromCommaSeparatedString(input.get(0)); } - if (input.size() > 1 && ListUtil.getListFromCommaSeparatedString(input.get(1)) != null) { + if (input.size() > 1) { subtitleLanguage = ListUtil.getListFromCommaSeparatedString(input.get(1)); } if (input.size() > 2) { @@ -125,7 +129,19 @@ class Main { if (input.size() > 3) { preventSigns = Boolean.parseBoolean(input.get(3)); } - converter = new AnimeConverter(FFPROBE_PATH, FFMPEG_PATH, audioLanguage, subtitleLanguage, toStereo, preventSigns); + try { + if (input.size() > 4) { + forcedAudioIndex = Integer.parseInt(input.get(4)); + } + if (input.size() > 5) { + forcedSubtitleIndex = Integer.parseInt(input.get(5)); + } + } catch (NumberFormatException exception) { + OutputUtil.println("Forced audio or subtitle index is not a number"); + return; + } + converter = new AnimeConverter(FFPROBE_PATH, FFMPEG_PATH, audioLanguage, subtitleLanguage, toStereo, + preventSigns, forcedAudioIndex, forcedSubtitleIndex); } @@ -184,4 +200,5 @@ class Main { } while (choice < min || choice > max); return choice; } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java index cbc40cd..549ab79 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java @@ -17,6 +17,7 @@ import java.util.List; * Implements all methods which can be useful for any implementation of a converter. */ public abstract class AbstractConverter implements Converter { + final boolean debug = false; private final String newExtension; String ffprobePath; @@ -85,7 +86,7 @@ public abstract class AbstractConverter implements Converter { } /** - * Sorts subtitle streams according to chosen languages and removes non matching languages + * Sorts subtitle streams according to chosen languages and removes non-matching languages * * @param streams

A list of streams to sort.

* @param languages

The languages chosen by the user.

@@ -115,7 +116,7 @@ public abstract class AbstractConverter implements Converter { public abstract String[] getValidFormats(); /** - * Reads streams from a file, and converts it to an mp4 + * Reads streams from a file, and converts it to a mp4 file * * @param folder

The folder of the file to process.

* @param file

The file to process.

@@ -136,15 +137,18 @@ public abstract class AbstractConverter implements Converter { } /** - * Gets the first audio stream from a list of streams + * Gets the n-th audio stream from a list of streams * * @param streams

A list of all streams.

+ * @param n

The index of the audio stream to get

* @return

The first audio stream found or null if no audio streams were found.

*/ - AudioStream getFirstAudioSteam(List streams) { + protected AudioStream getNthAudioSteam(List streams, int n) { List audioStreams = filterStreamsByType(streams, AudioStream.class); AudioStream audioStream = null; - if (audioStreams.size() > 0) { + if (audioStreams.size() > n) { + audioStream = audioStreams.get(n); + } else if (audioStreams.size() > 0) { audioStream = audioStreams.get(0); } return audioStream; @@ -154,12 +158,15 @@ public abstract class AbstractConverter implements Converter { * Gets the first subtitle stream from a list of streams * * @param streams

A list of all streams.

+ * @param n

The index of the subtitle stream to get

* @return

The first subtitle stream found or null if no subtitle streams were found.

*/ - SubtitleStream getFirstSubtitleStream(List streams) { + protected SubtitleStream getNthSubtitleStream(List streams, int n) { List subtitleStreams = filterStreamsByType(streams, SubtitleStream.class); SubtitleStream subtitleStream = null; - if (subtitleStreams.size() > 0) { + if (subtitleStreams.size() > n) { + subtitleStream = subtitleStreams.get(n); + } else if (subtitleStreams.size() > 0) { subtitleStream = subtitleStreams.get(0); } return subtitleStream; @@ -171,7 +178,7 @@ public abstract class AbstractConverter implements Converter { * @param streams

A list of all streams.

* @return

The first video stream found or null if no video streams were found.

*/ - VideoStream getFirstVideoStream(List streams) { + protected VideoStream getFirstVideoStream(List streams) { List videoStreams = filterStreamsByType(streams, VideoStream.class); VideoStream videoStream = null; if (videoStreams.size() > 0) { @@ -187,4 +194,5 @@ public abstract class AbstractConverter implements Converter { public void convert(File file) throws IOException { processFile(file.getParentFile(), file); } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java index ff14aa9..bd02e13 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java @@ -14,10 +14,13 @@ import java.util.List; * A converter mainly designed for converting anime to web-playable mp4 */ public class AnimeConverter extends AbstractConverter { + private final String[] audioLanguages; private final String[] subtitleLanguages; private final boolean toStereo; private final boolean preventSignsAndSongs; + private final int forcedAudioIndex; + private final int forcedSubtitleIndex; /** * Instantiates a new anime converter @@ -28,9 +31,11 @@ public class AnimeConverter extends AbstractConverter { * @param subtitleLanguages

List of wanted subtitle languages in descending order.

* @param toStereo

Convert video with several audio channels to stereo.

* @param preventSignsAndSongs

Prevent subtitles only converting signs and songs (not speech).

+ * @param forcedAudioIndex

A specific audio stream to force. 0-indexed from the first audio stream found

+ * @param forcedSubtitleIndex

A specific subtitle stream to force. 0-indexed for the first subtitle stream found

*/ public AnimeConverter(String ffprobePath, String ffmpegPath, String[] audioLanguages, String[] subtitleLanguages, - boolean toStereo, boolean preventSignsAndSongs) { + boolean toStereo, boolean preventSignsAndSongs, int forcedAudioIndex, int forcedSubtitleIndex) { super("mp4"); this.ffprobePath = ffprobePath; this.ffmpegPath = ffmpegPath; @@ -38,6 +43,8 @@ public class AnimeConverter extends AbstractConverter { this.subtitleLanguages = subtitleLanguages; this.toStereo = toStereo; this.preventSignsAndSongs = preventSignsAndSongs; + this.forcedAudioIndex = forcedAudioIndex; + this.forcedSubtitleIndex = forcedSubtitleIndex; } @Override @@ -49,12 +56,13 @@ public class AnimeConverter extends AbstractConverter { //Get the first audio stream in accordance with chosen languages List audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages); - AudioStream audioStream = getFirstAudioSteam(new ArrayList<>(audioStreams)); + AudioStream audioStream = getNthAudioSteam(new ArrayList<>(audioStreams), Math.max(forcedAudioIndex, 0)); //Get the first subtitle stream in accordance with chosen languages and signs and songs prevention List subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams, SubtitleStream.class), subtitleLanguages, preventSignsAndSongs); - SubtitleStream subtitleStream = getFirstSubtitleStream(new ArrayList<>(subtitleStreams)); + SubtitleStream subtitleStream = getNthSubtitleStream(new ArrayList<>(subtitleStreams), + Math.max(forcedSubtitleIndex, 0)); //Get the first video stream VideoStream videoStream = getFirstVideoStream(streams); @@ -71,4 +79,5 @@ public class AnimeConverter extends AbstractConverter { public String[] getValidFormats() { return videoFormats; } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java index fa63110..4ccab47 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java @@ -33,7 +33,7 @@ public class AudioConverter extends AbstractConverter { } //Gets the first audio stream from the file and adds it to the output file - AudioStream audioStream = getFirstAudioSteam(streams); + AudioStream audioStream = getNthAudioSteam(streams, 0); FFMpegHelper.addAudioStream(command, audioStream, false); command.add(outFile); @@ -44,4 +44,5 @@ public class AudioConverter extends AbstractConverter { public String[] getValidFormats() { return audioFormats; } + } \ No newline at end of file diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/Converter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/Converter.java index 900b04a..988277a 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/Converter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/Converter.java @@ -29,4 +29,5 @@ interface Converter { * @return

A list of commands

*/ String[] generateConversionCommand(String executable, File file, List streams, String outFile); + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java index 74363e9..841f1a2 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java @@ -9,6 +9,9 @@ import net.knarcraft.ffmpegconverter.utility.FFMpegHelper; import java.io.File; import java.util.List; +/** + * A simple converter for web-video + */ public class WebVideoConverter extends AbstractConverter { /** @@ -37,9 +40,9 @@ public class WebVideoConverter extends AbstractConverter { } //Get first streams from the file - SubtitleStream subtitleStream = getFirstSubtitleStream(streams); + SubtitleStream subtitleStream = getNthSubtitleStream(streams, 0); VideoStream videoStream = getFirstVideoStream(streams); - AudioStream audioStream = getFirstAudioSteam(streams); + AudioStream audioStream = getNthAudioSteam(streams, 0); //Add streams to output FFMpegHelper.addSubtitleAndVideoStream(command, subtitleStream, videoStream, file); diff --git a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java index 3c61509..3083950 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgument.java @@ -10,16 +10,17 @@ public class ConverterArgument { private final String name; private final char shorthand; private final boolean valueRequired; - private final ConverterArgumentValue valueType; + private final ConverterArgumentValueType valueType; /** * Instantiates a converter argument - * @param name

The name of the argument which users has to type.

- * @param shorthand

A single character value for using the command.

+ * + * @param name

The name of the argument which users has to type.

+ * @param shorthand

A single character value for using the command.

* @param valueRequired

Whether the argument must be followed by a valid value.

- * @param valueType

The type of value the argument requires.

+ * @param valueType

The type of value the argument requires.

*/ - public ConverterArgument(String name, char shorthand, boolean valueRequired, ConverterArgumentValue valueType) { + public ConverterArgument(String name, char shorthand, boolean valueRequired, ConverterArgumentValueType valueType) { this.name = name; this.shorthand = shorthand; this.valueRequired = valueRequired; @@ -28,6 +29,7 @@ public class ConverterArgument { /** * Gets the argument name + * * @return

The argument name.

*/ public String getName() { @@ -36,6 +38,7 @@ public class ConverterArgument { /** * Gets the argument shorthand + * * @return

The argument shorthand

*/ public char getShorthand() { @@ -44,6 +47,7 @@ public class ConverterArgument { /** * Gets whether the argument requires a value + * * @return

Whether the argument requires a value.

*/ public boolean isValueRequired() { @@ -73,9 +77,14 @@ public class ConverterArgument { case STRING: return true; case INT: - int ignored = Integer.parseInt(value); - return true; + try { + Integer.parseInt(value); + return true; + } catch (NumberFormatException exception) { + return false; + } } return false; } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java deleted file mode 100644 index afb460b..0000000 --- a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValue.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.knarcraft.ffmpegconverter.parser; - -public enum ConverterArgumentValue { - BOOLEAN, - COMMA_SEPARATED_LIST, - STRING, - INT -} diff --git a/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValueType.java b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValueType.java new file mode 100644 index 0000000..ffa26f0 --- /dev/null +++ b/src/main/java/net/knarcraft/ffmpegconverter/parser/ConverterArgumentValueType.java @@ -0,0 +1,28 @@ +package net.knarcraft.ffmpegconverter.parser; + +/** + * The value types converter arguments can have + */ +public enum ConverterArgumentValueType { + + /** + * A boolean value + */ + BOOLEAN, + + /** + * A list separated by commas + */ + COMMA_SEPARATED_LIST, + + /** + * A normal string + */ + STRING, + + /** + * An integer + */ + INT + +} diff --git a/src/main/java/net/knarcraft/ffmpegconverter/streams/AbstractStream.java b/src/main/java/net/knarcraft/ffmpegconverter/streams/AbstractStream.java index 1b8882a..850e7fe 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/streams/AbstractStream.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/streams/AbstractStream.java @@ -4,6 +4,7 @@ package net.knarcraft.ffmpegconverter.streams; * An abstract implementation of a stream object implementing common methods */ public abstract class AbstractStream implements StreamObject { + int absoluteIndex; int relativeIndex; String codecName; diff --git a/src/main/java/net/knarcraft/ffmpegconverter/streams/AudioStream.java b/src/main/java/net/knarcraft/ffmpegconverter/streams/AudioStream.java index b0827a3..836c64b 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/streams/AudioStream.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/streams/AudioStream.java @@ -1,9 +1,10 @@ package net.knarcraft.ffmpegconverter.streams; /** - * This class represents an ffmpeg audio stream + * This class represents a ffmpeg audio stream */ public class AudioStream extends AbstractStream implements StreamObject { + private final int channels; private final String title; @@ -38,10 +39,14 @@ public class AudioStream extends AbstractStream implements StreamObject { /** * Gets the title of the audio stream + *

+ * TODO: While this isn't useful right now, it would be useful if the software allowed first looking at available + * steams, and then choose the correct stream based on the name * * @return

The title of the audio stream.

*/ public String getTitle() { return this.title; } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/streams/StreamObject.java b/src/main/java/net/knarcraft/ffmpegconverter/streams/StreamObject.java index f2430bd..549759f 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/streams/StreamObject.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/streams/StreamObject.java @@ -1,5 +1,8 @@ package net.knarcraft.ffmpegconverter.streams; +/** + * An object describing a generic video file stream + */ public interface StreamObject { /** @@ -24,9 +27,9 @@ public interface StreamObject { int getRelativeIndex(); /** - * Gets the language of the audio stream + * Gets the language of the audio or subtitle stream * - * @return

The language of the audio stream.

+ * @return

The language of the audio or subtitle stream.

*/ String getLanguage(); diff --git a/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java b/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java index eb2c4f9..ce6f492 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java @@ -4,6 +4,7 @@ package net.knarcraft.ffmpegconverter.streams; * An object representation of a subtitle stream in a media file */ public class SubtitleStream extends AbstractStream implements StreamObject { + final private String title; final private String file; final private boolean isFullSubtitle; @@ -92,4 +93,5 @@ public class SubtitleStream extends AbstractStream implements StreamObject { !titleLowercase.matches(".*forced.*") && !titleLowercase.matches(".*s&s.*"); } + } \ No newline at end of file diff --git a/src/main/java/net/knarcraft/ffmpegconverter/streams/VideoStream.java b/src/main/java/net/knarcraft/ffmpegconverter/streams/VideoStream.java index 8b7acff..001c397 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/streams/VideoStream.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/streams/VideoStream.java @@ -4,6 +4,7 @@ package net.knarcraft.ffmpegconverter.streams; * An object representation of a video stream in a media file */ public class VideoStream extends AbstractStream implements StreamObject { + private final int width; private final int height; @@ -41,4 +42,5 @@ public class VideoStream extends AbstractStream implements StreamObject { public int getHeight() { return this.height; } + } \ No newline at end of file diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java index 47a238a..3a9763c 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java @@ -21,6 +21,7 @@ public final class FFMpegHelper { private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå"; private FFMpegHelper() { + } /** @@ -429,4 +430,5 @@ public final class FFMpegHelper { } return new SubtitleStream(codecName, absoluteIndex, relativeIndex, language, title, file); } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java index 4e0c75e..3f00db1 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/FileUtil.java @@ -12,6 +12,7 @@ import java.io.InputStreamReader; public final class FileUtil { private FileUtil() { + } /** diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java index 6fd361a..1c98ec8 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/ListUtil.java @@ -11,6 +11,7 @@ import java.util.function.Predicate; public final class ListUtil { private ListUtil() { + } /** @@ -77,4 +78,5 @@ public final class ListUtil { } return result; } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java index 137d9f6..4bf32f5 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/OutputUtil.java @@ -8,10 +8,12 @@ import java.io.OutputStreamWriter; * A class which helps with outputting information */ public final class OutputUtil { + private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); private static boolean debug; private OutputUtil() { + } /** @@ -78,4 +80,5 @@ public final class OutputUtil { print(message); } } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/Parser.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/Parser.java index 93e9321..8c040e0 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/Parser.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/Parser.java @@ -13,11 +13,13 @@ import java.util.Map; public final class Parser { private Parser() { + } /** * This function parses the input to understandable converter instructions - * @param input

The input string to parse.

+ * + * @param input

The input string to parse.

* @param validArguments

All arguments which are considered valid.

* @return

A map with all parsed arguments.

*/ @@ -28,7 +30,7 @@ public final class Parser { /** * This function parses command inputs into understandable converter instructions * - * @param tokens

A list of tokens containing all arguments

+ * @param tokens

A list of tokens containing all arguments

* @param validArguments

A list of arguments which are considered valid.

* @return

A map with all parsed arguments.

*/ @@ -193,4 +195,5 @@ public final class Parser { private static boolean isNotEmpty(StringBuilder builder) { return !builder.toString().trim().equals(""); } + } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java index 068d602..52bea10 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/StringUtil.java @@ -6,6 +6,7 @@ package net.knarcraft.ffmpegconverter.utility; final class StringUtil { private StringUtil() { + } /** @@ -29,4 +30,5 @@ final class StringUtil { //Add other occurrences recursively return ListUtil.concatenate(new String[]{outString}, stringBetween(nextString, start, end)); } + } diff --git a/src/test/java/net/knarcraft/ffmpegconverter/converter/AnimeConverterTest.java b/src/test/java/net/knarcraft/ffmpegconverter/converter/AnimeConverterTest.java index ed69875..0e2c5b8 100644 --- a/src/test/java/net/knarcraft/ffmpegconverter/converter/AnimeConverterTest.java +++ b/src/test/java/net/knarcraft/ffmpegconverter/converter/AnimeConverterTest.java @@ -6,15 +6,17 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; public class AnimeConverterTest { + @Before public void setUp() { - AnimeConverter converter = new AnimeConverter("ffprobe", "ffmpeg", + new AnimeConverter("ffprobe", "ffmpeg", new String[]{"jpn", "eng", "nor", "swe"}, new String[]{"nor", "eng", "swe", "fin"}, false, - false); + false, -1, -1); } @Test public void weirdTest() { assertEquals(0, 0); } + } diff --git a/src/test/java/net/knarcraft/ffmpegconverter/utility/ParserTest.java b/src/test/java/net/knarcraft/ffmpegconverter/utility/ParserTest.java index ac8c37f..a9da423 100644 --- a/src/test/java/net/knarcraft/ffmpegconverter/utility/ParserTest.java +++ b/src/test/java/net/knarcraft/ffmpegconverter/utility/ParserTest.java @@ -1,7 +1,7 @@ package net.knarcraft.ffmpegconverter.utility; import net.knarcraft.ffmpegconverter.parser.ConverterArgument; -import net.knarcraft.ffmpegconverter.parser.ConverterArgumentValue; +import net.knarcraft.ffmpegconverter.parser.ConverterArgumentValueType; import org.junit.Before; import org.junit.Test; @@ -18,9 +18,9 @@ public class ParserTest { @Before public void setUp() { validArguments = new ArrayList<>(); - validArguments.add(new ConverterArgument("anargument", 'a', true, ConverterArgumentValue.STRING)); - validArguments.add(new ConverterArgument("turnoff", 't', false, ConverterArgumentValue.BOOLEAN)); - validArguments.add(new ConverterArgument("turnon", 'o', false, ConverterArgumentValue.BOOLEAN)); + validArguments.add(new ConverterArgument("anargument", 'a', true, ConverterArgumentValueType.STRING)); + validArguments.add(new ConverterArgument("turnoff", 't', false, ConverterArgumentValueType.BOOLEAN)); + validArguments.add(new ConverterArgument("turnon", 'o', false, ConverterArgumentValueType.BOOLEAN)); } @Test @@ -42,17 +42,17 @@ public class ParserTest { assertEquals("false", parsed.get("turnon")); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void parseInvalidArgument() { Parser.parse("--someInvalidArgument hahaha", validArguments); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void parseValueWhenExpectingArgument() { Parser.parse("somevalue", validArguments); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void parseArgumentWithoutRequiredValue() { Parser.parse("--anargument -t", validArguments); }