From 5b11e05619b96802f650b1fd5c7198e8c469bece Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 6 Apr 2013 17:49:27 +0000 Subject: [PATCH] * take series rating into consideration when matching episodes of multiple shows with the same name --- .../filebot/similarity/EpisodeMetrics.java | 38 +++++++++++++++++-- .../filebot/similarity/TimeStampMetric.java | 3 +- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java index b1d23faf..87a992fa 100644 --- a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java +++ b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java @@ -11,13 +11,19 @@ import static net.sourceforge.tuned.FileUtilities.*; import static net.sourceforge.tuned.StringUtilities.*; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.media.ReleaseInfo; import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE; import net.sourceforge.filebot.vfs.FileInfo; @@ -25,6 +31,7 @@ import net.sourceforge.filebot.web.Date; import net.sourceforge.filebot.web.Episode; import net.sourceforge.filebot.web.EpisodeFormat; import net.sourceforge.filebot.web.Movie; +import net.sourceforge.filebot.web.TheTVDBClient.SeriesInfo; import com.ibm.icu.text.Transliterator; @@ -292,8 +299,10 @@ public enum EpisodeMetrics implements SimilarityMetric { // equally strip away strip potential any clutter try { object = releaseInfo.cleanRelease(singleton(object.toString()), strict).iterator().next(); - } catch (Exception e) { + } catch (NoSuchElementException e) { // keep default value in case all tokens are stripped away + } catch (IOException e) { + Logger.getLogger(EpisodeMetrics.class.getName()).log(Level.WARNING, e.getMessage()); } // simplify file name, if possible @@ -426,6 +435,29 @@ public enum EpisodeMetrics implements SimilarityMetric { } }), + SeriesRating(new SimilarityMetric() { + + @Override + public float getSimilarity(Object o1, Object o2) { + return max(getRating(o1), getRating(o2)) >= 0.4 ? 1 : 0; + } + + + public float getRating(Object o) { + if (o instanceof Episode) { + try { + SeriesInfo seriesInfo = WebServices.TheTVDB.getSeriesInfoByName(((Episode) o).getSeriesName(), Locale.ENGLISH); + if (seriesInfo != null && seriesInfo.getRatingCount() >= 10) { + return max(0, seriesInfo.getRating().floatValue()); + } + } catch (Exception e) { + Logger.getLogger(EpisodeMetrics.class.getName()).log(Level.WARNING, e.getMessage()); + } + } + return 0; + } + }), + // Match by stored MetaAttributes if possible MetaAttributes(new CrossPropertyMetric() { @@ -515,9 +547,9 @@ public enum EpisodeMetrics implements SimilarityMetric { // 7 pass: prefer episodes that were aired closer to the last modified date of the file // 8 pass: resolve remaining collisions via absolute string similarity if (includeFileMetrics) { - return new SimilarityMetric[] { FileSize, new MetricCascade(FileName, EpisodeFunnel), EpisodeBalancer, SubstringFields, MetaAttributes, new MetricCascade(NameSubstringSequence, Name), Numeric, NumericSequence, SeriesName, TimeStamp, AbsolutePath }; + return new SimilarityMetric[] { FileSize, new MetricCascade(FileName, EpisodeFunnel), EpisodeBalancer, SubstringFields, MetaAttributes, new MetricCascade(NameSubstringSequence, Name), Numeric, NumericSequence, SeriesName, SeriesRating, TimeStamp, AbsolutePath }; } else { - return new SimilarityMetric[] { EpisodeFunnel, EpisodeBalancer, SubstringFields, MetaAttributes, new MetricCascade(NameSubstringSequence, Name), Numeric, NumericSequence, SeriesName, TimeStamp, AbsolutePath }; + return new SimilarityMetric[] { EpisodeFunnel, EpisodeBalancer, SubstringFields, MetaAttributes, new MetricCascade(NameSubstringSequence, Name), Numeric, NumericSequence, SeriesName, SeriesRating, TimeStamp, AbsolutePath }; } } diff --git a/source/net/sourceforge/filebot/similarity/TimeStampMetric.java b/source/net/sourceforge/filebot/similarity/TimeStampMetric.java index 954fc56a..396070b8 100644 --- a/source/net/sourceforge/filebot/similarity/TimeStampMetric.java +++ b/source/net/sourceforge/filebot/similarity/TimeStampMetric.java @@ -40,8 +40,7 @@ public class TimeStampMetric implements SimilarityMetric { // ignore Java 6 issues return ((File) obj).lastModified(); } - } - if (obj instanceof Number) { + } else if (obj instanceof Number) { return ((Number) obj).longValue(); }