From 647f25fa30b828b32d491dd70a3861f9242f1b88 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 20 Sep 2014 18:37:42 +0000 Subject: [PATCH] * support {info.ProductionCountries} --- source/net/filebot/web/OMDbClient.java | 2 +- source/net/filebot/web/TMDbClient.java | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/source/net/filebot/web/OMDbClient.java b/source/net/filebot/web/OMDbClient.java index a0147c8a..528bc35f 100644 --- a/source/net/filebot/web/OMDbClient.java +++ b/source/net/filebot/web/OMDbClient.java @@ -237,6 +237,6 @@ public class OMDbClient implements MovieIdentificationService { actors.add(new Person(writer, null, "Writer")); } - return new MovieInfo(fields, new ArrayList(0), genres, new ArrayList(0), actors, new ArrayList(0)); + return new MovieInfo(fields, new ArrayList(), genres, new ArrayList(), new ArrayList(), actors, new ArrayList()); } } diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 2383964b..05d3503f 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -156,7 +156,12 @@ public class TMDbClient implements MovieIdentificationService { public Movie getMovieDescriptor(Movie id, Locale locale) throws IOException { if (id.getTmdbId() > 0 || id.getImdbId() > 0) { MovieInfo info = getMovieInfo(id, locale, false); - return new Movie(info.getName(), info.getOriginalName() == null || info.getOriginalName().isEmpty() ? new String[0] : new String[] { info.getOriginalName() }, info.getReleased().getYear(), info.getImdbId(), info.getId(), locale); + String name = info.getName(); + String[] aliasNames = info.getOriginalName() == null || info.getOriginalName().isEmpty() ? new String[0] : new String[] { info.getOriginalName() }; + int year = info.getReleased().getYear(); + int tmdbid = info.getId(); + int imdbid = info.getImdbId() != null ? info.getImdbId() : -1; + return new Movie(name, aliasNames, year, imdbid, tmdbid, locale); } return null; } @@ -224,6 +229,15 @@ public class TMDbClient implements MovieIdentificationService { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal spoken_languages data: " + response); } + List productionCountries = new ArrayList(); + try { + for (JSONObject it : jsonList(response.get("production_countries"))) { + productionCountries.add((String) it.get("name")); + } + } catch (Exception e) { + Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal production_countries data: " + response); + } + List alternativeTitles = new ArrayList(); try { JSONObject titles = (JSONObject) response.get("alternative_titles"); @@ -293,7 +307,7 @@ public class TMDbClient implements MovieIdentificationService { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal trailers data: " + response); } - return new MovieInfo(fields, alternativeTitles, genres, spokenLanguages, cast, trailers); + return new MovieInfo(fields, alternativeTitles, genres, spokenLanguages, productionCountries, cast, trailers); } public List getArtwork(String id) throws IOException { @@ -389,6 +403,7 @@ public class TMDbClient implements MovieIdentificationService { protected String[] alternativeTitles; protected String[] genres; protected String[] spokenLanguages; + protected String[] productionCountries; protected Person[] people; protected Trailer[] trailers; @@ -397,11 +412,12 @@ public class TMDbClient implements MovieIdentificationService { // used by serializer } - protected MovieInfo(Map fields, List alternativeTitles, List genres, List spokenLanguages, List people, List trailers) { + protected MovieInfo(Map fields, List alternativeTitles, List genres, List spokenLanguages, List productionCountries, List people, List trailers) { this.fields = new EnumMap(fields); this.alternativeTitles = alternativeTitles.toArray(new String[0]); this.genres = genres.toArray(new String[0]); this.spokenLanguages = spokenLanguages.toArray(new String[0]); + this.productionCountries = productionCountries.toArray(new String[0]); this.people = people.toArray(new Person[0]); this.trailers = trailers.toArray(new Trailer[0]); } @@ -430,6 +446,10 @@ public class TMDbClient implements MovieIdentificationService { } } + public List getProductionCountries() { + return unmodifiableList(asList(productionCountries)); + } + public String getOriginalName() { return get(MovieProperty.original_title); }