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

* make sure every matched object is a unique object (as required by Matcher)

This commit is contained in:
Reinhard Pointner 2012-02-16 07:19:12 +00:00
parent 2fa9b625fa
commit dd9e0bdc22
6 changed files with 88 additions and 45 deletions

View File

@ -218,8 +218,8 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
for (File file : derivateFiles) { for (File file : derivateFiles) {
for (Match<File, ?> match : matches) { for (Match<File, ?> match : matches) {
if (file.getParentFile().equals(match.getValue().getParentFile()) && isDerived(file, match.getValue())) { if (file.getParentFile().equals(match.getValue().getParentFile()) && isDerived(file, match.getValue()) && match.getCandidate() instanceof Episode) {
derivateMatches.add(new Match<File, Object>(file, match.getCandidate())); derivateMatches.add(new Match<File, Object>(file, new Episode((Episode) match.getCandidate())));
break; break;
} }
} }

View File

@ -25,8 +25,8 @@ import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.Matcher; import net.sourceforge.filebot.similarity.Matcher;
import net.sourceforge.filebot.similarity.SimilarityMetric; import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.tuned.ui.ProgressDialog; import net.sourceforge.tuned.ui.ProgressDialog;
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
import net.sourceforge.tuned.ui.ProgressDialog.Cancellable; import net.sourceforge.tuned.ui.ProgressDialog.Cancellable;
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
class MatchAction extends AbstractAction { class MatchAction extends AbstractAction {
@ -47,12 +47,12 @@ class MatchAction extends AbstractAction {
if (model.names().isEmpty() || model.files().isEmpty()) if (model.names().isEmpty() || model.files().isEmpty())
return; return;
Window window = getWindow(evt.getSource());
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true)); BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
backgroundMatcher.execute(); backgroundMatcher.execute();
Window window = getWindow(evt.getSource());
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try { try {
// wait a for little while (matcher might finish in less than a second) // wait a for little while (matcher might finish in less than a second)
backgroundMatcher.get(2, TimeUnit.SECONDS); backgroundMatcher.get(2, TimeUnit.SECONDS);
@ -65,10 +65,10 @@ class MatchAction extends AbstractAction {
dialog.setVisible(true); dialog.setVisible(true);
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
} } finally {
window.setCursor(Cursor.getDefaultCursor()); window.setCursor(Cursor.getDefaultCursor());
} }
}
protected ProgressDialog createProgressDialog(Window parent, final BackgroundMatcher worker) { protected ProgressDialog createProgressDialog(Window parent, final BackgroundMatcher worker) {

View File

@ -180,13 +180,13 @@ class MovieHashMatcher implements AutoCompleteMatcher {
moviePart = new MoviePart(moviePart, i + 1, fileSet.size()); moviePart = new MoviePart(moviePart, i + 1, fileSet.size());
} }
matches.add(new Match<File, Movie>(fileSet.get(i), moviePart)); matches.add(new Match<File, Movie>(fileSet.get(i), moviePart.clone()));
// automatically add matches for derivate files // automatically add matches for derivate files
List<File> derivates = derivatesByMovieFile.get(fileSet.get(i)); List<File> derivates = derivatesByMovieFile.get(fileSet.get(i));
if (derivates != null) { if (derivates != null) {
for (File derivate : derivates) { for (File derivate : derivates) {
matches.add(new Match<File, Movie>(derivate, moviePart)); matches.add(new Match<File, Movie>(derivate, moviePart.clone()));
} }
} }
} }

View File

@ -30,6 +30,11 @@ public class Episode implements Serializable {
} }
public Episode(Episode obj) {
this(obj.seriesName, obj.seriesStartDate, obj.season, obj.episode, obj.title, obj.absolute, obj.special, obj.airdate);
}
public Episode(String seriesName, Date seriesStartDate, Integer season, Integer episode, String title) { public Episode(String seriesName, Date seriesStartDate, Integer season, Integer episode, String title) {
this(seriesName, seriesStartDate, season, episode, title, null, null, null); this(seriesName, seriesStartDate, season, episode, title, null, null, null);
} }

View File

@ -16,6 +16,11 @@ public class Movie extends SearchResult {
} }
public Movie(Movie obj) {
this(obj.name, obj.year, obj.imdbId);
}
public Movie(String name, int year, int imdbId) { public Movie(String name, int year, int imdbId) {
super(name); super(name);
this.year = year; this.year = year;
@ -44,6 +49,12 @@ public class Movie extends SearchResult {
} }
@Override
public Movie clone() {
return new Movie(this);
}
@Override @Override
public int hashCode() { public int hashCode() {
return Arrays.hashCode(new Object[] { name, year, imdbId }); return Arrays.hashCode(new Object[] { name, year, imdbId });

View File

@ -8,8 +8,18 @@ public class MoviePart extends Movie {
protected final int partCount; protected final int partCount;
public MoviePart(MoviePart obj) {
this(obj.name, obj.year, obj.imdbId, obj.partIndex, obj.partCount);
}
public MoviePart(Movie movie, int partIndex, int partCount) { public MoviePart(Movie movie, int partIndex, int partCount) {
super(movie.name, movie.year, movie.imdbId); this(movie.name, movie.year, movie.imdbId, partIndex, partCount);
}
public MoviePart(String name, int year, int imdbId, int partIndex, int partCount) {
super(name, year, imdbId);
this.partIndex = partIndex; this.partIndex = partIndex;
this.partCount = partCount; this.partCount = partCount;
} }
@ -25,6 +35,23 @@ public class MoviePart extends Movie {
} }
@Override
public boolean equals(Object object) {
if (object instanceof MoviePart && super.equals(object)) {
MoviePart other = (MoviePart) object;
return partIndex == other.partIndex && partCount == other.partCount;
}
return super.equals(object);
}
@Override
public MoviePart clone() {
return new MoviePart(this);
}
@Override @Override
public String toString() { public String toString() {
return String.format("%s (%d) [%d]", name, year, partIndex); return String.format("%s (%d) [%d]", name, year, partIndex);