From b6b1dcab2a7f37bb723721d1073becc367740145 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 21 Mar 2016 18:44:57 +0000 Subject: [PATCH] Better logging for bad subtitle files --- source/net/filebot/subtitle/MicroDVDReader.java | 5 +++++ source/net/filebot/subtitle/SubRipReader.java | 5 +++++ source/net/filebot/subtitle/SubStationAlphaReader.java | 9 ++++----- source/net/filebot/subtitle/SubViewerReader.java | 7 ++++--- source/net/filebot/subtitle/SubtitleReader.java | 4 +++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/subtitle/MicroDVDReader.java b/source/net/filebot/subtitle/MicroDVDReader.java index 42373d30..4860403a 100644 --- a/source/net/filebot/subtitle/MicroDVDReader.java +++ b/source/net/filebot/subtitle/MicroDVDReader.java @@ -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(); diff --git a/source/net/filebot/subtitle/SubRipReader.java b/source/net/filebot/subtitle/SubRipReader.java index 41d90322..05d34f82 100644 --- a/source/net/filebot/subtitle/SubRipReader.java +++ b/source/net/filebot/subtitle/SubRipReader.java @@ -26,6 +26,11 @@ public class SubRipReader extends SubtitleReader { tag = Pattern.compile("]*)>", Pattern.CASE_INSENSITIVE); } + @Override + public String getFormatName() { + return "SubRip"; + } + @Override protected SubtitleElement readNext() throws Exception { String number = scanner.nextLine(); diff --git a/source/net/filebot/subtitle/SubStationAlphaReader.java b/source/net/filebot/subtitle/SubStationAlphaReader.java index df8c3190..76bc4c5a 100644 --- a/source/net/filebot/subtitle/SubStationAlphaReader.java +++ b/source/net/filebot/subtitle/SubStationAlphaReader.java @@ -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(""); diff --git a/source/net/filebot/subtitle/SubViewerReader.java b/source/net/filebot/subtitle/SubViewerReader.java index bcf83065..18ddc300 100644 --- a/source/net/filebot/subtitle/SubViewerReader.java +++ b/source/net/filebot/subtitle/SubViewerReader.java @@ -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 { diff --git a/source/net/filebot/subtitle/SubtitleReader.java b/source/net/filebot/subtitle/SubtitleReader.java index 746acc0f..bfba205d 100644 --- a/source/net/filebot/subtitle/SubtitleReader.java +++ b/source/net/filebot/subtitle/SubtitleReader.java @@ -17,6 +17,8 @@ public abstract class SubtitleReader implements Iterator, 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, 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())); } }