1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-04 16:35:08 -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();
}
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 {
return releaseInfo.cleanRelease(names, strict);
}

View File

@ -923,63 +923,67 @@ class SubtitleAutoMatchDialog extends JDialog {
}
@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
files = filter(files, not(getClutterFileFilter()));
fileSet = filter(fileSet, not(getClutterFileFilter()));
// auto-detect query and search for subtitles
Collection<String> querySet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
// collect results
Map<File, List<SubtitleDescriptor>> subtitlesByFile = new HashMap<File, List<SubtitleDescriptor>>();
// auto-detect series names
querySet.addAll(detectSeriesNames(files, Locale.ROOT));
for (List<File> files : mapByMediaFolder(fileSet).values()) {
// auto-detect query and search for subtitles
Collection<String> querySet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
// auto-detect movie names
for (File f : files) {
if (!isEpisode(f.getName(), false)) {
for (Movie movie : detectMovie(f, null, null, Locale.ROOT, false)) {
querySet.add(movie.getName());
// auto-detect series names
querySet.addAll(detectSeriesNames(files, Locale.ROOT));
// auto-detect movie names
for (File f : files) {
if (!isEpisode(f.getName(), false)) {
for (Movie movie : detectMovie(f, null, null, Locale.ROOT, false)) {
querySet.add(movie.getName());
}
}
}
}
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
if (Thread.interrupted()) {
throw new CancellationException();
}
querySet = inputProvider.getUserQuery(join(querySet, ","), service.getName(), parent);
subtitles = findSubtitles(service, querySet, languageName);
// still no luck... na women ye mei banfa
// if auto-detection fails, ask user for input
if (subtitles.isEmpty()) {
throw new Exception("Unable to lookup subtitles: " + querySet);
querySet = inputProvider.getUserQuery(join(querySet, ","), service.getName(), parent);
subtitles = findSubtitles(service, querySet, languageName);
// still no luck... na women ye mei banfa
if (subtitles.isEmpty()) {
throw new Exception("Unable to lookup subtitles: " + querySet);
}
}
}
// files by possible subtitles matches
Map<File, List<SubtitleDescriptor>> subtitlesByFile = new HashMap<File, List<SubtitleDescriptor>>();
for (File file : files) {
subtitlesByFile.put(file, new ArrayList<SubtitleDescriptor>());
}
// files by possible subtitles matches
for (File file : files) {
subtitlesByFile.put(file, new ArrayList<SubtitleDescriptor>());
}
// first match everything as best as possible, then filter possibly bad matches
for (Entry<File, SubtitleDescriptor> it : matchSubtitles(files, subtitles, false).entrySet()) {
subtitlesByFile.get(it.getKey()).add(it.getValue());
}
// first match everything as best as possible, then filter possibly bad matches
for (Entry<File, SubtitleDescriptor> it : matchSubtitles(files, subtitles, false).entrySet()) {
subtitlesByFile.get(it.getKey()).add(it.getValue());
}
// add other possible matches to the options
SimilarityMetric sanity = EpisodeMetrics.verificationMetric();
float minMatchSimilarity = 0.5f;
// add other possible matches to the options
SimilarityMetric sanity = EpisodeMetrics.verificationMetric();
float minMatchSimilarity = 0.5f;
for (File file : files) {
// add matching subtitles
for (SubtitleDescriptor it : subtitles) {
if (!subtitlesByFile.get(file).contains(it) && sanity.getSimilarity(file, it) >= minMatchSimilarity) {
subtitlesByFile.get(file).add(it);
for (File file : files) {
// add matching subtitles
for (SubtitleDescriptor it : subtitles) {
if (!subtitlesByFile.get(file).contains(it) && sanity.getSimilarity(file, it) >= minMatchSimilarity) {
subtitlesByFile.get(file).add(it);
}
}
}
}