Basic POC for cutting subtitles in their separate dialog lines
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
2fa8b18a0a
commit
3e0758a634
@ -34,5 +34,6 @@ dependencies {
|
|||||||
implementation 'com.discord4j:discord4j-core:3.1.1'
|
implementation 'com.discord4j:discord4j-core:3.1.1'
|
||||||
implementation 'com.github.wtekiela:opensub4j:0.3.0'
|
implementation 'com.github.wtekiela:opensub4j:0.3.0'
|
||||||
implementation 'org.apache.commons:commons-lang3:3.11'
|
implementation 'org.apache.commons:commons-lang3:3.11'
|
||||||
|
implementation 'com.github.dnbn.submerge:submerge-api:1.9.2'
|
||||||
implementation 'ch.qos.logback:logback-classic:1.2.3'
|
implementation 'ch.qos.logback:logback-classic:1.2.3'
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.xmlrpc.XmlRpcException;
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import xyz.vallat.louis.subtitles.OpenSubtitles;
|
import xyz.vallat.louis.subtitles.OpenSubtitles;
|
||||||
|
import xyz.vallat.louis.subtitles.parser.SubtitleParser;
|
||||||
|
|
||||||
public class Download extends Command {
|
public class Download extends Command {
|
||||||
|
|
||||||
@ -28,7 +29,9 @@ public class Download extends Command {
|
|||||||
return event.getMessage().getChannel()
|
return event.getMessage().getChannel()
|
||||||
.flatMap(messageChannel ->
|
.flatMap(messageChannel ->
|
||||||
{
|
{
|
||||||
System.out.println(subs.getData().get(0).getContentAsString("cp1252"));
|
String var = subs.getData().get(0).getContentAsString("cp1252");
|
||||||
|
SubtitleParser subtitleParser = new SubtitleParser();
|
||||||
|
subtitleParser.parseSRT(var);
|
||||||
return messageChannel.createMessage("Good");
|
return messageChannel.createMessage("Good");
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package xyz.vallat.louis.subtitles.parser;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class SubtitleParser {
|
||||||
|
|
||||||
|
private final List<String> subtitleText = new ArrayList<>();
|
||||||
|
|
||||||
|
// TODO: FIND A WAY TO DO THIS THAT HAS A BETTER COMPLEXITY
|
||||||
|
public void parseSRT(String s) {
|
||||||
|
s = s.replace("\r\n", "\n");
|
||||||
|
String[] blocks = s.split("\n\n");
|
||||||
|
for (String block : blocks) {
|
||||||
|
List<String> 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user