1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 16:28: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 (Match<File, ?> match : matches) {
if (file.getParentFile().equals(match.getValue().getParentFile()) && isDerived(file, match.getValue())) {
derivateMatches.add(new Match<File, Object>(file, match.getCandidate()));
if (file.getParentFile().equals(match.getValue().getParentFile()) && isDerived(file, match.getValue()) && match.getCandidate() instanceof Episode) {
derivateMatches.add(new Match<File, Object>(file, new Episode((Episode) match.getCandidate())));
break;
}
}

View File

@ -25,15 +25,15 @@ import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.Matcher;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.tuned.ui.ProgressDialog;
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
import net.sourceforge.tuned.ui.ProgressDialog.Cancellable;
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
class MatchAction extends AbstractAction {
private final RenameModel model;
public MatchAction(RenameModel model) {
this.model = model;
@ -42,17 +42,17 @@ class MatchAction extends AbstractAction {
putValue(SHORT_DESCRIPTION, "Match files and names");
}
public void actionPerformed(ActionEvent evt) {
if (model.names().isEmpty() || model.files().isEmpty())
return;
Window window = getWindow(evt.getSource());
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
backgroundMatcher.execute();
Window window = getWindow(evt.getSource());
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
// wait a for little while (matcher might finish in less than a second)
backgroundMatcher.get(2, TimeUnit.SECONDS);
@ -65,12 +65,12 @@ class MatchAction extends AbstractAction {
dialog.setVisible(true);
} catch (Exception 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) {
final ProgressDialog progressDialog = new ProgressDialog(parent, worker);
@ -91,24 +91,24 @@ class MatchAction extends AbstractAction {
return progressDialog;
}
protected class BackgroundMatcher extends SwingWorker<List<Match<Object, File>>, Void> implements Cancellable {
private final Matcher<Object, File> matcher;
public BackgroundMatcher(MatchModel<Object, File> model, SimilarityMetric[] metrics) {
// match names against files
this.matcher = new Matcher<Object, File>(model.values(), model.candidates(), false, metrics);
}
@Override
protected List<Match<Object, File>> doInBackground() throws Exception {
return matcher.match();
}
@Override
protected void done() {
if (isCancelled())
@ -129,7 +129,7 @@ class MatchAction extends AbstractAction {
}
}
@Override
public boolean cancel() {
return cancel(true);

View File

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

View File

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