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); super(source);
} }
@Override
public String getFormatName() {
return "MicroDVD";
}
@Override @Override
public SubtitleElement readNext() throws Exception { public SubtitleElement readNext() throws Exception {
String line = scanner.nextLine(); 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); tag = Pattern.compile("</?(b|u|i|font[^<>]*)>", Pattern.CASE_INSENSITIVE);
} }
@Override
public String getFormatName() {
return "SubRip";
}
@Override @Override
protected SubtitleElement readNext() throws Exception { protected SubtitleElement readNext() throws Exception {
String number = scanner.nextLine(); String number = scanner.nextLine();

View File

@ -1,14 +1,12 @@
package net.filebot.subtitle; package net.filebot.subtitle;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Arrays; 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;
public class SubStationAlphaReader extends SubtitleReader { public class SubStationAlphaReader extends SubtitleReader {
private final DateFormat timeFormat = new SubtitleTimeFormat(); private final DateFormat timeFormat = new SubtitleTimeFormat();
@ -20,11 +18,14 @@ public class SubStationAlphaReader extends SubtitleReader {
private int formatIndexEnd; private int formatIndexEnd;
private int formatIndexText; private int formatIndexText;
public SubStationAlphaReader(Readable source) { public SubStationAlphaReader(Readable source) {
super(source); super(source);
} }
@Override
public String getFormatName() {
return "SubStationAlpha";
}
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)
@ -48,7 +49,6 @@ public class SubStationAlphaReader extends SubtitleReader {
formatIndexText = lookup.indexOf("text"); formatIndexText = lookup.indexOf("text");
} }
@Override @Override
public SubtitleElement readNext() throws Exception { public SubtitleElement readNext() throws Exception {
if (format == null) { if (format == null) {
@ -84,7 +84,6 @@ public class SubStationAlphaReader extends SubtitleReader {
return new SubtitleElement(start, end, resolve(text)); return new SubtitleElement(start, end, resolve(text));
} }
protected String resolve(String text) { protected String resolve(String text) {
// remove tags // remove tags
text = tag.matcher(text).replaceAll(""); text = tag.matcher(text).replaceAll("");

View File

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

View File

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