1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04: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,15 +25,15 @@ 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 {
private final RenameModel model; private final RenameModel model;
public MatchAction(RenameModel model) { public MatchAction(RenameModel model) {
this.model = model; this.model = model;
@ -42,17 +42,17 @@ class MatchAction extends AbstractAction {
putValue(SHORT_DESCRIPTION, "Match files and names"); putValue(SHORT_DESCRIPTION, "Match files and names");
} }
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
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,12 +65,12 @@ 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) {
final ProgressDialog progressDialog = new ProgressDialog(parent, worker); final ProgressDialog progressDialog = new ProgressDialog(parent, worker);
@ -91,24 +91,24 @@ class MatchAction extends AbstractAction {
return progressDialog; return progressDialog;
} }
protected class BackgroundMatcher extends SwingWorker<List<Match<Object, File>>, Void> implements Cancellable { protected class BackgroundMatcher extends SwingWorker<List<Match<Object, File>>, Void> implements Cancellable {
private final Matcher<Object, File> matcher; private final Matcher<Object, File> matcher;
public BackgroundMatcher(MatchModel<Object, File> model, SimilarityMetric[] metrics) { public BackgroundMatcher(MatchModel<Object, File> model, SimilarityMetric[] metrics) {
// match names against files // match names against files
this.matcher = new Matcher<Object, File>(model.values(), model.candidates(), false, metrics); this.matcher = new Matcher<Object, File>(model.values(), model.candidates(), false, metrics);
} }
@Override @Override
protected List<Match<Object, File>> doInBackground() throws Exception { protected List<Match<Object, File>> doInBackground() throws Exception {
return matcher.match(); return matcher.match();
} }
@Override @Override
protected void done() { protected void done() {
if (isCancelled()) if (isCancelled())
@ -129,7 +129,7 @@ class MatchAction extends AbstractAction {
} }
} }
@Override @Override
public boolean cancel() { public boolean cancel() {
return cancel(true); return cancel(true);

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

@ -24,17 +24,22 @@ public class Episode implements Serializable {
// episode airdate // episode airdate
private Date airdate; private Date airdate;
protected Episode() { protected Episode() {
// used by serializer // used by serializer
} }
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);
} }
public Episode(String seriesName, Date seriesStartDate, Integer season, Integer episode, String title, Integer absolute, Integer special, Date airdate) { public Episode(String seriesName, Date seriesStartDate, Integer season, Integer episode, String title, Integer absolute, Integer special, Date airdate) {
this.seriesName = seriesName; this.seriesName = seriesName;
this.seriesStartDate = seriesStartDate; this.seriesStartDate = seriesStartDate;
@ -46,47 +51,47 @@ public class Episode implements Serializable {
this.airdate = airdate; this.airdate = airdate;
} }
public String getSeriesName() { public String getSeriesName() {
return seriesName; return seriesName;
} }
public Date getSeriesStartDate() { public Date getSeriesStartDate() {
return seriesStartDate; return seriesStartDate;
} }
public Integer getEpisode() { public Integer getEpisode() {
return episode; return episode;
} }
public Integer getSeason() { public Integer getSeason() {
return season; return season;
} }
public String getTitle() { public String getTitle() {
return title; return title;
} }
public Integer getAbsolute() { public Integer getAbsolute() {
return absolute; return absolute;
} }
public Integer getSpecial() { public Integer getSpecial() {
return special; return special;
} }
public Date airdate() { public Date airdate() {
return airdate; return airdate;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Episode) { if (obj instanceof Episode) {
@ -97,7 +102,7 @@ public class Episode implements Serializable {
return false; return false;
} }
private boolean equals(Object o1, Object o2) { private boolean equals(Object o1, Object o2) {
if (o1 == null || o2 == null) if (o1 == null || o2 == null)
return o1 == o2; return o1 == o2;
@ -105,13 +110,13 @@ public class Episode implements Serializable {
return o1.equals(o2); return o1.equals(o2);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Arrays.hashCode(new Object[] { seriesName, season, episode, title, special }); return Arrays.hashCode(new Object[] { seriesName, season, episode, title, special });
} }
@Override @Override
public String toString() { public String toString() {
return EpisodeFormat.SeasonEpisode.format(this); return EpisodeFormat.SeasonEpisode.format(this);

View File

@ -10,29 +10,34 @@ public class Movie extends SearchResult {
protected int year; protected int year;
protected int imdbId; protected int imdbId;
protected Movie() { protected Movie() {
// used by serializer // used by serializer
} }
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;
this.imdbId = imdbId; this.imdbId = imdbId;
} }
public int getYear() { public int getYear() {
return year; return year;
} }
public int getImdbId() { public int getImdbId() {
return imdbId; return imdbId;
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (object instanceof Movie) { if (object instanceof Movie) {
@ -43,13 +48,19 @@ public class Movie extends SearchResult {
return false; return false;
} }
@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 });
} }
@Override @Override
public String toString() { public String toString() {
return String.format("%s (%d)", name, year); return String.format("%s (%d)", name, year);

View File

@ -7,24 +7,51 @@ public class MoviePart extends Movie {
protected final int partIndex; protected final int partIndex;
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;
} }
public int getPartIndex() { public int getPartIndex() {
return partIndex; return partIndex;
} }
public int getPartCount() { public int getPartCount() {
return partCount; return partCount;
} }
@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);