Better logging for bad subtitle files

This commit is contained in:
Reinhard Pointner 2016-03-21 18:44:57 +00:00
parent 912ddbc2d8
commit b6b1dcab2a
5 changed files with 21 additions and 9 deletions

View File

@ -13,6 +13,11 @@ public class MicroDVDReader extends SubtitleReader {
super(source);
}
@Override
public String getFormatName() {
return "MicroDVD";
}
@Override
public SubtitleElement readNext() throws Exception {
String line = scanner.nextLine();

View File

@ -26,6 +26,11 @@ public class SubRipReader extends SubtitleReader {
tag = Pattern.compile("</?(b|u|i|font[^<>]*)>", Pattern.CASE_INSENSITIVE);
}
@Override
public String getFormatName() {
return "SubRip";
}
@Override
protected SubtitleElement readNext() throws Exception {
String number = scanner.nextLine();

View File

@ -1,14 +1,12 @@
package net.filebot.subtitle;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import java.util.regex.Pattern;
public class SubStationAlphaReader extends SubtitleReader {
private final DateFormat timeFormat = new SubtitleTimeFormat();
@ -20,11 +18,14 @@ public class SubStationAlphaReader extends SubtitleReader {
private int formatIndexEnd;
private int formatIndexText;
public SubStationAlphaReader(Readable source) {
super(source);
}
@Override
public String getFormatName() {
return "SubStationAlpha";
}
private void readFormat() throws Exception {
// read format line (e.g. Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text)
@ -48,7 +49,6 @@ public class SubStationAlphaReader extends SubtitleReader {
formatIndexText = lookup.indexOf("text");
}
@Override
public SubtitleElement readNext() throws Exception {
if (format == null) {
@ -84,7 +84,6 @@ public class SubStationAlphaReader extends SubtitleReader {
return new SubtitleElement(start, end, resolve(text));
}
protected String resolve(String text) {
// remove tags
text = tag.matcher(text).replaceAll("");

View File

@ -1,7 +1,6 @@
package net.filebot.subtitle;
import static java.util.regex.Pattern.*;
import static net.filebot.util.StringUtilities.*;
@ -10,17 +9,19 @@ import java.text.ParseException;
import java.util.InputMismatchException;
import java.util.regex.Pattern;
public class SubViewerReader extends SubtitleReader {
private final DateFormat timeFormat = new SubtitleTimeFormat();
private final Pattern newline = compile(quote("[br]"), CASE_INSENSITIVE);
public SubViewerReader(Readable source) {
super(source);
}
@Override
public String getFormatName() {
return "SubViewer";
}
@Override
protected SubtitleElement readNext() throws Exception {

View File

@ -17,6 +17,8 @@ public abstract class SubtitleReader implements Iterator<SubtitleElement>, Close
this.scanner = new Scanner(source);
}
public abstract String getFormatName();
protected abstract SubtitleElement readNext() throws Exception;
@Override
@ -27,7 +29,7 @@ public abstract class SubtitleReader implements Iterator<SubtitleElement>, Close
current = readNext();
} catch (Exception e) {
// log and ignore
debug.warning("Illegal input: " + e.getMessage());
debug.warning(format("Failed to read %s subtitles: %s", getFormatName(), e.getMessage()));
}
}