Parsing returns the parsed list

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2020-10-27 12:00:13 +01:00
parent 4c30f55f29
commit bcac5c325f
2 changed files with 7 additions and 7 deletions

View File

@ -52,6 +52,7 @@ public class MovieQuoteBot {
args[0] : args[0] :
System.getenv(DISCORD_TOKEN_ENVIRONMENT); System.getenv(DISCORD_TOKEN_ENVIRONMENT);
// TODO: FIX CRASH ON LOGIN IF OS IS IN MAINTENANCE OR BROKEN
OpenSubtitles.login( OpenSubtitles.login(
System.getenv(OS_USERNAME_ENVIRONMENT) == null ? System.getenv(OS_USERNAME_ENVIRONMENT) == null ?
args[1] : args[1] :

View File

@ -10,17 +10,16 @@ public class SubtitleParser {
private final List<String> subtitleText = new ArrayList<>(); private final List<String> subtitleText = new ArrayList<>();
// TODO: FIND A WAY TO DO THIS THAT HAS A BETTER COMPLEXITY // TODO: FIND A WAY TO DO THIS THAT HAS A BETTER COMPLEXITY
public void parseSRT(String s) { public List<String> parseSRT(String s) {
s = s.replace("\r\n", "\n"); s = s.replace("\r\n", "\n");
String[] blocks = s.split("\n\n"); String[] blocks = s.split("\n\n");
for (String block : blocks) { for (String block : blocks) {
List<String> splittedBlock = Arrays.stream(block.split("\n")).collect(Collectors.toList()); List<String> splitBlock = Arrays.stream(block.split("\n")).collect(Collectors.toList());
subtitleText.add(splittedBlock.subList(2, splittedBlock.size()).stream().collect(Collectors.joining("\n"))); subtitleText.add(String.join("\n", splitBlock.subList(2, splitBlock.size())));
}
for(String st : subtitleText) {
System.out.println("TEXT:\n" + st + "\n\n");
} }
subtitleText.remove(0);
subtitleText.remove(subtitleText.size() - 1);
return subtitleText;
} }
} }