From bb1d95e9e1b31f92e00ae9d14c43a4ebdac06032 Mon Sep 17 00:00:00 2001 From: Caleb Goh <46834785+heze8@users.noreply.github.com> Date: Wed, 6 Nov 2019 05:17:07 +0800 Subject: [PATCH] Added recommended movies method in tmdbMovies (#111) * Added reccomended movies method in tmdbMovies * Changed the MovieDb class to reflect the new Json data --- .../info/movito/themoviedbapi/TmdbMovies.java | 23 ++++++++++++++++++- .../movito/themoviedbapi/model/MovieDb.java | 17 +++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/info/movito/themoviedbapi/TmdbMovies.java b/src/main/java/info/movito/themoviedbapi/TmdbMovies.java index fb2362d9..f73b914a 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbMovies.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbMovies.java @@ -34,7 +34,7 @@ public static enum MovieMethod { alternative_titles, credits, images, keywords, releases, release_dates, @Deprecated trailers, videos, // replacement for trailers - translations, similar, + translations, similar, recommendations, reviews, lists, changes, latest, upcoming, now_playing, popular, top_rated, } @@ -203,6 +203,27 @@ public MovieResultsPage getSimilarMovies(int movieId, String language, Integer p return mapJsonResult(apiUrl, MovieResultsPage.class); } + /** + * The recomendations movies method will let you retrieve the reccomended movies for a particular movie. + *

+ * This data is created dynamically but with the help of TMDb internal algorithm. + *

+ * The data is much better with movies that are more popular + * + * @param movieId + * @param language + * @param page + */ + public MovieResultsPage getRecommendedMovies(int movieId, String language, Integer page) { + ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.recommendations); + + apiUrl.addLanguage(language); + + apiUrl.addPage(page); + + return mapJsonResult(apiUrl, MovieResultsPage.class); + } + /** * Get the lists that the movie belongs to diff --git a/src/main/java/info/movito/themoviedbapi/model/MovieDb.java b/src/main/java/info/movito/themoviedbapi/model/MovieDb.java index b886bc41..d8bcbe49 100644 --- a/src/main/java/info/movito/themoviedbapi/model/MovieDb.java +++ b/src/main/java/info/movito/themoviedbapi/model/MovieDb.java @@ -17,6 +17,7 @@ public class MovieDb extends IdElement implements Multi { @JsonProperty("title") private String title; + @JsonProperty("original_title") private String originalTitle; @@ -25,19 +26,25 @@ public class MovieDb extends IdElement implements Multi { @JsonProperty("backdrop_path") private String backdropPath; + @JsonProperty("poster_path") private String posterPath; @JsonProperty("release_date") private String releaseDate; + @JsonProperty("adult") private boolean adult; + @JsonProperty("belongs_to_collection") private Collection belongsToCollection; + @JsonProperty("budget") private long budget; + @JsonProperty("genres") private List genres; + @JsonProperty("homepage") private String homepage; @@ -53,11 +60,13 @@ public class MovieDb extends IdElement implements Multi { @JsonProperty("production_companies") private List productionCompanies; + @JsonProperty("production_countries") private List productionCountries; @JsonProperty("revenue") private long revenue; + @JsonProperty("runtime") private int runtime; @@ -72,6 +81,7 @@ public class MovieDb extends IdElement implements Multi { @JsonProperty("vote_average") private float voteAverage; + @JsonProperty("vote_count") private int voteCount; @@ -79,7 +89,6 @@ public class MovieDb extends IdElement implements Multi { private String status; // Appendable responses - @JsonProperty("alternative_titles") private MoviesAlternativeTitles alternativeTitles; @@ -105,6 +114,9 @@ public class MovieDb extends IdElement implements Multi { @JsonProperty("similar") private ResultsPage similarMovies; + @JsonProperty("recommendations") + private ResultsPage recommendedMovies; + @JsonProperty("reviews") private ResultsPage reviews; @@ -270,6 +282,9 @@ public List getSimilarMovies() { return similarMovies != null ? similarMovies.getResults() : null; } + public List getRecommendations() { + return recommendedMovies != null ? recommendedMovies.getResults() : null; + } public List getLists() { return lists != null ? lists.getResults() : null;