diff --git a/source/net/sourceforge/filebot/format/MediaBindingBean.java b/source/net/sourceforge/filebot/format/MediaBindingBean.java index 6b701908..af510894 100644 --- a/source/net/sourceforge/filebot/format/MediaBindingBean.java +++ b/source/net/sourceforge/filebot/format/MediaBindingBean.java @@ -65,7 +65,7 @@ public class MediaBindingBean { @Define("y") public Integer getYear() { if (infoObject instanceof Episode) - return getEpisode().airdate().getYear(); + return getEpisode().getSeriesStartDate().getYear(); if (infoObject instanceof Movie) return getMovie().getYear(); @@ -97,6 +97,12 @@ public class MediaBindingBean { } + @Define("startdate") + public Date startdate() { + return getEpisode().getSeriesStartDate(); + } + + @Define("absolute") public Integer getAbsoluteEpisodeNumber() { return getEpisode().getAbsolute(); diff --git a/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties b/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties index a62719a8..1a2867b7 100644 --- a/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties +++ b/source/net/sourceforge/filebot/ui/rename/BindingDialog.properties @@ -2,4 +2,4 @@ parameter.exclude: ^StreamKind|Count$ # preview expressions (keys are tagged so they can be sorted alphabetically) -expressions: n,s,e,t,y,airdate,absolute,special,imdb,episode,movie,vc,ac,cf,vf,af,resolution,source,group,crc32,fn,ext,file,pi,pn,media.title,media.durationString,media.overallBitRateString,video.codecID,video.frameRate,video.displayAspectRatioString,video.height,video.scanType,audio.format,audio.bitRateString,audio.language,text.codecInfo,text.language +expressions: n,y,s,e,t,airdate,startdate,absolute,special,imdb,episode,movie,vc,ac,cf,vf,af,resolution,source,group,crc32,fn,ext,file,pi,pn,media.title,media.durationString,media.overallBitRateString,video.codecID,video.frameRate,video.displayAspectRatioString,video.height,video.scanType,audio.format,audio.bitRateString,audio.language,text.codecInfo,text.language diff --git a/source/net/sourceforge/filebot/web/AnidbClient.java b/source/net/sourceforge/filebot/web/AnidbClient.java index 88a1e254..6273e328 100644 --- a/source/net/sourceforge/filebot/web/AnidbClient.java +++ b/source/net/sourceforge/filebot/web/AnidbClient.java @@ -95,7 +95,6 @@ public class AnidbClient extends AbstractEpisodeListProvider { if (name != null) { // normalize name = name.toLowerCase(); - float similarity = metric.getSimilarity(name, query); if (similarity > 0.5 || name.contains(query)) { @@ -149,7 +148,8 @@ public class AnidbClient extends AbstractEpisodeListProvider { // get anime page as xml Document dom = getDocument(url); - // select main title + // select main title and anime start date + Date seriesStartDate = Date.parse(selectString("//startdate", dom), "yyyy-MM-dd"); String animeTitle = selectString("//titles/title[@type='official' and @lang='" + language.getLanguage() + "']", dom); if (animeTitle.isEmpty()) { animeTitle = selectString("//titles/title[@type='main']", dom); @@ -162,15 +162,14 @@ public class AnidbClient extends AbstractEpisodeListProvider { // ignore special episodes if (number != null) { + Date airdate = Date.parse(getTextContent("airdate", node), "yyyy-MM-dd"); String title = selectString(".//title[@lang='" + language.getLanguage() + "']", node); if (title.isEmpty()) { // English language fall-back title = selectString(".//title[@lang='en']", node); } - String airdate = getTextContent("airdate", node); - // no seasons for anime - episodes.add(new Episode(animeTitle, null, number, title, number, null, Date.parse(airdate, "yyyy-MM-dd"))); + episodes.add(new Episode(animeTitle, seriesStartDate, null, number, title, number, null, airdate)); } } diff --git a/source/net/sourceforge/filebot/web/Date.java b/source/net/sourceforge/filebot/web/Date.java index f65072f6..37b991b1 100644 --- a/source/net/sourceforge/filebot/web/Date.java +++ b/source/net/sourceforge/filebot/web/Date.java @@ -56,7 +56,7 @@ public class Date implements Serializable { return year == other.year && month == other.month && day == other.day; } - return false; + return super.equals(obj); } diff --git a/source/net/sourceforge/filebot/web/Episode.java b/source/net/sourceforge/filebot/web/Episode.java index bad9c299..573c549f 100644 --- a/source/net/sourceforge/filebot/web/Episode.java +++ b/source/net/sourceforge/filebot/web/Episode.java @@ -9,6 +9,8 @@ import java.util.Arrays; public class Episode implements Serializable { private String seriesName; + private Date seriesStartDate; + private Integer season; private Integer episode; private String title; @@ -28,13 +30,14 @@ public class Episode implements Serializable { } - public Episode(String seriesName, Integer season, Integer episode, String title) { - this(seriesName, season, episode, title, null, null, null); + 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, 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.seriesStartDate = seriesStartDate; this.season = season; this.episode = episode; this.title = title; @@ -49,6 +52,11 @@ public class Episode implements Serializable { } + public Date getSeriesStartDate() { + return seriesStartDate; + } + + public Integer getEpisode() { return episode; } diff --git a/source/net/sourceforge/filebot/web/EpisodeFormat.java b/source/net/sourceforge/filebot/web/EpisodeFormat.java index e83d6bae..122c2ab4 100644 --- a/source/net/sourceforge/filebot/web/EpisodeFormat.java +++ b/source/net/sourceforge/filebot/web/EpisodeFormat.java @@ -94,7 +94,7 @@ public class EpisodeFormat extends Format { // did parse input pos.setIndex(source.length()); - return new Episode(name, season, episode, title, season == null ? episode : null, special, airdate); + return new Episode(name, null, season, episode, title, season == null ? episode : null, special, airdate); } // failed to parse input diff --git a/source/net/sourceforge/filebot/web/IMDbClient.java b/source/net/sourceforge/filebot/web/IMDbClient.java index 7b9bf53f..b167a91a 100644 --- a/source/net/sourceforge/filebot/web/IMDbClient.java +++ b/source/net/sourceforge/filebot/web/IMDbClient.java @@ -46,9 +46,7 @@ public class IMDbClient extends AbstractEpisodeListProvider { @Override public List search(String query, Locale locale) throws IOException, SAXException { - URL searchUrl = new URL("http", host, "/find?s=tt&q=" + URLEncoder.encode(query, "UTF-8")); - Document dom = getHtmlDocument(openConnection(searchUrl)); List nodes = selectNodes("//TABLE//A[following-sibling::SMALL[contains(.,'series')]]", dom); @@ -85,6 +83,7 @@ public class IMDbClient extends AbstractEpisodeListProvider { Document dom = getHtmlDocument(openConnection(getEpisodeListLink(searchResult).toURL())); String seriesName = normalizeName(selectString("//H1/A", dom)); + Date year = new Date(((Movie) searchResult).getYear(), 0, 0); List nodes = selectNodes("//TABLE//H3/A[preceding-sibling::text()]", dom); @@ -98,9 +97,9 @@ public class IMDbClient extends AbstractEpisodeListProvider { Integer episode = numberScanner.nextInt(); // e.g. 20 May 2003 - String airdate = selectString("./following::STRONG", node); + Date airdate = Date.parse(selectString("./following::STRONG", node), "dd MMMMM yyyyy"); - episodes.add(new Episode(seriesName, season, episode, title, null, null, Date.parse(airdate, "dd MMMMM yyyyy"))); + episodes.add(new Episode(seriesName, year, season, episode, title, null, null, airdate)); } return episodes; diff --git a/source/net/sourceforge/filebot/web/TVRageClient.java b/source/net/sourceforge/filebot/web/TVRageClient.java index 67da6301..b907547f 100644 --- a/source/net/sourceforge/filebot/web/TVRageClient.java +++ b/source/net/sourceforge/filebot/web/TVRageClient.java @@ -72,6 +72,7 @@ public class TVRageClient extends AbstractEpisodeListProvider { Document dom = getDocument(episodeListUrl); String seriesName = selectString("Show/name", dom); + Date seriesStartDate = Date.parse(selectString("//started", dom), "MMM/dd/yyyy"); List episodes = new ArrayList(25); List specials = new ArrayList(5); @@ -89,10 +90,10 @@ 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, seasonNumber, null, title, null, specialNumber, airdate)); + specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, title, null, specialNumber, airdate)); } else { // handle as normal episode - episodes.add(new Episode(seriesName, seasonNumber, episodeNumber, title, null, null, airdate)); + episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, title, null, null, airdate)); } } diff --git a/source/net/sourceforge/filebot/web/TheTVDBClient.java b/source/net/sourceforge/filebot/web/TheTVDBClient.java index 561eda05..2f8abbfc 100644 --- a/source/net/sourceforge/filebot/web/TheTVDBClient.java +++ b/source/net/sourceforge/filebot/web/TheTVDBClient.java @@ -117,6 +117,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { // we could get the series name from the search result, but the language may not match the given parameter String seriesName = selectString("Data/Series/SeriesName", seriesRecord); + Date seriesStartDate = Date.parse(selectString("Data/Series/FirstAired", seriesRecord), "yyyy-MM-dd"); List nodes = selectNodes("Data/Episode", seriesRecord); @@ -150,10 +151,10 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } Integer specialNumber = filterBySeason(specials, seasonNumber).size() + 1; - specials.add(new Episode(seriesName, seasonNumber, null, episodeName, null, specialNumber, airdate)); + specials.add(new Episode(seriesName, seriesStartDate, seasonNumber, null, episodeName, null, specialNumber, airdate)); } else { // handle as normal episode - episodes.add(new Episode(seriesName, seasonNumber, episodeNumber, episodeName, absoluteNumber, null, airdate)); + episodes.add(new Episode(seriesName, seriesStartDate, seasonNumber, episodeNumber, episodeName, absoluteNumber, null, airdate)); } if (episodeNumber == 1) { diff --git a/source/net/sourceforge/filebot/web/WebRequest.java b/source/net/sourceforge/filebot/web/WebRequest.java index 0990bf12..94334561 100644 --- a/source/net/sourceforge/filebot/web/WebRequest.java +++ b/source/net/sourceforge/filebot/web/WebRequest.java @@ -106,6 +106,11 @@ public final class WebRequest { } + public static ByteBuffer fetch(URL resource) throws IOException { + return fetch(resource, 0, null); + } + + public static ByteBuffer fetchIfModified(URL resource, long ifModifiedSince) throws IOException { return fetch(resource, ifModifiedSince, null); } diff --git a/test/net/sourceforge/filebot/web/AnidbClientTest.java b/test/net/sourceforge/filebot/web/AnidbClientTest.java index 89557bf2..5c48196b 100644 --- a/test/net/sourceforge/filebot/web/AnidbClientTest.java +++ b/test/net/sourceforge/filebot/web/AnidbClientTest.java @@ -41,7 +41,7 @@ public class AnidbClientTest { } - private AnidbClient anidb = new AnidbClient("filebot", 1); + private AnidbClient anidb = new AnidbClient("filebot", 2); @Test @@ -83,6 +83,7 @@ public class AnidbClientTest { Episode first = list.get(0); assertEquals("Monster", first.getSeriesName()); + assertEquals("2004-04-07", first.getSeriesStartDate().toString()); assertEquals("Herr Dr. Tenma", first.getTitle()); assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getAbsolute().toString()); @@ -100,6 +101,7 @@ public class AnidbClientTest { Episode first = list.get(0); assertEquals("The Twelve Kingdoms", first.getSeriesName()); + assertEquals("2002-04-09", first.getSeriesStartDate().toString()); assertEquals("Shadow of the Moon, The Sea of Shadow - Chapter 1", first.getTitle()); assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getAbsolute().toString()); @@ -120,6 +122,7 @@ public class AnidbClientTest { Episode last = list.get(73); assertEquals("モンスター", last.getSeriesName()); + assertEquals("2004-04-07", last.getSeriesStartDate().toString()); assertEquals("本当の怪物", last.getTitle()); assertEquals("74", last.getEpisode().toString()); assertEquals("74", last.getAbsolute().toString()); diff --git a/test/net/sourceforge/filebot/web/IMDbClientTest.java b/test/net/sourceforge/filebot/web/IMDbClientTest.java index 2ddfa80c..84871c28 100644 --- a/test/net/sourceforge/filebot/web/IMDbClientTest.java +++ b/test/net/sourceforge/filebot/web/IMDbClientTest.java @@ -71,6 +71,7 @@ public class IMDbClientTest { Episode first = list.get(0); assertEquals("Buffy the Vampire Slayer", first.getSeriesName()); + assertEquals("1997-00-00", first.getSeriesStartDate().toString()); assertEquals("Unaired Pilot", first.getTitle()); assertEquals("0", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); @@ -79,6 +80,7 @@ public class IMDbClientTest { Episode last = list.get(144); assertEquals("Buffy the Vampire Slayer", last.getSeriesName()); + assertEquals("1997-00-00", first.getSeriesStartDate().toString()); assertEquals("Chosen", last.getTitle()); assertEquals("22", last.getEpisode().toString()); assertEquals("7", last.getSeason().toString()); @@ -95,6 +97,7 @@ public class IMDbClientTest { Episode first = list.get(0); assertEquals("Mushi-Shi", first.getSeriesName()); + assertEquals("2005-00-00", first.getSeriesStartDate().toString()); assertEquals("Midori no za", first.getTitle()); assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); diff --git a/test/net/sourceforge/filebot/web/TVRageClientTest.java b/test/net/sourceforge/filebot/web/TVRageClientTest.java index fdbe0bbc..4072cbb4 100644 --- a/test/net/sourceforge/filebot/web/TVRageClientTest.java +++ b/test/net/sourceforge/filebot/web/TVRageClientTest.java @@ -43,6 +43,7 @@ public class TVRageClientTest { Episode chosen = list.get(21); assertEquals("Buffy the Vampire Slayer", chosen.getSeriesName()); + assertEquals("2002-04-09", chosen.getSeriesStartDate().toString()); assertEquals("Chosen", chosen.getTitle()); assertEquals("22", chosen.getEpisode().toString()); assertEquals("7", chosen.getSeason().toString()); diff --git a/test/net/sourceforge/filebot/web/TheTVDBClientTest.java b/test/net/sourceforge/filebot/web/TheTVDBClientTest.java index 4a9090eb..3a6856e6 100644 --- a/test/net/sourceforge/filebot/web/TheTVDBClientTest.java +++ b/test/net/sourceforge/filebot/web/TheTVDBClientTest.java @@ -38,19 +38,14 @@ public class TheTVDBClientTest { @Test public void searchGerman() throws Exception { - List results = thetvdb.search("buffy", Locale.GERMAN); + List results = thetvdb.search("Buffy the Vampire Slayer", Locale.GERMAN); - assertEquals(4, results.size()); + assertEquals(2, results.size()); TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0); - assertEquals("Buffy", first.getName()); + assertEquals("Buffy the Vampire Slayer", first.getName()); assertEquals(70327, first.getSeriesId()); - - TheTVDBSearchResult second = (TheTVDBSearchResult) results.get(1); - - assertEquals("Buffy the Vampire Slayer", second.getName()); - assertEquals(70327, second.getSeriesId()); } @@ -63,6 +58,7 @@ public class TheTVDBClientTest { // check ordinary episode Episode first = list.get(0); assertEquals("Buffy the Vampire Slayer", first.getSeriesName()); + assertEquals("1997-03-10", first.getSeriesStartDate().toString()); assertEquals("Welcome to the Hellmouth (1)", first.getTitle()); assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); @@ -90,6 +86,7 @@ public class TheTVDBClientTest { Episode first = list.get(0); assertEquals("Wonderfalls", first.getSeriesName()); + assertEquals("2004-03-12", first.getSeriesStartDate().toString()); assertEquals("Wax Lion", first.getTitle()); assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); @@ -106,6 +103,7 @@ public class TheTVDBClientTest { Episode first = list.get(0); assertEquals("Firefly", first.getSeriesName()); + assertEquals("2002-09-20", first.getSeriesStartDate().toString()); assertEquals("Serenity", first.getTitle()); assertEquals("1", first.getEpisode().toString()); assertEquals("1", first.getSeason().toString()); diff --git a/website/naming.html b/website/naming.html index ee86afcc..2868b2b3 100644 --- a/website/naming.html +++ b/website/naming.html @@ -119,6 +119,11 @@ series/movie name Dark Angel + + y + series/movie year + 2009 + s season number @@ -134,11 +139,6 @@ episode title Labyrinth - - y - episode/movie year - 2009 - airdate episode airdate