From 92a9eadf1c06994fef1dcada2cbe13ce7fe1d335 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 17 Sep 2013 17:32:38 +0000 Subject: [PATCH] * support probing .ISO files for video disk hints to check if an .ISO file is a video disk or not --- .../filebot/cli/ScriptShell.lib.groovy | 2 +- .../filebot/media/MediaDetection.java | 18 +++++++++++++++++ .../filebot/media/ReleaseInfo.java | 5 +++++ .../net/sourceforge/tuned/FileUtilities.java | 20 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index c965353c..913416f7 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -15,7 +15,7 @@ File.metaClass.isAudio = { _types.getFilter("audio").accept(delegate) } File.metaClass.isSubtitle = { _types.getFilter("subtitle").accept(delegate) } File.metaClass.isVerification = { _types.getFilter("verification").accept(delegate) } File.metaClass.isArchive = { _types.getFilter("archive").accept(delegate) } -File.metaClass.isDisk = { MediaDetection.isDiskFolder(delegate) } +File.metaClass.isDisk = { (delegate.isDirectory() && MediaDetection.isDiskFolder(delegate)) || (delegate.isFile() && _types.getFilter("video/iso").accept(delegate) && MediaDetection.isVideoDiskFile(delegate)) } File.metaClass.getDir = { getParentFile() } File.metaClass.hasFile = { c -> isDirectory() && listFiles().find(c) } diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 4f18b7b4..5d484051 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -38,6 +38,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import net.sourceforge.filebot.WebServices; +import net.sourceforge.filebot.archive.Archive; import net.sourceforge.filebot.similarity.CommonSequenceMatcher; import net.sourceforge.filebot.similarity.DateMatcher; import net.sourceforge.filebot.similarity.DateMetric; @@ -88,6 +89,23 @@ public class MediaDetection { return getClutterFileFilter().accept(file); } + public static boolean isVideoDiskFile(File file) throws Exception { + FileFilter diskFolderEntryFilter = releaseInfo.getDiskFolderEntryFilter(); + Archive iso = new Archive(file); + try { + for (File path : iso.listFiles()) { + for (File entry : listPath(path)) { + if (diskFolderEntryFilter.accept(entry)) { + return true; + } + } + } + return false; + } finally { + iso.close(); + } + } + public static boolean isEpisode(String name, boolean strict) { return parseEpisodeNumber(name, strict) != null || parseDate(name) != null; } diff --git a/source/net/sourceforge/filebot/media/ReleaseInfo.java b/source/net/sourceforge/filebot/media/ReleaseInfo.java index 8b4560e1..9c845d2a 100644 --- a/source/net/sourceforge/filebot/media/ReleaseInfo.java +++ b/source/net/sourceforge/filebot/media/ReleaseInfo.java @@ -36,6 +36,7 @@ import net.sourceforge.filebot.web.CachedResource; import net.sourceforge.filebot.web.Movie; import net.sourceforge.filebot.web.TheTVDBSearchResult; import net.sourceforge.tuned.ByteBufferInputStream; +import net.sourceforge.tuned.FileUtilities.RegexFileFilter; import org.tukaani.xz.XZInputStream; @@ -240,6 +241,10 @@ public class ReleaseInfo { return new FolderEntryFilter(compile(getBundle(getClass().getName()).getString("pattern.diskfolder.entry"))); } + public FileFilter getDiskFolderEntryFilter() { + return new RegexFileFilter(compile(getBundle(getClass().getName()).getString("pattern.diskfolder.entry"))); + } + public FileFilter getClutterFileFilter() throws IOException { return new ClutterFileFilter(getExcludePattern(), 262144000); // only files smaller than 250 MB may be considered clutter } diff --git a/source/net/sourceforge/tuned/FileUtilities.java b/source/net/sourceforge/tuned/FileUtilities.java index 9cc8b650..5818b639 100644 --- a/source/net/sourceforge/tuned/FileUtilities.java +++ b/source/net/sourceforge/tuned/FileUtilities.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -622,6 +623,25 @@ public final class FileUtilities { } } + public static class RegexFileFilter implements FileFilter, FilenameFilter { + + private final Pattern pattern; + + public RegexFileFilter(Pattern pattern) { + this.pattern = pattern; + } + + @Override + public boolean accept(File dir, String name) { + return pattern.matcher(name).find(); + } + + @Override + public boolean accept(File file) { + return accept(file.getParentFile(), file.getName()); + } + } + public static class NotFileFilter implements FileFilter { public FileFilter filter;