Fixes code style of utility classes
This commit is contained in:
parent
857c8f29a4
commit
4f07fd09fd
@ -18,15 +18,16 @@ import java.util.List;
|
||||
*/
|
||||
public final class FFMpegHelper {
|
||||
|
||||
private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå";
|
||||
|
||||
private FFMpegHelper() {
|
||||
}
|
||||
|
||||
private static final String PROBE_SPLIT_CHARACTER = "øæåÆØå";
|
||||
|
||||
/**
|
||||
* Gets streams from a file
|
||||
*
|
||||
* @param ffprobePath <p>The path/command to ffprobe.</p>
|
||||
* @param file <p>The file to probe.</p>
|
||||
* @param file <p>The file to probe.</p>
|
||||
* @return <p>A list of StreamObjects.</p>
|
||||
* @throws IOException <p>If the process can't be readProcess.</p>
|
||||
*/
|
||||
@ -36,8 +37,9 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Gets a list of all streams in a file
|
||||
*
|
||||
* @param ffprobePath <p>The path/command to ffprobe.</p>
|
||||
* @param file <p>The file to probe.</p>
|
||||
* @param file <p>The file to probe.</p>
|
||||
* @return <p>A list of streams.</p>
|
||||
* @throws IOException <p>If something goes wrong while probing.</p>
|
||||
*/
|
||||
@ -69,8 +71,9 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Takes a list of all streams and parses each stream into one of three objects
|
||||
*
|
||||
* @param streams <p>A list of all streams for the current file.</p>
|
||||
* @param file <p>The file currently being converted.</p>
|
||||
* @param file <p>The file currently being converted.</p>
|
||||
* @return <p>A list of StreamObjects.</p>
|
||||
*/
|
||||
private static List<StreamObject> parseStreams(String ffprobePath, String[] streams, File file) throws IOException {
|
||||
@ -95,8 +98,9 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Checks whether there exists an external image subtitle with the same filename as the file
|
||||
* @param ffprobePath <p>The path/command to ffprobe.</p>
|
||||
* @param directory <p>The directory containing the file.</p>
|
||||
*
|
||||
* @param ffprobePath <p>The path/command to ffprobe.</p>
|
||||
* @param directory <p>The directory containing the file.</p>
|
||||
* @param convertingFile <p>The file to be converted.</p>
|
||||
* @return <p>The extension of the subtitle or empty if no subtitle was found.</p>
|
||||
*/
|
||||
@ -127,8 +131,9 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Starts and prints output of a process
|
||||
*
|
||||
* @param process <p>The process to run.</p>
|
||||
* @param folder <p>The folder the process should run in.</p>
|
||||
* @param folder <p>The folder the process should run in.</p>
|
||||
* @throws IOException <p>If the process can't be readProcess.</p>
|
||||
*/
|
||||
public static void convertProcess(ProcessBuilder process, File folder) throws IOException {
|
||||
@ -149,6 +154,7 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Reads from a process reader
|
||||
*
|
||||
* @param reader <p>The reader of a process.</p>
|
||||
* @return <p>The output from the readProcess.</p>
|
||||
* @throws IOException <p>On reader failure.</p>
|
||||
@ -164,8 +170,9 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Creates a list containing all required arguments for converting a video to a web playable video
|
||||
*
|
||||
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @return <p>A base list of ffmpeg commands for converting a video for web</p>
|
||||
*/
|
||||
public static List<String> getFFMpegWebVideoCommand(String executable, String fileName) {
|
||||
@ -183,8 +190,9 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Creates a list containing command line arguments for a general file
|
||||
*
|
||||
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @return <p>A base list of ffmpeg commands for converting a file.</p>
|
||||
*/
|
||||
public static List<String> getFFMpegGeneralFileCommand(String executable, String fileName) {
|
||||
@ -198,9 +206,10 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Adds debugging parameters for only converting parts of a file
|
||||
*
|
||||
* @param command <p>The list containing the command to run.</p>
|
||||
* @param start <p>The offset before converting.</p>
|
||||
* @param length <p>The offset for stopping the conversion.</p>
|
||||
* @param start <p>The offset before converting.</p>
|
||||
* @param length <p>The offset for stopping the conversion.</p>
|
||||
*/
|
||||
public static void addDebugArguments(List<String> command, int start, int length) {
|
||||
command.add("-ss");
|
||||
@ -211,7 +220,8 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Parses a list of video stream parameters to a video stream object
|
||||
* @param streamParts <p>A list of parameters belonging to an video stream.</p>
|
||||
*
|
||||
* @param streamParts <p>A list of parameters belonging to an video stream.</p>
|
||||
* @param relativeIndex <p>The relative index of the video stream.</p>
|
||||
* @return <p>A SubtitleStream object.</p>
|
||||
* @throws NumberFormatException <p>If codec index contains a non-numeric value.</p>
|
||||
@ -237,7 +247,8 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Parses a list of audio stream parameters to an audio stream object
|
||||
* @param streamParts <p>A list of parameters belonging to an audio stream.</p>
|
||||
*
|
||||
* @param streamParts <p>A list of parameters belonging to an audio stream.</p>
|
||||
* @param relativeIndex <p>The relative index of the audio stream.</p>
|
||||
* @return <p>A SubtitleStream object.</p>
|
||||
* @throws NumberFormatException <p>If codec index contains a non-numeric value.</p>
|
||||
@ -266,9 +277,10 @@ public final class FFMpegHelper {
|
||||
|
||||
/**
|
||||
* Parses a list of subtitle stream parameters to a subtitle stream object
|
||||
* @param streamParts <p>A list of parameters belonging to a subtitle stream.</p>
|
||||
*
|
||||
* @param streamParts <p>A list of parameters belonging to a subtitle stream.</p>
|
||||
* @param relativeIndex <p>The relative index of the subtitle.</p>
|
||||
* @param file <p>The file currently being converted.</p>
|
||||
* @param file <p>The file currently being converted.</p>
|
||||
* @return <p>A SubtitleStream object.</p>
|
||||
* @throws NumberFormatException <p>If codec index contains a non-numeric value.</p>
|
||||
*/
|
||||
|
@ -16,8 +16,9 @@ public final class FileUtil {
|
||||
|
||||
/**
|
||||
* Adds parentheses with an integer if the output file already exists
|
||||
*
|
||||
* @param targetPath <p>The path the file should ideally be saved at.</p>
|
||||
* @param extension <p>The extension of the target file.</p>
|
||||
* @param extension <p>The extension of the target file.</p>
|
||||
* @return <p>A filename guaranteed not to collide with other files.</p>
|
||||
*/
|
||||
public static String getNonCollidingFilename(String targetPath, String extension) {
|
||||
@ -32,6 +33,7 @@ public final class FileUtil {
|
||||
|
||||
/**
|
||||
* Gets filename without extension from File object
|
||||
*
|
||||
* @param file <p>A file object.</p>
|
||||
* @return <p>A filename.</p>
|
||||
*/
|
||||
@ -41,6 +43,7 @@ public final class FileUtil {
|
||||
|
||||
/**
|
||||
* Removes the extension from a file name
|
||||
*
|
||||
* @param file <p>A filename.</p>
|
||||
* @return <p>A filename without its extension.</p>
|
||||
*/
|
||||
@ -50,15 +53,20 @@ public final class FileUtil {
|
||||
|
||||
/**
|
||||
* Recursively lists all files in a folder
|
||||
* @param folder <p>The folder to start from.</p>
|
||||
*
|
||||
* @param folder <p>The folder to start from.</p>
|
||||
* @param maxRecursions <p>Maximum number of recursions</p>
|
||||
* @return A list of files
|
||||
* @return A list of files
|
||||
*/
|
||||
public static File[] listFilesRecursive(File folder, String[] extensions, int maxRecursions) {
|
||||
if (maxRecursions == 0) { return null; }
|
||||
if (maxRecursions == 0) {
|
||||
return null;
|
||||
}
|
||||
File[] listOfFiles = folder.listFiles((file) -> file.isFile() &&
|
||||
ListUtil.listContains(extensions, (item) -> file.getName().endsWith(item)));
|
||||
if (listOfFiles == null) { return null; }
|
||||
if (listOfFiles == null) {
|
||||
return null;
|
||||
}
|
||||
if (maxRecursions > 1) {
|
||||
File[] listOfFolders = folder.listFiles((dir, name) -> new File(dir, name).isDirectory());
|
||||
if (listOfFolders != null) {
|
||||
@ -94,6 +102,7 @@ public final class FileUtil {
|
||||
|
||||
/**
|
||||
* Gets a resource as an InputStream
|
||||
*
|
||||
* @param resourceName <p>The name of the resource you want to read.</p>
|
||||
* @return <p>An input stream which can be used to access the resource.</p>
|
||||
*/
|
||||
|
@ -15,9 +15,10 @@ public final class ListUtil {
|
||||
|
||||
/**
|
||||
* Combines two arrays to one
|
||||
*
|
||||
* @param listA <p>The first array.</p>
|
||||
* @param listB <p>The second array.</p>
|
||||
* @param <T> <p>The type of the two lists.</p>
|
||||
* @param <T> <p>The type of the two lists.</p>
|
||||
* @return <p>A new array containing all elements from the two arrays.</p>
|
||||
*/
|
||||
static <T> T[] concatenate(T[] listA, T[] listB) {
|
||||
@ -32,9 +33,10 @@ public final class ListUtil {
|
||||
|
||||
/**
|
||||
* Gets all list items according to the predicate
|
||||
* @param list <p>The list to process.</p>
|
||||
*
|
||||
* @param list <p>The list to process.</p>
|
||||
* @param predicate <p>The predicate to test.</p>
|
||||
* @param <T> <p>The type of the list.</p>
|
||||
* @param <T> <p>The type of the list.</p>
|
||||
* @return <p>A new list containing all matching elements.</p>
|
||||
*/
|
||||
static <T> List<T> getMatching(List<T> list, Predicate<T> predicate) {
|
||||
@ -50,7 +52,7 @@ public final class ListUtil {
|
||||
* @param list The list to test against
|
||||
* @param predicate A predicate to use on every element in the list
|
||||
* @param <T> Anything which can be stored in a list
|
||||
* @return True if at least one element fulfills the predicate
|
||||
* @return True if at least one element fulfills the predicate
|
||||
*/
|
||||
static <T> boolean listContains(T[] list, Predicate<T> predicate) {
|
||||
for (T item : list) {
|
||||
@ -63,7 +65,8 @@ public final class ListUtil {
|
||||
|
||||
/**
|
||||
* Gets a list from a comma separated string at index in list
|
||||
* @param list <p>A list of tokens.</p>
|
||||
*
|
||||
* @param list <p>A list of tokens.</p>
|
||||
* @param index <p>The index of the token containing comma separated entries.</p>
|
||||
* @return <p>A string list.</p>
|
||||
*/
|
||||
|
@ -8,14 +8,15 @@ import java.io.OutputStreamWriter;
|
||||
* A class which helps with outputting information
|
||||
*/
|
||||
public final class OutputUtil {
|
||||
private static boolean debug;
|
||||
private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
|
||||
private static boolean debug;
|
||||
|
||||
private OutputUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to show debug messages
|
||||
*
|
||||
* @param debug <p>The debug message to show.</p>
|
||||
*/
|
||||
public static void setDebug(boolean debug) {
|
||||
@ -24,6 +25,7 @@ public final class OutputUtil {
|
||||
|
||||
/**
|
||||
* Prints something and a newline to the commandline efficiently
|
||||
*
|
||||
* @param input <p>The text to print.</p>
|
||||
* @throws IOException <p>If a write is not possible.</p>
|
||||
*/
|
||||
@ -36,6 +38,7 @@ public final class OutputUtil {
|
||||
|
||||
/**
|
||||
* Prints a string
|
||||
*
|
||||
* @param input <p>The string to print.</p>
|
||||
* @throws IOException <p>If the writer fails to write.</p>
|
||||
*/
|
||||
@ -47,6 +50,7 @@ public final class OutputUtil {
|
||||
|
||||
/**
|
||||
* Prints a newline
|
||||
*
|
||||
* @throws IOException <p>If a write is not possible.</p>
|
||||
*/
|
||||
public static void println() throws IOException {
|
||||
@ -56,6 +60,7 @@ public final class OutputUtil {
|
||||
|
||||
/**
|
||||
* Closes the writer
|
||||
*
|
||||
* @throws IOException <p>If the writer cannot be closed.</p>
|
||||
*/
|
||||
public static void close() throws IOException {
|
||||
@ -64,6 +69,7 @@ public final class OutputUtil {
|
||||
|
||||
/**
|
||||
* Prints a message if debug messages should be shown
|
||||
*
|
||||
* @param message <p>The debug message to show.</p>
|
||||
* @throws IOException <p>If a write is not possible.</p>
|
||||
*/
|
||||
|
@ -1,32 +1,42 @@
|
||||
package net.knarcraft.ffmpegconverter;
|
||||
package net.knarcraft.ffmpegconverter.utility;
|
||||
|
||||
import net.knarcraft.ffmpegconverter.parser.ConverterArgument;
|
||||
import net.knarcraft.ffmpegconverter.parser.ConverterArgumentValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Parser {
|
||||
/**
|
||||
* A class to help with command parsing
|
||||
*/
|
||||
public final class Parser {
|
||||
|
||||
private Parser() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function parses command inputs into understandable converter instructions
|
||||
*
|
||||
* @param tokens <p>A list of tokens containing all arguments</p>
|
||||
*/
|
||||
private static void parse(List<String> tokens) {
|
||||
String[] types = {"animeconverter", "audioconverter", "videoconverter"};
|
||||
Main.converterArgument[] commonArgs = {
|
||||
new Main.converterArgument("-recursions", true, Main.converterArgumentValueType.INT)
|
||||
ConverterArgument[] commonArgs = {
|
||||
new ConverterArgument("-recursions", true, ConverterArgumentValue.INT)
|
||||
};
|
||||
Main.converterArgument[] animeArgs = {
|
||||
ConverterArgument[] animeArgs = {
|
||||
|
||||
};
|
||||
Main.converterArgument[] audioArgs = {
|
||||
new Main.converterArgument("-outext", true,
|
||||
Main.converterArgumentValueType.SINGLE_VALUE)
|
||||
ConverterArgument[] audioArgs = {
|
||||
new ConverterArgument("-outext", true,
|
||||
ConverterArgumentValue.SINGLE_VALUE)
|
||||
};
|
||||
Main.converterArgument[] videoArgs = {
|
||||
new Main.converterArgument("-outext", true,
|
||||
Main.converterArgumentValueType.SINGLE_VALUE)
|
||||
ConverterArgument[] videoArgs = {
|
||||
new ConverterArgument("-outext", true,
|
||||
ConverterArgumentValue.SINGLE_VALUE)
|
||||
};
|
||||
String type = tokens.get(0).toLowerCase();
|
||||
if (!Main.listContains(types, s -> s.equals(type))) {
|
||||
if (!ListUtil.listContains(types, s -> s.equals(type))) {
|
||||
throw new IllegalArgumentException("Unknown converter type chosen.");
|
||||
}
|
||||
if (tokens.size() < 2) {
|
||||
@ -40,6 +50,7 @@ public class Parser {
|
||||
|
||||
/**
|
||||
* Tokenizes a string
|
||||
*
|
||||
* @param input <p>A string.</p>
|
||||
* @return <p>A list of tokens.</p>
|
||||
*/
|
||||
@ -89,6 +100,7 @@ public class Parser {
|
||||
|
||||
/**
|
||||
* Checks whether a string builder is empty
|
||||
*
|
||||
* @param builder <p>The string builder to check.</p>
|
||||
* @return <p>True if the string builder is non empty.</p>
|
||||
*/
|
@ -10,9 +10,10 @@ final class StringUtil {
|
||||
|
||||
/**
|
||||
* Finds all substrings between two substrings in a string
|
||||
*
|
||||
* @param string <p>The string containing the substrings.</p>
|
||||
* @param start <p>The substring before the wanted substring.</p>
|
||||
* @param end <p>The substring after the wanted substring.</p>
|
||||
* @param start <p>The substring before the wanted substring.</p>
|
||||
* @param end <p>The substring after the wanted substring.</p>
|
||||
* @return <p>A list of all occurrences of the substring.</p>
|
||||
*/
|
||||
static String[] stringBetween(String string, String start, String end) {
|
||||
|
Loading…
Reference in New Issue
Block a user