1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 16:28:51 -05:00

* better performance for SxE/Airdate matching

This commit is contained in:
Reinhard Pointner 2011-11-13 18:29:25 +00:00
parent cfee1cbb51
commit 9c55decf67
4 changed files with 39 additions and 13 deletions

View File

@ -150,7 +150,7 @@ public class CmdlineOperations implements CmdlineInterface {
if (strict) { if (strict) {
sequence = new SimilarityMetric[] { StrictMetric.EpisodeIdentifier, StrictMetric.Title, StrictMetric.Name }; // use SEI for matching and SN for excluding false positives sequence = new SimilarityMetric[] { StrictMetric.EpisodeIdentifier, StrictMetric.Title, StrictMetric.Name }; // use SEI for matching and SN for excluding false positives
} else { } else {
sequence = MatchSimilarityMetric.defaultSequence(); // same as in GUI sequence = MatchSimilarityMetric.defaultSequence(false); // same as in GUI
} }
List<Match<File, Episode>> matches = new ArrayList<Match<File, Episode>>(); List<Match<File, Episode>> matches = new ArrayList<Match<File, Episode>>();

View File

@ -192,7 +192,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
// group by subtitles first and then by files in general // group by subtitles first and then by files in general
for (List<File> filesPerType : mapByExtension(mediaFiles).values()) { for (List<File> filesPerType : mapByExtension(mediaFiles).values()) {
Matcher<File, Episode> matcher = new Matcher<File, Episode>(filesPerType, episodes, false, MatchSimilarityMetric.defaultSequence()); Matcher<File, Episode> matcher = new Matcher<File, Episode>(filesPerType, episodes, false, MatchSimilarityMetric.defaultSequence(false));
matches.addAll(matcher.match()); matches.addAll(matcher.match());
} }

View File

@ -49,7 +49,7 @@ class MatchAction extends AbstractAction {
Window window = getWindow(evt.getSource()); Window window = getWindow(evt.getSource());
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, MatchSimilarityMetric.defaultSequence()); BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, MatchSimilarityMetric.defaultSequence(true));
backgroundMatcher.execute(); backgroundMatcher.execute();
try { try {

View File

@ -3,12 +3,14 @@ package net.sourceforge.filebot.ui.rename;
import static java.lang.Math.*; import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static net.sourceforge.tuned.FileUtilities.*; import static net.sourceforge.tuned.FileUtilities.*;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Map;
import java.util.WeakHashMap;
import net.sourceforge.filebot.similarity.DateMetric; import net.sourceforge.filebot.similarity.DateMetric;
import net.sourceforge.filebot.similarity.FileSizeMetric; import net.sourceforge.filebot.similarity.FileSizeMetric;
@ -65,8 +67,16 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
// Match by season / episode numbers // Match by season / episode numbers
SeasonEpisode(new SeasonEpisodeMetric() { SeasonEpisode(new SeasonEpisodeMetric() {
private final Map<Object, Collection<SxE>> matchCache = synchronizedMap(new WeakHashMap<Object, Collection<SxE>>(64, 4));
@Override @Override
protected Collection<SxE> parse(Object object) { protected Collection<SxE> parse(Object object) {
Collection<SxE> result = matchCache.get(object);
if (result != null) {
return result;
}
if (object instanceof Episode) { if (object instanceof Episode) {
Episode episode = (Episode) object; Episode episode = (Episode) object;
@ -74,26 +84,39 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
SxE seasonEpisode = new SxE(episode.getSeason(), episode.getEpisode()); SxE seasonEpisode = new SxE(episode.getSeason(), episode.getEpisode());
SxE absoluteEpisode = new SxE(null, episode.getAbsolute()); SxE absoluteEpisode = new SxE(null, episode.getAbsolute());
return seasonEpisode.equals(absoluteEpisode) ? Collections.singleton(absoluteEpisode) : Arrays.asList(seasonEpisode, absoluteEpisode); result = seasonEpisode.equals(absoluteEpisode) ? singleton(absoluteEpisode) : asList(seasonEpisode, absoluteEpisode);
} else {
result = super.parse(object);
} }
return super.parse(object); matchCache.put(object, result);
return result;
} }
}), }),
// Match episode airdate // Match episode airdate
AirDate(new DateMetric() { AirDate(new DateMetric() {
private final Map<Object, Date> matchCache = synchronizedMap(new WeakHashMap<Object, Date>(64, 4));
@Override @Override
protected Date parse(Object object) { protected Date parse(Object object) {
if (object instanceof Episode) { if (object instanceof Episode) {
Episode episode = (Episode) object; Episode episode = (Episode) object;
// create SxE from episode // use airdate from episode
return episode.airdate(); return episode.airdate();
} }
return super.parse(object); Date result = matchCache.get(object);
if (result != null) {
return result;
}
result = super.parse(object);
matchCache.put(object, result);
return result;
} }
}), }),
@ -152,7 +175,6 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
return new Object[] { object }; return new Object[] { object };
} }
}), }),
// Match by generic name similarity // Match by generic name similarity
@ -220,13 +242,17 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
} }
public static SimilarityMetric[] defaultSequence() { public static SimilarityMetric[] defaultSequence(boolean includeFileMetrics) {
// 1. pass: match by file length (fast, but only works when matching torrents or files) // 1. pass: match by file length (fast, but only works when matching torrents or files)
// 2. pass: match by season / episode numbers // 2. pass: match by season / episode numbers
// 3. pass: match by checking series/episode title against the file path // 3. pass: match by checking series / episode title against the file path
// 4. pass: match by generic name similarity (slow, but most matches will have been determined in second pass) // 4. pass: match by generic name similarity (slow, but most matches will have been determined in second pass)
// 5. pass: match by generic numeric similarity // 5. pass: match by generic numeric similarity
return new SimilarityMetric[] { FileSize, EpisodeIdentifier, Title, Name, Numeric }; if (includeFileMetrics) {
return new SimilarityMetric[] { FileSize, EpisodeIdentifier, Title, Name, Numeric };
} else {
return new SimilarityMetric[] { EpisodeIdentifier, Title, Name, Numeric };
}
} }
} }