diff --git a/source/net/filebot/web/OMDbClient.java b/source/net/filebot/web/OMDbClient.java index 13a75ffc..568011f0 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, emptyList(), genres, emptyList(), emptyList(), emptyList(), actors, emptyList()); + return new MovieInfo(fields, emptyList(), genres, emptyMap(), emptyList(), emptyList(), emptyList(), actors, emptyList()); } } diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 817778ea..88a1de9d 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -16,6 +16,7 @@ import java.util.AbstractList; import java.util.ArrayList; import java.util.Collection; import java.util.EnumMap; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -256,13 +257,21 @@ public class TMDbClient implements MovieIdentificationService { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal alternative_titles data: " + response); } + Map certifications = new HashMap(); try { String countryCode = locale.getCountry().isEmpty() ? "US" : locale.getCountry(); JSONObject releases = (JSONObject) response.get("releases"); if (releases != null) { for (JSONObject it : jsonList(releases.get("countries"))) { - if (countryCode.equals(it.get("iso_3166_1"))) { - fields.put(MovieProperty.certification, (String) it.get("certification")); + String certificationCountry = (String) it.get("iso_3166_1"); + String certification = (String) it.get("certification"); + if (certification != null && certificationCountry != null && certification.length() > 0 && certificationCountry.length() > 0) { + // add country specific certification code + if (countryCode.equals(certificationCountry)) { + fields.put(MovieProperty.certification, certification); + } + // collect all certification codes just in case + certifications.put(certificationCountry, certification); } } } @@ -313,7 +322,7 @@ public class TMDbClient implements MovieIdentificationService { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal trailers data: " + response); } - return new MovieInfo(fields, alternativeTitles, genres, spokenLanguages, productionCountries, productionCompanies, cast, trailers); + return new MovieInfo(fields, alternativeTitles, genres, certifications, spokenLanguages, productionCountries, productionCompanies, cast, trailers); } public List getArtwork(String id) throws IOException { @@ -421,6 +430,7 @@ public class TMDbClient implements MovieIdentificationService { protected String[] spokenLanguages; protected String[] productionCountries; protected String[] productionCompanies; + protected Map certifications; protected Person[] people; protected Trailer[] trailers; @@ -429,10 +439,11 @@ public class TMDbClient implements MovieIdentificationService { // used by serializer } - protected MovieInfo(Map fields, List alternativeTitles, List genres, List spokenLanguages, List productionCountries, List productionCompanies, List people, List trailers) { + protected MovieInfo(Map fields, List alternativeTitles, List genres, Map certifications, List spokenLanguages, List productionCountries, List productionCompanies, List people, List trailers) { this.fields = new EnumMap(fields); this.alternativeTitles = alternativeTitles.toArray(new String[0]); this.genres = genres.toArray(new String[0]); + this.certifications = new HashMap(certifications); this.spokenLanguages = spokenLanguages.toArray(new String[0]); this.productionCountries = productionCountries.toArray(new String[0]); this.productionCompanies = productionCompanies.toArray(new String[0]); @@ -534,6 +545,11 @@ public class TMDbClient implements MovieIdentificationService { return get(MovieProperty.certification); } + public Map getCertifications() { + // e.g. ['US': PG-13] + return unmodifiableMap(certifications); + } + public String getCollection() { // e.g. Star Wars Collection return get(MovieProperty.collection);