1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-17 14:55:09 -05:00

* pre-cluster by folder before using the nm-Matcher as to to avoid exponential time increase problems

This commit is contained in:
Reinhard Pointner 2014-01-01 09:30:38 +00:00
parent 85953f2753
commit 23cff2321c
2 changed files with 72 additions and 38 deletions

View File

@ -895,6 +895,36 @@ public class MediaDetection {
return releaseInfo.getStructureRootPattern().matcher(folder.getName()).matches(); return releaseInfo.getStructureRootPattern().matcher(folder.getName()).matches();
} }
public static Map<File, List<File>> mapByMediaFolder(Collection<File> files) {
Map<File, List<File>> mediaFolders = new HashMap<File, List<File>>();
for (File f : files) {
File folder = guessMediaFolder(f);
List<File> value = mediaFolders.get(folder);
if (value == null) {
value = new ArrayList<File>();
mediaFolders.put(folder, value);
}
value.add(f);
}
return mediaFolders;
}
public static File guessMediaFolder(File file) {
List<File> tail = listPathTail(file, 3, true);
// skip file itself (first entry)
for (int i = 1; i < tail.size(); i++) {
File folder = tail.get(i);
String term = stripReleaseInfo(folder.getName());
if (term.length() > 0) {
return folder;
}
}
// simply default to parent folder
return file.getParentFile();
}
public static List<String> stripReleaseInfo(Collection<String> names, boolean strict) throws IOException { public static List<String> stripReleaseInfo(Collection<String> names, boolean strict) throws IOException {
return releaseInfo.cleanRelease(names, strict); return releaseInfo.cleanRelease(names, strict);
} }

View File

@ -923,10 +923,14 @@ class SubtitleAutoMatchDialog extends JDialog {
} }
@Override @Override
protected Map<File, List<SubtitleDescriptor>> getSubtitleList(Collection<File> files, String languageName, Component parent) throws Exception { protected Map<File, List<SubtitleDescriptor>> getSubtitleList(Collection<File> fileSet, String languageName, Component parent) throws Exception {
// ignore clutter files from processing // ignore clutter files from processing
files = filter(files, not(getClutterFileFilter())); fileSet = filter(fileSet, not(getClutterFileFilter()));
// collect results
Map<File, List<SubtitleDescriptor>> subtitlesByFile = new HashMap<File, List<SubtitleDescriptor>>();
for (List<File> files : mapByMediaFolder(fileSet).values()) {
// auto-detect query and search for subtitles // auto-detect query and search for subtitles
Collection<String> querySet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); Collection<String> querySet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
@ -944,13 +948,13 @@ class SubtitleAutoMatchDialog extends JDialog {
List<SubtitleDescriptor> subtitles = findSubtitles(service, querySet, languageName); List<SubtitleDescriptor> subtitles = findSubtitles(service, querySet, languageName);
// if auto-detection fails, ask user for input
if (subtitles.isEmpty()) {
// dialog may have been cancelled by now // dialog may have been cancelled by now
if (Thread.interrupted()) { if (Thread.interrupted()) {
throw new CancellationException(); throw new CancellationException();
} }
// if auto-detection fails, ask user for input
if (subtitles.isEmpty()) {
querySet = inputProvider.getUserQuery(join(querySet, ","), service.getName(), parent); querySet = inputProvider.getUserQuery(join(querySet, ","), service.getName(), parent);
subtitles = findSubtitles(service, querySet, languageName); subtitles = findSubtitles(service, querySet, languageName);
@ -961,7 +965,6 @@ class SubtitleAutoMatchDialog extends JDialog {
} }
// files by possible subtitles matches // files by possible subtitles matches
Map<File, List<SubtitleDescriptor>> subtitlesByFile = new HashMap<File, List<SubtitleDescriptor>>();
for (File file : files) { for (File file : files) {
subtitlesByFile.put(file, new ArrayList<SubtitleDescriptor>()); subtitlesByFile.put(file, new ArrayList<SubtitleDescriptor>());
} }
@ -983,6 +986,7 @@ class SubtitleAutoMatchDialog extends JDialog {
} }
} }
} }
}
return subtitlesByFile; return subtitlesByFile;
} }