Improves reading of input

This commit is contained in:
Kristian Knarvik 2019-08-20 21:05:31 +02:00
parent 104d9ccb4b
commit 0a39a69e73
4 changed files with 95 additions and 87 deletions

View File

@ -6,7 +6,8 @@
</artifacts-to-build>
</component>
<component name="ChangeListManager">
<list default="true" id="e9b48a04-29ff-46ce-9630-42742dc34d68" name="Default" comment="Adds surround to stereo">
<list default="true" id="e9b48a04-29ff-46ce-9630-42742dc34d68" name="Default" comment="Improves reading of input">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java" afterDir="false" />
@ -31,24 +32,21 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2907">
<caret line="178" column="13" selection-start-line="178" selection-start-column="13" selection-end-line="178" selection-end-column="13" />
<state relative-caret-position="187">
<caret line="320" column="66" selection-start-line="320" selection-start-column="66" selection-end-line="320" selection-end-column="66" />
<folding>
<element signature="e#12992#12993#0" expanded="true" />
<element signature="e#13075#13076#0" expanded="true" />
<element signature="e#13124#13125#0" expanded="true" />
<element signature="e#13187#13188#0" expanded="true" />
<element signature="imports" expanded="true" />
<element signature="method#concatenate#0;class#Converter#0" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="65">
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
<state relative-caret-position="249">
<caret line="116" column="57" selection-start-line="116" selection-start-column="57" selection-end-line="116" selection-end-column="57" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@ -68,19 +66,15 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="25" column="10" selection-start-line="25" selection-start-column="10" selection-end-line="25" selection-end-column="10" />
<state relative-caret-position="231">
<caret line="149" column="31" lean-forward="true" selection-start-line="149" selection-start-column="31" selection-end-line="149" selection-end-column="31" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#testArgumentValue#0;class#converterArgument#0;class#Main#0" />
<element signature="method#tokenizer#0;class#Main#0" />
<element signature="method#animeConverter#0;class#Main#0" />
<element signature="method#getList#0;class#Main#0" />
<element signature="method#readInput#0;class#Main#0" />
<element signature="method#getChoice#0;class#Main#0" />
<element signature="method#getChoice#1;class#Main#0" />
</folding>
</state>
</provider>
@ -109,6 +103,9 @@
<find>listSubtitlesRelative</find>
<find>debug</find>
<find>isimage</find>
<find>jap</find>
<find>listFilesRec</find>
<find>readInput</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -119,17 +116,16 @@
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/VideoConverter.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/Main.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java" />
<option value="$PROJECT_DIR$/src/ffmpegconverter/Main.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-8" />
<option name="y" value="-8" />
<option name="x" value="-7" />
<option name="width" value="974" />
<option name="height" value="728" />
<option name="height" value="1047" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
@ -143,6 +139,24 @@
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
<item name="out" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
<item name="out" type="462c0819:PsiDirectoryNode" />
<item name="artifacts" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
<item name="out" type="462c0819:PsiDirectoryNode" />
<item name="artifacts" type="462c0819:PsiDirectoryNode" />
<item name="FFmpegConvert" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="FFmpegConvert1" type="b2602c69:ProjectViewProjectNode" />
<item name="FFmpegConvert1" type="462c0819:PsiDirectoryNode" />
@ -172,7 +186,7 @@
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1559848538589" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1566327893996" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../rogue-one-oh-one" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
@ -317,7 +331,10 @@
<workItem from="1558270332068" duration="1231000" />
<workItem from="1559411406801" duration="621000" />
<workItem from="1559765370819" duration="3857000" />
<workItem from="1560477751040" duration="642000" />
<workItem from="1560477751040" duration="2758000" />
<workItem from="1561162925209" duration="2043000" />
<workItem from="1561850923206" duration="1264000" />
<workItem from="1566295287966" duration="2888000" />
</task>
<task id="LOCAL-00001" summary="Adds missing files">
<created>1538261222377</created>
@ -351,7 +368,7 @@
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="97157000" />
<option name="totallyTimeSpent" value="105468000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -364,8 +381,9 @@
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.1098081" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.1130064" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
@ -374,17 +392,17 @@
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.75054705" visible="true" weight="0.7659805" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.75054705" weight="0.48754063" />
<window_info anchor="bottom" id="Debug" order="3" sideWeight="0.49895614" weight="0.39869988" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" sideWeight="0.49946696" weight="0.32936078" />
<window_info anchor="bottom" id="Version Control" order="7" sideWeight="0.4989059" weight="0.32932165" />
<window_info anchor="bottom" id="Version Control" order="7" sideWeight="0.4989059" weight="0.32827735" />
<window_info anchor="bottom" id="Database Changes" order="8" show_stripe_button="false" />
<window_info anchor="bottom" id="Statistic" order="9" sideWeight="0.49946696" weight="0.32936078" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.4989059" weight="0.32932165" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.4989059" weight="0.32827735" />
<window_info anchor="bottom" id="Event Log" order="11" sideWeight="0.24945295" side_tool="true" weight="0.47811815" />
<window_info anchor="bottom" id="Messages" order="12" sideWeight="0.49840087" weight="0.33152762" />
<window_info active="true" anchor="bottom" id="Messages" order="12" sideWeight="0.49840087" visible="true" weight="0.32827735" />
<window_info anchor="bottom" id="Docker" order="13" show_stripe_button="false" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
@ -406,7 +424,8 @@
<MESSAGE value="Hopefully fixes issues #1 and #2&#10;&#10;File collision handling similar to windows" />
<MESSAGE value="Adds hardsubbing of subtitles with same name as video file&#10;&#10;Better file collision detection&#10;Adds debug mode to only render part of the video" />
<MESSAGE value="Adds surround to stereo" />
<option name="LAST_COMMIT_MESSAGE" value="Adds surround to stereo" />
<MESSAGE value="Improves reading of input" />
<option name="LAST_COMMIT_MESSAGE" value="Improves reading of input" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/misc.xml" />
@ -425,20 +444,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2907">
<caret line="178" column="13" selection-start-line="178" selection-start-column="13" selection-end-line="178" selection-end-column="13" />
<folding>
<element signature="e#12992#12993#0" expanded="true" />
<element signature="e#13075#13076#0" expanded="true" />
<element signature="e#13124#13125#0" expanded="true" />
<element signature="e#13187#13188#0" expanded="true" />
<element signature="method#concatenate#0;class#Converter#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AudioConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
@ -449,22 +454,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272">
<caret line="25" column="10" selection-start-line="25" selection-start-column="10" selection-end-line="25" selection-end-column="10" />
<folding>
<element signature="method#testArgumentValue#0;class#converterArgument#0;class#Main#0" />
<element signature="method#tokenizer#0;class#Main#0" />
<element signature="method#animeConverter#0;class#Main#0" />
<element signature="method#getList#0;class#Main#0" />
<element signature="method#readInput#0;class#Main#0" />
<element signature="method#getChoice#0;class#Main#0" />
<element signature="method#getChoice#1;class#Main#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/VideoConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="731">
@ -477,12 +466,35 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java">
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/Converter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="65">
<caret line="14" column="59" selection-start-line="14" selection-start-column="59" selection-end-line="14" selection-end-column="59" />
<state relative-caret-position="187">
<caret line="320" column="66" selection-start-line="320" selection-start-column="66" selection-end-line="320" selection-end-column="66" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#concatenate#0;class#Converter#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/converter/AnimeConverter.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="249">
<caret line="116" column="57" selection-start-line="116" selection-start-column="57" selection-end-line="116" selection-end-column="57" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ffmpegconverter/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="231">
<caret line="149" column="31" lean-forward="true" selection-start-line="149" selection-start-column="31" selection-end-line="149" selection-end-column="31" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#testArgumentValue#0;class#converterArgument#0;class#Main#0" />
<element signature="method#getList#0;class#Main#0" />
</folding>
</state>
</provider>

View File

@ -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) {

View File

@ -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);

View File

@ -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));
}