From 9496ce6f10bc34e7cb0343ab95c6d618018f2731 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 3 Dec 2018 20:00:27 +0700 Subject: [PATCH] Add {ci} collection index binding --- source/net/filebot/format/MediaBindingBean.java | 2 +- source/net/filebot/web/TMDbClient.java | 9 +++------ test/net/filebot/web/TMDbClientTest.java | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 9f576883..42a7e580 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -710,7 +710,7 @@ public class MediaBindingBean { @Define("ci") public Integer getCollectionIndex() throws Exception { if (infoObject instanceof Movie && getMovie().getTmdbId() > 0) - return TheMovieDB.getCollection(getMovie(), Locale.US).indexOf(getMovie()) + 1; + return TheMovieDB.getCollection(getMovie().getTmdbId(), Locale.US).indexOf(getMovie()) + 1; return null; } diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 31d48ac2..969154b7 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -285,17 +285,14 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider { return new MovieInfo(fields, alternativeTitles, genres, certifications, spokenLanguages, productionCountries, productionCompanies, cast, trailers); } - public List getCollection(Movie movie, Locale locale) throws Exception { - Object movieResponse = request("movie/" + movie.getTmdbId(), emptyMap(), locale); + public List getCollection(int id, Locale locale) throws Exception { + Object movieResponse = request("movie/" + id, emptyMap(), locale); Map collectionObject = getMap(movieResponse, "belongs_to_collection"); Integer collectionId = getInteger(collectionObject, "id"); Object collectionResponse = request("collection/" + collectionId, emptyMap(), locale); return streamJsonObjects(collectionResponse, "parts").filter(it -> null != getString(it, "release_date")).sorted(comparing(it -> getString(it, "release_date"))).map(it -> { - int id = getDouble(it, "id").intValue(); - int year = matchInteger(getString(it, "release_date")); // release date is often missing - String title = getString(it, "title"); - return new Movie(title, null, year, -1, id, locale); + return new Movie(getString(it, "title"), null, matchInteger(getString(it, "release_date")), -1, getInteger(it, "id"), locale); }).collect(toList()); } diff --git a/test/net/filebot/web/TMDbClientTest.java b/test/net/filebot/web/TMDbClientTest.java index f6c59e64..7cf748ca 100644 --- a/test/net/filebot/web/TMDbClientTest.java +++ b/test/net/filebot/web/TMDbClientTest.java @@ -116,7 +116,7 @@ public class TMDbClientTest { @Test public void getCollection() throws Exception { - List collection = TheMovieDB.getCollection(new Movie(24253), Locale.ENGLISH); // Serenity + List collection = TheMovieDB.getCollection(24253, Locale.ENGLISH); // Serenity assertEquals("[The Girl with the Dragon Tattoo (2009), The Girl Who Played with Fire (2009), The Girl Who Kicked the Hornet's Nest (2009)]", collection.toString()); }