Ignore Comment subtitle entries

This commit is contained in:
Reinhard Pointner 2016-06-28 03:00:50 +08:00
parent ba439cc2b6
commit 37335243cc
2 changed files with 10 additions and 9 deletions

View File

@ -1,8 +1,9 @@
package net.filebot.subtitle; package net.filebot.subtitle;
import static java.util.Arrays.*;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Arrays;
import java.util.InputMismatchException; import java.util.InputMismatchException;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -30,11 +31,12 @@ public class SubStationAlphaReader extends SubtitleReader {
private void readFormat() throws Exception { private void readFormat() throws Exception {
// read format line (e.g. Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text) // read format line (e.g. Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text)
String[] event = scanner.nextLine().split(":", 2); String line = scanner.nextLine();
String[] event = line.split(":", 2);
// sanity check // sanity check
if (!event[0].equals("Format")) if (!event[0].equals("Format"))
throw new InputMismatchException("Illegal format header: " + Arrays.toString(event)); throw new InputMismatchException("Illegal format header: " + line);
// read columns // read columns
format = event[1].split(","); format = event[1].split(",");
@ -44,7 +46,7 @@ public class SubStationAlphaReader extends SubtitleReader {
format[i] = format[i].trim().toLowerCase(); format[i] = format[i].trim().toLowerCase();
} }
List<String> lookup = Arrays.asList(format); List<String> lookup = asList(format);
formatIndexStart = lookup.indexOf("start"); formatIndexStart = lookup.indexOf("start");
formatIndexEnd = lookup.indexOf("end"); formatIndexEnd = lookup.indexOf("end");
formatIndexText = lookup.indexOf("text"); formatIndexText = lookup.indexOf("text");
@ -71,9 +73,9 @@ public class SubStationAlphaReader extends SubtitleReader {
// read next dialogue line // read next dialogue line
String[] event = scanner.nextLine().split(":", 2); String[] event = scanner.nextLine().split(":", 2);
// sanity check // ignore non-dialog lines
if (!event[0].equals("Dialogue")) if (event.length < 2 || !event[0].equals("Dialogue"))
throw new InputMismatchException("Illegal dialogue event: " + Arrays.toString(event)); return null;
// extract information // extract information
String[] values = event[1].split(",", format.length); String[] values = event[1].split(",", format.length);

View File

@ -28,8 +28,7 @@ public abstract class SubtitleReader implements Iterator<SubtitleElement>, Close
try { try {
current = readNext(); current = readNext();
} catch (Exception e) { } catch (Exception e) {
// log and ignore debug.warning(format("%s: %s", getFormatName(), e.getMessage())); // log and ignore
debug.warning(format("Failed to read %s subtitles: %s", getFormatName(), e.getMessage()));
} }
} }