From e771cf39a5c2640b86010b1edba32a428a8c5bb4 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 13 Jul 2013 10:01:33 +0000 Subject: [PATCH] + store series info with each episode object and add new bindings {series} {primaryTitle} and {json} for debugging the info object --- .../net/sourceforge/filebot/WebServices.java | 2 + .../filebot/format/MediaBindingBean.java | 36 ++++++++- .../filebot/media/MediaDetection.java | 8 +- .../filebot/media/ReleaseInfo.java | 6 +- .../filebot/similarity/EpisodeMetrics.java | 4 +- .../filebot/ui/rename/FormatDialog.properties | 2 +- .../sourceforge/filebot/web/AnidbClient.java | 69 +--------------- .../filebot/web/AnidbSearchResult.java | 65 +++++++++++++++ .../net/sourceforge/filebot/web/Episode.java | 19 +++-- .../filebot/web/EpisodeFormat.java | 6 +- .../filebot/web/SerienjunkiesClient.java | 74 +---------------- .../web/SerienjunkiesSearchResult.java | 79 +++++++++++++++++++ .../sourceforge/filebot/web/TVRageClient.java | 50 +----------- .../filebot/web/TVRageSearchResult.java | 53 +++++++++++++ .../filebot/web/TheTVDBClient.java | 78 +----------------- .../filebot/web/TheTVDBSearchResult.java | 46 +++++++++++ .../similarity/EpisodeMetricsTest.java | 22 +++--- .../filebot/web/AnidbClientTest.java | 7 +- .../filebot/web/SerienjunkiesClientTest.java | 3 +- .../filebot/web/TVRageClientTest.java | 5 +- .../filebot/web/TheTVDBClientTest.java | 9 +-- 21 files changed, 335 insertions(+), 308 deletions(-) create mode 100644 source/net/sourceforge/filebot/web/AnidbSearchResult.java create mode 100644 source/net/sourceforge/filebot/web/SerienjunkiesSearchResult.java create mode 100644 source/net/sourceforge/filebot/web/TVRageSearchResult.java create mode 100644 source/net/sourceforge/filebot/web/TheTVDBSearchResult.java diff --git a/source/net/sourceforge/filebot/WebServices.java b/source/net/sourceforge/filebot/WebServices.java index 8e75c327..3b6f5319 100644 --- a/source/net/sourceforge/filebot/WebServices.java +++ b/source/net/sourceforge/filebot/WebServices.java @@ -23,6 +23,7 @@ import java.util.logging.Logger; import net.sourceforge.filebot.media.MediaDetection; import net.sourceforge.filebot.web.AcoustID; import net.sourceforge.filebot.web.AnidbClient; +import net.sourceforge.filebot.web.AnidbSearchResult; import net.sourceforge.filebot.web.EpisodeListProvider; import net.sourceforge.filebot.web.FanartTV; import net.sourceforge.filebot.web.ID3Lookup; @@ -37,6 +38,7 @@ import net.sourceforge.filebot.web.SubtitleProvider; import net.sourceforge.filebot.web.TMDbClient; import net.sourceforge.filebot.web.TVRageClient; import net.sourceforge.filebot.web.TheTVDBClient; +import net.sourceforge.filebot.web.TheTVDBSearchResult; import net.sourceforge.filebot.web.VideoHashSubtitleService; diff --git a/source/net/sourceforge/filebot/format/MediaBindingBean.java b/source/net/sourceforge/filebot/format/MediaBindingBean.java index 4714c566..cd9be181 100644 --- a/source/net/sourceforge/filebot/format/MediaBindingBean.java +++ b/source/net/sourceforge/filebot/format/MediaBindingBean.java @@ -35,16 +35,21 @@ import net.sourceforge.filebot.media.MetaAttributes; import net.sourceforge.filebot.mediainfo.MediaInfo; import net.sourceforge.filebot.mediainfo.MediaInfo.StreamKind; import net.sourceforge.filebot.similarity.SimilarityComparator; +import net.sourceforge.filebot.web.AnidbSearchResult; import net.sourceforge.filebot.web.AudioTrack; import net.sourceforge.filebot.web.Date; import net.sourceforge.filebot.web.Episode; import net.sourceforge.filebot.web.Movie; import net.sourceforge.filebot.web.MoviePart; import net.sourceforge.filebot.web.MultiEpisode; +import net.sourceforge.filebot.web.SearchResult; import net.sourceforge.filebot.web.SortOrder; +import net.sourceforge.filebot.web.TheTVDBSearchResult; import net.sourceforge.tuned.FileUtilities; import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter; +import com.cedarsoftware.util.io.JsonWriter; + public class MediaBindingBean { @@ -153,7 +158,7 @@ public class MediaBindingBean { @Define("d") public Object getReleaseDate() { if (infoObject instanceof Episode) { - return getEpisode().airdate(); + return getEpisode().getAirdate(); } if (infoObject instanceof Movie) { return getMetaInfo().getProperty("released"); @@ -169,7 +174,7 @@ public class MediaBindingBean { @Define("airdate") public Date airdate() { - return getEpisode().airdate(); + return getEpisode().getAirdate(); } @@ -191,6 +196,27 @@ public class MediaBindingBean { } + @Define("series") + public SearchResult getSeriesObject() { + return getEpisode().getSeries(); + } + + + @Define("primaryTitle") + public String getOfficialTitle() throws Exception { + System.out.println(getSeriesObject()); + if (getSeriesObject() instanceof TheTVDBSearchResult) { + return WebServices.TheTVDB.getSeriesInfo((TheTVDBSearchResult) getSeriesObject(), Locale.ENGLISH).getName(); + } + if (getSeriesObject() instanceof AnidbSearchResult) { + return ((AnidbSearchResult) getSeriesObject()).getPrimaryTitle(); + } + + // default to original search result + return getSeriesObject().getName(); + } + + @Define("tmdbid") public String getTmdbId() throws Exception { int tmdbid = getMovie().getTmdbId(); @@ -682,6 +708,12 @@ public class MediaBindingBean { } + @Define("json") + public String getInfoObjectDump() throws Exception { + return JsonWriter.objectToJson(infoObject); + } + + private File getInferredMediaFile() { // make sure media file is defined checkMediaFile(); diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index f7ef8178..84fa3c3a 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -52,14 +52,14 @@ import net.sourceforge.filebot.similarity.SequenceMatchSimilarity; import net.sourceforge.filebot.similarity.SeriesNameMatcher; import net.sourceforge.filebot.similarity.SimilarityComparator; import net.sourceforge.filebot.similarity.SimilarityMetric; -import net.sourceforge.filebot.web.AnidbClient.AnidbSearchResult; +import net.sourceforge.filebot.web.AnidbSearchResult; import net.sourceforge.filebot.web.Date; import net.sourceforge.filebot.web.Episode; import net.sourceforge.filebot.web.Movie; import net.sourceforge.filebot.web.MovieIdentificationService; import net.sourceforge.filebot.web.SearchResult; import net.sourceforge.filebot.web.TheTVDBClient.SeriesInfo; -import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult; +import net.sourceforge.filebot.web.TheTVDBSearchResult; public class MediaDetection { @@ -1007,8 +1007,8 @@ public class MediaDetection { try { if (model instanceof Episode) { Episode episode = (Episode) model; - if (episode.airdate() != null) { - xattr.setCreationDate(episode.airdate().getTimeStamp()); + if (episode.getAirdate() != null) { + xattr.setCreationDate(episode.getAirdate().getTimeStamp()); } } else if (model instanceof Movie) { Movie movie = (Movie) model; diff --git a/source/net/sourceforge/filebot/media/ReleaseInfo.java b/source/net/sourceforge/filebot/media/ReleaseInfo.java index 80f78aa8..b7c26b28 100644 --- a/source/net/sourceforge/filebot/media/ReleaseInfo.java +++ b/source/net/sourceforge/filebot/media/ReleaseInfo.java @@ -33,10 +33,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; -import net.sourceforge.filebot.web.AnidbClient.AnidbSearchResult; +import net.sourceforge.filebot.web.AnidbSearchResult; import net.sourceforge.filebot.web.CachedResource; import net.sourceforge.filebot.web.Movie; -import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult; +import net.sourceforge.filebot.web.TheTVDBSearchResult; import net.sourceforge.tuned.ByteBufferInputStream; @@ -357,7 +357,7 @@ public class ReleaseInfo { if (englishTitle.isEmpty() || englishTitle.equals(primaryTitle)) { anime.add(new AnidbSearchResult(aid, primaryTitle, null)); } else { - anime.add(new AnidbSearchResult(aid, primaryTitle, singletonMap("en", englishTitle))); + anime.add(new AnidbSearchResult(aid, primaryTitle, englishTitle)); } } diff --git a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java index 78934ad7..5a39b27f 100644 --- a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java +++ b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java @@ -92,7 +92,7 @@ public enum EpisodeMetrics implements SimilarityMetric { Episode episode = (Episode) object; // use airdate from episode - return episode.airdate(); + return episode.getAirdate(); } Date result = transformCache.get(object); @@ -454,7 +454,7 @@ public enum EpisodeMetrics implements SimilarityMetric { public long getTimeStamp(Object object) { if (object instanceof Episode) { try { - long ts = ((Episode) object).airdate().getTimeStamp(); + long ts = ((Episode) object).getAirdate().getTimeStamp(); // big penalty for episodes not yet aired if (ts > System.currentTimeMillis()) { diff --git a/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties b/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties index 9ecf64a7..c5cf1369 100644 --- a/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties +++ b/source/net/sourceforge/filebot/ui/rename/FormatDialog.properties @@ -4,7 +4,7 @@ episode.syntax: { } \u2026 expression, n \u2026 name, movie.syntax: { } \u2026 expression, n \u2026 name, y \u2026 year music.syntax: { } \u2026 expression, n \u2026 album artist, t \u2026 title, album \u2026 album, pi \u2026 track -episode.sample: {"@type":"net.sourceforge.filebot.web.Episode","seriesName":"Firefly","seriesStartDate":{"year":2002,"month":9,"day":20},"season":1,"episode":1,"title":"Serenity","absolute":1,"special":null,"airdate":{"year":2002,"month":12,"day":20}} +episode.sample: {"@type":"net.sourceforge.filebot.web.Episode","seriesName":"Firefly","seriesStartDate":{"year":2002,"month":9,"day":20},"season":1,"episode":1,"title":"Serenity","absolute":1,"special":null,"airdate":{"year":2002,"month":12,"day":20},"series":{"@type":"net.sourceforge.filebot.web.TheTVDBSearchResult","seriesId":78874,"name":"Firefly"}} movie.sample: {"@type":"net.sourceforge.filebot.web.MoviePart","partIndex":1,"partCount":2,"year":2009,"imdbId":-1,"tmdbId":19995,"name":"Avatar"} music.sample: {"@type":"net.sourceforge.filebot.web.AudioTrack","artist":"Leona Lewis","title":"I See You","album":"Avatar","albumArtist":"James Horner","trackTitle":null,"albumReleaseDate":{"year":2009,"month":12,"day":11},"mediumIndex":1,"mediumCount":1,"trackIndex":14,"trackCount":14} diff --git a/source/net/sourceforge/filebot/web/AnidbClient.java b/source/net/sourceforge/filebot/web/AnidbClient.java index de8bef83..bce7c2b9 100644 --- a/source/net/sourceforge/filebot/web/AnidbClient.java +++ b/source/net/sourceforge/filebot/web/AnidbClient.java @@ -133,9 +133,9 @@ public class AnidbClient extends AbstractEpisodeListProvider { } if (type == 1) { - episodes.add(new Episode(animeTitle, seriesStartDate, null, number, title, number, null, airdate)); // normal episode, no seasons for anime + episodes.add(new Episode(animeTitle, seriesStartDate, null, number, title, number, null, airdate, searchResult)); // normal episode, no seasons for anime } else { - episodes.add(new Episode(animeTitle, seriesStartDate, null, null, title, null, number, airdate)); // special episode + episodes.add(new Episode(animeTitle, seriesStartDate, null, null, title, null, number, airdate, searchResult)); // special episode } } } @@ -224,74 +224,11 @@ public class AnidbClient extends AbstractEpisodeListProvider { localizedTitles.putAll(officialTitleMap.get(entry.getKey())); // primarily use official title if available } - anime.add(new AnidbSearchResult(entry.getKey(), entry.getValue(), localizedTitles)); + anime.add(new AnidbSearchResult(entry.getKey(), entry.getValue(), localizedTitles.get("en"))); } // populate cache return cache.putSearchResult(null, Locale.ROOT, anime); } - - public static class AnidbSearchResult extends SearchResult { - - protected int aid; - protected String primaryTitle; // one per anime - protected Map officialTitle; // one per language - - - protected AnidbSearchResult() { - // used by serializer - } - - - public AnidbSearchResult(int aid, String primaryTitle, Map officialTitle) { - this.aid = aid; - this.primaryTitle = primaryTitle; - this.officialTitle = officialTitle; - } - - - public int getAnimeId() { - return aid; - } - - - @Override - public String getName() { - return primaryTitle; - } - - - public String getPrimaryTitle() { - return primaryTitle; - } - - - public String getEnglishTitle() { - return officialTitle != null ? officialTitle.get("en") : null; - } - - - public String getOfficialTitle(String key) { - return officialTitle != null ? officialTitle.get(key) : null; - } - - - @Override - public int hashCode() { - return aid; - } - - - @Override - public boolean equals(Object object) { - if (object instanceof AnidbSearchResult) { - AnidbSearchResult other = (AnidbSearchResult) object; - return this.aid == other.aid; - } - - return false; - } - } - } diff --git a/source/net/sourceforge/filebot/web/AnidbSearchResult.java b/source/net/sourceforge/filebot/web/AnidbSearchResult.java new file mode 100644 index 00000000..cf021f3a --- /dev/null +++ b/source/net/sourceforge/filebot/web/AnidbSearchResult.java @@ -0,0 +1,65 @@ + +package net.sourceforge.filebot.web; + + +public class AnidbSearchResult extends SearchResult { + + protected int aid; + protected String primaryTitle; // one per anime + protected String englishTitle; // one per language + + + protected AnidbSearchResult() { + // used by serializer + } + + + public AnidbSearchResult(int aid, String primaryTitle, String englishTitle) { + this.aid = aid; + this.primaryTitle = primaryTitle; + this.englishTitle = englishTitle; + } + + + public int getId() { + return aid; + } + + + public int getAnimeId() { + return aid; + } + + + @Override + public String getName() { + return primaryTitle; + } + + + public String getPrimaryTitle() { + return primaryTitle; + } + + + public String getEnglishTitle() { + return englishTitle; + } + + + @Override + public int hashCode() { + return aid; + } + + + @Override + public boolean equals(Object object) { + if (object instanceof AnidbSearchResult) { + AnidbSearchResult other = (AnidbSearchResult) object; + return this.aid == other.aid; + } + + return false; + } +} \ No newline at end of file diff --git a/source/net/sourceforge/filebot/web/Episode.java b/source/net/sourceforge/filebot/web/Episode.java index 63ffaab4..b1d45253 100644 --- a/source/net/sourceforge/filebot/web/Episode.java +++ b/source/net/sourceforge/filebot/web/Episode.java @@ -24,6 +24,9 @@ public class Episode implements Serializable { // episode airdate private Date airdate; + // original series descriptor + private SearchResult series; + protected Episode() { // used by serializer @@ -31,16 +34,16 @@ 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); + this(obj.seriesName, obj.seriesStartDate, obj.season, obj.episode, obj.title, obj.absolute, obj.special, obj.airdate, obj.series); } - 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, SearchResult series) { + this(seriesName, seriesStartDate, season, episode, title, null, null, null, series); } - 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, SearchResult series) { this.seriesName = seriesName; this.seriesStartDate = seriesStartDate; this.season = season; @@ -49,6 +52,7 @@ public class Episode implements Serializable { this.absolute = absolute; this.special = special; this.airdate = airdate; + this.series = series; } @@ -87,11 +91,16 @@ public class Episode implements Serializable { } - public Date airdate() { + public Date getAirdate() { return airdate; } + public SearchResult getSeries() { + return series; + } + + @Override public boolean equals(Object obj) { if (obj instanceof Episode) { diff --git a/source/net/sourceforge/filebot/web/EpisodeFormat.java b/source/net/sourceforge/filebot/web/EpisodeFormat.java index dfae85c8..c9da9d50 100644 --- a/source/net/sourceforge/filebot/web/EpisodeFormat.java +++ b/source/net/sourceforge/filebot/web/EpisodeFormat.java @@ -63,8 +63,8 @@ public class EpisodeFormat extends Format { sb.append(" - ").append(episode.getTitle()); - if (includeAirdate && episode.airdate() != null) { - sb.append(" [").append(episode.airdate().format("yyyy-MM-dd")).append("]"); + if (includeAirdate && episode.getAirdate() != null) { + sb.append(" [").append(episode.getAirdate().format("yyyy-MM-dd")).append("]"); } return sb; @@ -195,7 +195,7 @@ public class EpisodeFormat extends Format { // did parse input pos.setIndex(source.length()); - return new Episode(name, null, season, episode, title, season == null ? episode : null, special, airdate); + return new Episode(name, null, season, episode, title, season == null ? episode : null, special, airdate, null); } // failed to parse input diff --git a/source/net/sourceforge/filebot/web/SerienjunkiesClient.java b/source/net/sourceforge/filebot/web/SerienjunkiesClient.java index 02e54873..d0eb6c53 100644 --- a/source/net/sourceforge/filebot/web/SerienjunkiesClient.java +++ b/source/net/sourceforge/filebot/web/SerienjunkiesClient.java @@ -143,7 +143,7 @@ public class SerienjunkiesClient extends AbstractEpisodeListProvider { title = ""; } - episodes.add(new Episode(seriesName, series.getStartDate(), season, episode, title, i + 1, null, airdate)); + episodes.add(new Episode(seriesName, series.getStartDate(), season, episode, title, i + 1, null, airdate, searchResult)); } // make sure episodes are in ordered correctly @@ -175,76 +175,4 @@ public class SerienjunkiesClient extends AbstractEpisodeListProvider { return URI.create(String.format("http://www.serienjunkies.de/%s/alle-serien-staffeln.html", ((SerienjunkiesSearchResult) searchResult).getLink())); } - - public static class SerienjunkiesSearchResult extends SearchResult { - - protected int sid; - protected String link; - protected String mainTitle; - protected String germanTitle; - protected Date startDate; - - - protected SerienjunkiesSearchResult() { - // used by serializer - } - - - public SerienjunkiesSearchResult(int sid, String link, String mainTitle, String germanTitle, Date startDate) { - this.sid = sid; - this.link = link; - this.mainTitle = mainTitle; - this.germanTitle = germanTitle; - this.startDate = startDate; - } - - - @Override - public String getName() { - return germanTitle != null ? germanTitle : mainTitle; // prefer German title - } - - - public int getSeriesId() { - return sid; - } - - - public String getLink() { - return link; - } - - - public String getMainTitle() { - return mainTitle; - } - - - public String getGermanTitle() { - return germanTitle; - } - - - public Date getStartDate() { - return startDate; - } - - - @Override - public int hashCode() { - return sid; - } - - - @Override - public boolean equals(Object object) { - if (object instanceof SerienjunkiesSearchResult) { - SerienjunkiesSearchResult other = (SerienjunkiesSearchResult) object; - return this.sid == other.sid; - } - - return false; - } - } - } diff --git a/source/net/sourceforge/filebot/web/SerienjunkiesSearchResult.java b/source/net/sourceforge/filebot/web/SerienjunkiesSearchResult.java new file mode 100644 index 00000000..cc5a4904 --- /dev/null +++ b/source/net/sourceforge/filebot/web/SerienjunkiesSearchResult.java @@ -0,0 +1,79 @@ + +package net.sourceforge.filebot.web; + + +public class SerienjunkiesSearchResult extends SearchResult { + + protected int sid; + protected String link; + protected String mainTitle; + protected String germanTitle; + protected Date startDate; + + + protected SerienjunkiesSearchResult() { + // used by serializer + } + + + public SerienjunkiesSearchResult(int sid, String link, String mainTitle, String germanTitle, Date startDate) { + this.sid = sid; + this.link = link; + this.mainTitle = mainTitle; + this.germanTitle = germanTitle; + this.startDate = startDate; + } + + + public int getId() { + return sid; + } + + + @Override + public String getName() { + return germanTitle != null ? germanTitle : mainTitle; // prefer German title + } + + + public int getSeriesId() { + return sid; + } + + + public String getLink() { + return link; + } + + + public String getMainTitle() { + return mainTitle; + } + + + public String getGermanTitle() { + return germanTitle; + } + + + public Date getStartDate() { + return startDate; + } + + + @Override + public int hashCode() { + return sid; + } + + + @Override + public boolean equals(Object object) { + if (object instanceof SerienjunkiesSearchResult) { + SerienjunkiesSearchResult other = (SerienjunkiesSearchResult) object; + return this.sid == other.sid; + } + + return false; + } +} \ No newline at end of file diff --git a/source/net/sourceforge/filebot/web/TVRageClient.java b/source/net/sourceforge/filebot/web/TVRageClient.java index 3619784e..9faec6c4 100644 --- a/source/net/sourceforge/filebot/web/TVRageClient.java +++ b/source/net/sourceforge/filebot/web/TVRageClient.java @@ -92,7 +92,7 @@ public class TVRageClient extends AbstractEpisodeListProvider { // handle as special episode seasonNumber = getIntegerContent("season", node); int specialNumber = filterBySeason(specials, seasonNumber).size() + 1; - specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, title, null, specialNumber, airdate)); + specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, title, null, specialNumber, airdate, searchResult)); } else { // handle as normal episode if (sortOrder == SortOrder.Absolute) { @@ -100,7 +100,7 @@ public class TVRageClient extends AbstractEpisodeListProvider { seasonNumber = null; } - episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, title, null, null, airdate)); + episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, title, null, null, airdate, searchResult)); } } @@ -116,50 +116,4 @@ public class TVRageClient extends AbstractEpisodeListProvider { return URI.create(((TVRageSearchResult) searchResult).getLink() + "/episode_list/all"); } - - public static class TVRageSearchResult extends SearchResult { - - protected int showId; - protected String link; - - - protected TVRageSearchResult() { - // used by serializer - } - - - public TVRageSearchResult(String name, int showId, String link) { - super(name); - this.showId = showId; - this.link = link; - } - - - public int getSeriesId() { - return showId; - } - - - public String getLink() { - return link; - } - - - @Override - public int hashCode() { - return showId; - } - - - @Override - public boolean equals(Object object) { - if (object instanceof TVRageSearchResult) { - TVRageSearchResult other = (TVRageSearchResult) object; - return this.showId == other.showId; - } - - return false; - } - } - } diff --git a/source/net/sourceforge/filebot/web/TVRageSearchResult.java b/source/net/sourceforge/filebot/web/TVRageSearchResult.java new file mode 100644 index 00000000..a0975acb --- /dev/null +++ b/source/net/sourceforge/filebot/web/TVRageSearchResult.java @@ -0,0 +1,53 @@ + +package net.sourceforge.filebot.web; + + +public class TVRageSearchResult extends SearchResult { + + protected int showId; + protected String link; + + + protected TVRageSearchResult() { + // used by serializer + } + + + public TVRageSearchResult(String name, int showId, String link) { + super(name); + this.showId = showId; + this.link = link; + } + + + public int getId() { + return showId; + } + + + public int getSeriesId() { + return showId; + } + + + public String getLink() { + return link; + } + + + @Override + public int hashCode() { + return showId; + } + + + @Override + public boolean equals(Object object) { + if (object instanceof TVRageSearchResult) { + TVRageSearchResult other = (TVRageSearchResult) object; + return this.showId == other.showId; + } + + return false; + } +} \ No newline at end of file diff --git a/source/net/sourceforge/filebot/web/TheTVDBClient.java b/source/net/sourceforge/filebot/web/TheTVDBClient.java index 39473907..a3aa545c 100644 --- a/source/net/sourceforge/filebot/web/TheTVDBClient.java +++ b/source/net/sourceforge/filebot/web/TheTVDBClient.java @@ -159,7 +159,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { // use given episode number as special number or count specials by ourselves Integer specialNumber = (episodeNumber != null) ? episodeNumber : filterBySeason(specials, seasonNumber).size() + 1; - specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, episodeName, null, specialNumber, airdate)); + specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, episodeName, null, specialNumber, airdate, searchResult)); } else { // handle as normal episode if (sortOrder == SortOrder.Absolute) { @@ -176,7 +176,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } } - episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, episodeName, absoluteNumber, null, airdate)); + episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, episodeName, absoluteNumber, null, airdate, searchResult)); } } @@ -339,45 +339,6 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } - public static class TheTVDBSearchResult extends SearchResult { - - protected int seriesId; - - - protected TheTVDBSearchResult() { - // used by serializer - } - - - public TheTVDBSearchResult(String seriesName, int seriesId) { - super(seriesName); - this.seriesId = seriesId; - } - - - public int getSeriesId() { - return seriesId; - } - - - @Override - public int hashCode() { - return seriesId; - } - - - @Override - public boolean equals(Object object) { - if (object instanceof TheTVDBSearchResult) { - TheTVDBSearchResult other = (TheTVDBSearchResult) object; - return this.seriesId == other.seriesId; - } - - return false; - } - } - - protected static enum MirrorType { XML(1), BANNER(2), ZIP(4), SEARCH(1); @@ -457,26 +418,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { public static class SeriesInfo implements Serializable { public static enum SeriesProperty { - id, - Actors, - Airs_DayOfWeek, - Airs_Time, - ContentRating, - FirstAired, - Genre, - IMDB_ID, - Language, - Network, - Overview, - Rating, - RatingCount, - Runtime, - SeriesName, - Status, - BannerMirror, - banner, - fanart, - poster + id, Actors, Airs_DayOfWeek, Airs_Time, ContentRating, FirstAired, Genre, IMDB_ID, Language, Network, Overview, Rating, RatingCount, Runtime, SeriesName, Status, BannerMirror, banner, fanart, poster } protected Map fields; @@ -746,19 +688,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { public static class BannerDescriptor implements Serializable { public static enum BannerProperty { - id, - BannerMirror, - BannerPath, - BannerType, - BannerType2, - Season, - Colors, - Language, - Rating, - RatingCount, - SeriesName, - ThumbnailPath, - VignettePath + id, BannerMirror, BannerPath, BannerType, BannerType2, Season, Colors, Language, Rating, RatingCount, SeriesName, ThumbnailPath, VignettePath } protected Map fields; diff --git a/source/net/sourceforge/filebot/web/TheTVDBSearchResult.java b/source/net/sourceforge/filebot/web/TheTVDBSearchResult.java new file mode 100644 index 00000000..e31febed --- /dev/null +++ b/source/net/sourceforge/filebot/web/TheTVDBSearchResult.java @@ -0,0 +1,46 @@ + +package net.sourceforge.filebot.web; + + +public class TheTVDBSearchResult extends SearchResult { + + protected int seriesId; + + + protected TheTVDBSearchResult() { + // used by serializer + } + + + public TheTVDBSearchResult(String seriesName, int seriesId) { + super(seriesName); + this.seriesId = seriesId; + } + + + public int getId() { + return seriesId; + } + + + public int getSeriesId() { + return seriesId; + } + + + @Override + public int hashCode() { + return seriesId; + } + + + @Override + public boolean equals(Object object) { + if (object instanceof TheTVDBSearchResult) { + TheTVDBSearchResult other = (TheTVDBSearchResult) object; + return this.seriesId == other.seriesId; + } + + return false; + } +} \ No newline at end of file diff --git a/test/net/sourceforge/filebot/similarity/EpisodeMetricsTest.java b/test/net/sourceforge/filebot/similarity/EpisodeMetricsTest.java index 8acf6303..404ee2fd 100644 --- a/test/net/sourceforge/filebot/similarity/EpisodeMetricsTest.java +++ b/test/net/sourceforge/filebot/similarity/EpisodeMetricsTest.java @@ -9,21 +9,17 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import org.junit.Test; - -import net.sourceforge.filebot.similarity.EpisodeMetrics; -import net.sourceforge.filebot.similarity.Match; -import net.sourceforge.filebot.similarity.Matcher; -import net.sourceforge.filebot.similarity.SimilarityMetric; import net.sourceforge.filebot.web.Date; import net.sourceforge.filebot.web.Episode; +import org.junit.Test; + public class EpisodeMetricsTest { @Test public void substringMetrics() { - Episode eY1T1 = new Episode("Doctor Who", new Date(2005, 0, 0), 1, 1, "Rose"); + Episode eY1T1 = new Episode("Doctor Who", new Date(2005, 0, 0), 1, 1, "Rose", null); // Episode eY2T2 = new Episode("Doctor Who", new Date(1963, 0, 0), 1, 1, "An Unearthly Child"); File fY1T1 = new File("Doctor Who (2005)/Doctor Who - 1x01 - Rose"); File fY2T2 = new File("Doctor Who (1963)/Doctor Who - 1x01 - An Unearthly Child"); @@ -32,25 +28,25 @@ public class EpisodeMetricsTest { assertEquals(2.0 / 3, SubstringFields.getSimilarity(eY1T1, fY2T2), 0.01); } - + @Test public void nameIgnoreEmbeddedChecksum() { assertEquals(1, Name.getSimilarity("test", "test [EF62DF13]"), 0); } - + @Test public void numericIgnoreEmbeddedChecksum() { assertEquals(1, Numeric.getSimilarity("S01E02", "Season 1, Episode 2 [00A01E02]"), 0); } - + @Test public void normalizeFile() { assertEquals("abc", EpisodeMetrics.normalizeObject(new File("/folder/abc[EF62DF13].txt"))); } - + @Test public void matcherLevel2() throws Exception { List files = new ArrayList(); @@ -58,8 +54,8 @@ public class EpisodeMetricsTest { files.add(new File("Greek/Greek - S01E19 - No Campus for Old Rules")); files.add(new File("Veronica Mars - Season 1/Veronica Mars [1x19] Hot Dogs")); - episodes.add(new Episode("Veronica Mars", null, 1, 19, "Hot Dogs")); - episodes.add(new Episode("Greek", null, 1, 19, "No Campus for Old Rules")); + episodes.add(new Episode("Veronica Mars", null, 1, 19, "Hot Dogs", null)); + episodes.add(new Episode("Greek", null, 1, 19, "No Campus for Old Rules", null)); SimilarityMetric[] metrics = new SimilarityMetric[] { EpisodeIdentifier, SubstringFields }; List> m = new Matcher(files, episodes, true, metrics).match(); diff --git a/test/net/sourceforge/filebot/web/AnidbClientTest.java b/test/net/sourceforge/filebot/web/AnidbClientTest.java index 20addf9f..05e142ee 100644 --- a/test/net/sourceforge/filebot/web/AnidbClientTest.java +++ b/test/net/sourceforge/filebot/web/AnidbClientTest.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Locale; import net.sf.ehcache.CacheManager; -import net.sourceforge.filebot.web.AnidbClient.AnidbSearchResult; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -86,7 +85,7 @@ public class AnidbClientTest { assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getAbsolute().toString()); assertEquals(null, first.getSeason()); - assertEquals("2004-04-07", first.airdate().toString()); + assertEquals("2004-04-07", first.getAirdate().toString()); } @@ -104,7 +103,7 @@ public class AnidbClientTest { assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getAbsolute().toString()); assertEquals(null, first.getSeason()); - assertEquals("2002-04-09", first.airdate().toString()); + assertEquals("2002-04-09", first.getAirdate().toString()); } @@ -125,7 +124,7 @@ public class AnidbClientTest { assertEquals("74", last.getEpisode().toString()); assertEquals("74", last.getAbsolute().toString()); assertEquals(null, last.getSeason()); - assertEquals("2005-09-28", last.airdate().toString()); + assertEquals("2005-09-28", last.getAirdate().toString()); } diff --git a/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java b/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java index f6b3c4d8..a7b64227 100644 --- a/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java +++ b/test/net/sourceforge/filebot/web/SerienjunkiesClientTest.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Locale; import net.sf.ehcache.CacheManager; -import net.sourceforge.filebot.web.SerienjunkiesClient.SerienjunkiesSearchResult; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -46,7 +45,7 @@ public class SerienjunkiesClientTest { assertEquals("1", eps.getEpisode().toString()); assertEquals("1", eps.getSeason().toString()); assertEquals("1", eps.getAbsolute().toString()); - assertEquals("2005-03-27", eps.airdate().toString()); + assertEquals("2005-03-27", eps.getAirdate().toString()); } diff --git a/test/net/sourceforge/filebot/web/TVRageClientTest.java b/test/net/sourceforge/filebot/web/TVRageClientTest.java index 9ce636b9..6cf079a0 100644 --- a/test/net/sourceforge/filebot/web/TVRageClientTest.java +++ b/test/net/sourceforge/filebot/web/TVRageClientTest.java @@ -8,7 +8,6 @@ import java.util.List; import org.junit.Test; -import net.sourceforge.filebot.web.TVRageClient.TVRageSearchResult; public class TVRageClientTest { @@ -48,7 +47,7 @@ public class TVRageClientTest { assertEquals("22", chosen.getEpisode().toString()); assertEquals("7", chosen.getSeason().toString()); assertEquals(null, chosen.getAbsolute()); - assertEquals("2003-05-20", chosen.airdate().toString()); + assertEquals("2003-05-20", chosen.getAirdate().toString()); } @@ -65,7 +64,7 @@ public class TVRageClientTest { assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); assertEquals(null, first.getAbsolute()); - assertEquals("1997-03-10", first.airdate().toString()); + assertEquals("1997-03-10", first.getAirdate().toString()); } diff --git a/test/net/sourceforge/filebot/web/TheTVDBClientTest.java b/test/net/sourceforge/filebot/web/TheTVDBClientTest.java index d68a7c2a..701947da 100644 --- a/test/net/sourceforge/filebot/web/TheTVDBClientTest.java +++ b/test/net/sourceforge/filebot/web/TheTVDBClientTest.java @@ -14,7 +14,6 @@ import net.sf.ehcache.CacheManager; import net.sourceforge.filebot.web.TheTVDBClient.BannerDescriptor; import net.sourceforge.filebot.web.TheTVDBClient.MirrorType; import net.sourceforge.filebot.web.TheTVDBClient.SeriesInfo; -import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -67,7 +66,7 @@ public class TheTVDBClientTest { assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); assertEquals("1", first.getAbsolute().toString()); - assertEquals("1997-03-10", first.airdate().toString()); + assertEquals("1997-03-10", first.getAirdate().toString()); // check special episode Episode last = list.get(list.size() - 1); @@ -77,7 +76,7 @@ public class TheTVDBClientTest { assertEquals(null, last.getEpisode()); assertEquals(null, last.getAbsolute()); assertEquals("1", last.getSpecial().toString()); - assertEquals(null, last.airdate()); + assertEquals(null, last.getAirdate()); } @@ -93,7 +92,7 @@ public class TheTVDBClientTest { assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); assertEquals(null, first.getAbsolute()); // should be "1" but data has not yet been entered - assertEquals("2004-03-12", first.airdate().toString()); + assertEquals("2004-03-12", first.getAirdate().toString()); } @@ -108,7 +107,7 @@ public class TheTVDBClientTest { assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); assertEquals("1", first.getAbsolute().toString()); - assertEquals("2002-12-20", first.airdate().toString()); + assertEquals("2002-12-20", first.getAirdate().toString()); }