Refactor SubtitleFormat and add SAMI support (read-only)
This commit is contained in:
parent
ae96a2a55c
commit
c423f00c8a
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
@ -16,7 +17,7 @@ import org.jsoup.nodes.Element;
|
|||
public class SamiDecoder implements SubtitleDecoder {
|
||||
|
||||
@Override
|
||||
public List<SubtitleElement> decode(String file) {
|
||||
public Stream<SubtitleElement> decode(String file) {
|
||||
List<SubtitleElement> subtitles = new ArrayList<SubtitleElement>();
|
||||
|
||||
Matcher matcher = Pattern.compile("<SYNC(.*?)>", Pattern.CASE_INSENSITIVE).matcher(file);
|
||||
|
@ -63,7 +64,7 @@ public class SamiDecoder implements SubtitleDecoder {
|
|||
}
|
||||
}
|
||||
|
||||
return subtitles;
|
||||
return subtitles.stream();
|
||||
}
|
||||
|
||||
private SubtitleElement getSubtitle(long start, long end, CharSequence fragment) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.filebot.subtitle;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface SubtitleDecoder {
|
||||
|
||||
List<SubtitleElement> decode(String file);
|
||||
Stream<SubtitleElement> decode(String file);
|
||||
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
|
||||
package net.filebot.subtitle;
|
||||
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import net.filebot.MediaTypes;
|
||||
|
@ -14,7 +12,7 @@ public enum SubtitleFormat {
|
|||
|
||||
@Override
|
||||
public SubtitleDecoder getDecoder() {
|
||||
return content -> new SubRipReader(new Scanner(content)).stream().collect(toList());
|
||||
return content -> new SubRipReader(new Scanner(content)).stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,7 +25,7 @@ public enum SubtitleFormat {
|
|||
|
||||
@Override
|
||||
public SubtitleDecoder getDecoder() {
|
||||
return content -> new MicroDVDReader(new Scanner(content)).stream().collect(toList());
|
||||
return content -> new MicroDVDReader(new Scanner(content)).stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +38,7 @@ public enum SubtitleFormat {
|
|||
|
||||
@Override
|
||||
public SubtitleDecoder getDecoder() {
|
||||
return content -> new SubViewerReader(new Scanner(content)).stream().collect(toList());
|
||||
return content -> new SubViewerReader(new Scanner(content)).stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +51,7 @@ public enum SubtitleFormat {
|
|||
|
||||
@Override
|
||||
public SubtitleDecoder getDecoder() {
|
||||
return content -> new SubStationAlphaReader(new Scanner(content)).stream().collect(toList());
|
||||
return content -> new SubStationAlphaReader(new Scanner(content)).stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -330,7 +330,7 @@ public final class SubtitleUtilities {
|
|||
|
||||
// decode subtitle file with the first reader that seems to work
|
||||
for (SubtitleFormat format : likelyFormats) {
|
||||
List<SubtitleElement> subtitles = format.getDecoder().decode(content);
|
||||
List<SubtitleElement> subtitles = format.getDecoder().decode(content).collect(toList());
|
||||
|
||||
if (subtitles.size() > 0) {
|
||||
return subtitles;
|
||||
|
|
Loading…
Reference in New Issue