|
|
|
|
@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods;
|
|
|
|
|
|
|
|
|
|
import com.omertron.themoviedbapi.MovieDbException;
|
|
|
|
|
import com.omertron.themoviedbapi.model.Genre;
|
|
|
|
|
import com.omertron.themoviedbapi.model.MovieDb;
|
|
|
|
|
import com.omertron.themoviedbapi.model2.movie.MovieBasic;
|
|
|
|
|
import com.omertron.themoviedbapi.results.TmdbResultsList;
|
|
|
|
|
import com.omertron.themoviedbapi.tools.ApiUrl;
|
|
|
|
|
import com.omertron.themoviedbapi.tools.HttpTools;
|
|
|
|
|
@ -30,9 +30,9 @@ import com.omertron.themoviedbapi.tools.MethodSub;
|
|
|
|
|
import com.omertron.themoviedbapi.tools.Param;
|
|
|
|
|
import com.omertron.themoviedbapi.tools.TmdbParameters;
|
|
|
|
|
import com.omertron.themoviedbapi.wrapper.WrapperGenres;
|
|
|
|
|
import com.omertron.themoviedbapi.wrapper.WrapperMovie;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import org.yamj.api.common.exception.ApiExceptionType;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -53,19 +53,39 @@ public class TmdbGenres extends AbstractMethod {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* You can use this method to retrieve the list of genres used on TMDb.
|
|
|
|
|
* Get the list of movie genres.
|
|
|
|
|
*
|
|
|
|
|
* These IDs will correspond to those found in movie calls.
|
|
|
|
|
* @param language
|
|
|
|
|
* @return
|
|
|
|
|
* @throws MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
public TmdbResultsList<Genre> getGenreMovieList(String language) throws MovieDbException {
|
|
|
|
|
return getGenreList(language, MethodSub.MOVIE_LIST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the list of TV genres.
|
|
|
|
|
*
|
|
|
|
|
* @param language
|
|
|
|
|
* @return
|
|
|
|
|
* @throws MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
public TmdbResultsList<Genre> getGenreList(String language) throws MovieDbException {
|
|
|
|
|
public TmdbResultsList<Genre> getGenreTVList(String language) throws MovieDbException {
|
|
|
|
|
return getGenreList(language, MethodSub.TV_LIST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the list of genres for movies or TV
|
|
|
|
|
* @param language
|
|
|
|
|
* @param sub
|
|
|
|
|
* @return
|
|
|
|
|
* @throws MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
private TmdbResultsList<Genre> getGenreList(String language, MethodSub sub) throws MovieDbException {
|
|
|
|
|
TmdbParameters parameters = new TmdbParameters();
|
|
|
|
|
parameters.add(Param.LANGUAGE, language);
|
|
|
|
|
|
|
|
|
|
URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.LIST).buildUrl(parameters);
|
|
|
|
|
URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(sub).buildUrl(parameters);
|
|
|
|
|
String webpage = httpTools.getRequest(url);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
@ -74,43 +94,34 @@ public class TmdbGenres extends AbstractMethod {
|
|
|
|
|
results.copyWrapper(wrapper);
|
|
|
|
|
return results;
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre list", url, ex);
|
|
|
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre " + sub.toString(), url, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a list of movies per genre.
|
|
|
|
|
*
|
|
|
|
|
* It is important to understand that only movies with more than 10 votes
|
|
|
|
|
* get listed.
|
|
|
|
|
* Get the list of movies for a particular genre by id.
|
|
|
|
|
*
|
|
|
|
|
* This prevents movies from 1 10/10 rating from being listed first and for
|
|
|
|
|
* the first 5 pages.
|
|
|
|
|
* By default, only movies with 10 or more votes are included.
|
|
|
|
|
*
|
|
|
|
|
* @param genreId
|
|
|
|
|
* @param language
|
|
|
|
|
* @param page
|
|
|
|
|
* @param includeAllMovies
|
|
|
|
|
* @param includeAdult
|
|
|
|
|
* @return
|
|
|
|
|
* @throws MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
public TmdbResultsList<MovieDb> getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException {
|
|
|
|
|
public List<MovieBasic> getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException {
|
|
|
|
|
TmdbParameters parameters = new TmdbParameters();
|
|
|
|
|
parameters.add(Param.ID, genreId);
|
|
|
|
|
parameters.add(Param.LANGUAGE, language);
|
|
|
|
|
parameters.add(Param.PAGE, page);
|
|
|
|
|
parameters.add(Param.INCLUDE_ALL_MOVIES, includeAllMovies);
|
|
|
|
|
parameters.add(Param.INCLUDE_ADULT, includeAdult);
|
|
|
|
|
|
|
|
|
|
URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.MOVIES).buildUrl(parameters);
|
|
|
|
|
String webpage = httpTools.getRequest(url);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class);
|
|
|
|
|
TmdbResultsList<MovieDb> results = new TmdbResultsList<MovieDb>(wrapper.getMovies());
|
|
|
|
|
results.copyWrapper(wrapper);
|
|
|
|
|
return results;
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre movie list", url, ex);
|
|
|
|
|
}
|
|
|
|
|
return processWrapperList(TR_MOVIE_BASIC, url, webpage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|