From 06815469f6e527ef3b15a28d47deb2bc88e22718 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 30 Apr 2016 22:43:30 +0800 Subject: [PATCH] // ignore drawing commands (http://docs.aegisub.org/3.2/ASS_Tags/#drawing-commands) --- source/net/filebot/subtitle/SubStationAlphaReader.java | 9 +++++++-- source/net/filebot/subtitle/SubtitleFormat.java | 5 +---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/subtitle/SubStationAlphaReader.java b/source/net/filebot/subtitle/SubStationAlphaReader.java index 76bc4c5a..c108401c 100644 --- a/source/net/filebot/subtitle/SubStationAlphaReader.java +++ b/source/net/filebot/subtitle/SubStationAlphaReader.java @@ -11,7 +11,8 @@ public class SubStationAlphaReader extends SubtitleReader { private final DateFormat timeFormat = new SubtitleTimeFormat(); private final Pattern newline = Pattern.compile(Pattern.quote("\\n"), Pattern.CASE_INSENSITIVE); - private final Pattern tag = Pattern.compile("[{]\\\\[^}]+[}]"); + private final Pattern tags = Pattern.compile("[{]\\\\[^}]+[}]"); + private final Pattern drawingTags = Pattern.compile("\\\\[p][0-4]"); // ignore drawing commands (http://docs.aegisub.org/3.2/ASS_Tags/#drawing-commands) private String[] format; private int formatIndexStart; @@ -81,12 +82,16 @@ public class SubStationAlphaReader extends SubtitleReader { long end = timeFormat.parse(values[formatIndexEnd].trim()).getTime(); String text = values[formatIndexText].trim(); + // ignore drawing instructions + if (drawingTags.matcher(text).find()) + return null; + return new SubtitleElement(start, end, resolve(text)); } protected String resolve(String text) { // remove tags - text = tag.matcher(text).replaceAll(""); + text = tags.matcher(text).replaceAll(""); // resolve line breaks return newline.matcher(text).replaceAll("\n"); diff --git a/source/net/filebot/subtitle/SubtitleFormat.java b/source/net/filebot/subtitle/SubtitleFormat.java index 71b83649..6eb4262e 100644 --- a/source/net/filebot/subtitle/SubtitleFormat.java +++ b/source/net/filebot/subtitle/SubtitleFormat.java @@ -1,11 +1,9 @@ package net.filebot.subtitle; - import net.filebot.MediaTypes; import net.filebot.util.FileUtilities.ExtensionFileFilter; - public enum SubtitleFormat { SubRip { @@ -42,9 +40,8 @@ public enum SubtitleFormat { public abstract SubtitleReader newReader(Readable readable); - public ExtensionFileFilter getFilter() { - return MediaTypes.getDefaultFilter("subtitle/" + this.name()); + return MediaTypes.getDefaultFilter("subtitle/" + name()); } }