Improves reading of input
This commit is contained in:
		@@ -15,9 +15,9 @@ import java.util.function.Predicate;
 | 
			
		||||
 * Converts a files or files in a folder to a web playable mp4.
 | 
			
		||||
 */
 | 
			
		||||
public class Main {
 | 
			
		||||
    private static final String FFPROBE_PATH = "C:\\Users\\Kristian\\Downloads\\ffmpeg-20190427-8019395-win64-static\\bin\\ffprobe.exe"; //Can be just ffprobe if it's in the path
 | 
			
		||||
    private static final String FFMPEG_PATH = "C:\\Users\\Kristian\\Downloads\\ffmpeg-20190427-8019395-win64-static\\bin\\ffmpeg.exe"; //Can be just ffmpeg if it's in the path
 | 
			
		||||
    private static Scanner in = new Scanner(System.in);
 | 
			
		||||
    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 Scanner in = new Scanner(System.in, "UTF-8");
 | 
			
		||||
    private static Converter con = null;
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) throws IOException {
 | 
			
		||||
@@ -68,8 +68,10 @@ public class Main {
 | 
			
		||||
            } else {
 | 
			
		||||
                System.out.println("No valid files found in folder.");
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
        } else if (folder.exists()) {
 | 
			
		||||
            con.convert(folder);
 | 
			
		||||
        } else {
 | 
			
		||||
            System.out.println("Path " + folder.getAbsolutePath() + " does not point to any file or folder.");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -142,7 +144,7 @@ public class Main {
 | 
			
		||||
 | 
			
		||||
    private static List<String> tokenizer(String input) {
 | 
			
		||||
        List<String> tokens = new ArrayList<>();
 | 
			
		||||
        Boolean startedQuote = false;
 | 
			
		||||
        boolean startedQuote = false;
 | 
			
		||||
        StringBuilder currentToken = new StringBuilder();
 | 
			
		||||
        for (int i = 0; i < input.length(); i++) {
 | 
			
		||||
            char c = input.charAt(i);
 | 
			
		||||
@@ -179,7 +181,7 @@ public class Main {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void animeConverter() {
 | 
			
		||||
        System.out.println("[Audio languages jap,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if necessary true/false] [Prevent signs&songs subtitles true/false]\nYour input: ");
 | 
			
		||||
        System.out.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<String> input = readInput(4);
 | 
			
		||||
        String[] audioLang = new String[]{"jpn"};
 | 
			
		||||
        String[] subtitleLang = new String[]{"eng"};
 | 
			
		||||
@@ -213,20 +215,12 @@ public class Main {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static List<String> readInput(int max) {
 | 
			
		||||
        List<String> input = new ArrayList<>();
 | 
			
		||||
        String rx = "[^\"\\s]+|\"(\\\\.|[^\\\\\"])*\"";
 | 
			
		||||
        for (int i = 0; i < max; i++) {
 | 
			
		||||
            String line = in.findInLine(rx);
 | 
			
		||||
            if (line != null) {
 | 
			
		||||
                if (line.startsWith("\"") && line.endsWith("\"")) {
 | 
			
		||||
                    input.add(line.substring(1, line.length() - 1));
 | 
			
		||||
                } else {
 | 
			
		||||
                    input.add(line);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        List<String> tokens =  tokenizer(in.nextLine());
 | 
			
		||||
        if (max < tokens.size()) {
 | 
			
		||||
            throw new IllegalArgumentException("Input contains " + tokens.size() +
 | 
			
		||||
                    " arguments, but the input only supports " + max + " arguments.");
 | 
			
		||||
        }
 | 
			
		||||
        in.nextLine();
 | 
			
		||||
        return input;
 | 
			
		||||
        return tokens;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static String getChoice(String prompt) {
 | 
			
		||||
 
 | 
			
		||||
@@ -96,8 +96,8 @@ public class AnimeConverter extends Converter {
 | 
			
		||||
                subtitleStreams = listSubtitlesRelative(streams);
 | 
			
		||||
                subtitleStreamsAbsolute = listSubtitles(streams);
 | 
			
		||||
            } else if (preventSignsAndSongs) {
 | 
			
		||||
                subtitleStreams = listSubtitlesRelative(streams, lang, new String[]{"title=Signs"});
 | 
			
		||||
                subtitleStreamsAbsolute = listSubtitles(streams, lang, new String[]{"title=Signs"});
 | 
			
		||||
                subtitleStreams = listSubtitlesRelative(streams, lang, new String[]{"title=Signs", "Signs/Songs"});
 | 
			
		||||
                subtitleStreamsAbsolute = listSubtitles(streams, lang, new String[]{"title=Signs", "Signs/Songs"});
 | 
			
		||||
            } else {
 | 
			
		||||
                subtitleStreams = listSubtitlesRelative(streams, lang);
 | 
			
		||||
                subtitleStreamsAbsolute = listSubtitles(streams, lang);
 | 
			
		||||
 
 | 
			
		||||
@@ -120,6 +120,8 @@ public abstract class Converter {
 | 
			
		||||
        command.add("" + length);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO: Create a new object for subtitle containing language, relative index, absolute index and codec. Also signs & songs.
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks for the occurrence of otf attachments signifying the existence of image based subtitles.
 | 
			
		||||
     *
 | 
			
		||||
@@ -316,7 +318,7 @@ public abstract class Converter {
 | 
			
		||||
        }
 | 
			
		||||
        int endPos = string.indexOf(end, startPos);
 | 
			
		||||
        String outString = string.substring(startPos, endPos).trim();
 | 
			
		||||
        String nextString = string.substring(endPos + end.length(), string.length());
 | 
			
		||||
        String nextString = string.substring(endPos + end.length());
 | 
			
		||||
        return concatenate(new String[]{outString}, stringBetween(nextString, start, end));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user