From bcac5c325f8e8e8881e4cfd006ccd699476ebafd Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Tue, 27 Oct 2020 12:00:13 +0100 Subject: [PATCH] Parsing returns the parsed list Signed-off-by: Louis Vallat --- src/main/java/xyz/vallat/louis/MovieQuoteBot.java | 1 + .../louis/subtitles/parser/SubtitleParser.java | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java index c3dacdd..e62711d 100644 --- a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java +++ b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java @@ -52,6 +52,7 @@ public class MovieQuoteBot { args[0] : System.getenv(DISCORD_TOKEN_ENVIRONMENT); + // TODO: FIX CRASH ON LOGIN IF OS IS IN MAINTENANCE OR BROKEN OpenSubtitles.login( System.getenv(OS_USERNAME_ENVIRONMENT) == null ? args[1] : diff --git a/src/main/java/xyz/vallat/louis/subtitles/parser/SubtitleParser.java b/src/main/java/xyz/vallat/louis/subtitles/parser/SubtitleParser.java index b2ad23c..8bed69d 100644 --- a/src/main/java/xyz/vallat/louis/subtitles/parser/SubtitleParser.java +++ b/src/main/java/xyz/vallat/louis/subtitles/parser/SubtitleParser.java @@ -10,17 +10,16 @@ public class SubtitleParser { private final List subtitleText = new ArrayList<>(); // TODO: FIND A WAY TO DO THIS THAT HAS A BETTER COMPLEXITY - public void parseSRT(String s) { + public List parseSRT(String s) { s = s.replace("\r\n", "\n"); String[] blocks = s.split("\n\n"); for (String block : blocks) { - List splittedBlock = Arrays.stream(block.split("\n")).collect(Collectors.toList()); - subtitleText.add(splittedBlock.subList(2, splittedBlock.size()).stream().collect(Collectors.joining("\n"))); - } - - for(String st : subtitleText) { - System.out.println("TEXT:\n" + st + "\n\n"); + List splitBlock = Arrays.stream(block.split("\n")).collect(Collectors.toList()); + subtitleText.add(String.join("\n", splitBlock.subList(2, splitBlock.size()))); } + subtitleText.remove(0); + subtitleText.remove(subtitleText.size() - 1); + return subtitleText; } }