* support probing .ISO files for video disk hints to check if an .ISO file is a video disk or not

This commit is contained in:
Reinhard Pointner 2013-09-17 17:32:38 +00:00
parent a924855da0
commit 92a9eadf1c
4 changed files with 44 additions and 1 deletions

View File

@ -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) }

View File

@ -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;
}

View File

@ -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
}

View File

@ -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;