fixes issue 13

master
Omertron 14 years ago
parent ae4af48179
commit 43c9660a74

@ -39,8 +39,8 @@ public class TheMovieDb {
private String apiKey;
private TmdbConfiguration tmdbConfig;
/*
* API Methods These are not set to static so that multiple instances of the
* API can co-exist
* API Methods: These are not set to static so that multiple instances of
* the API can co-exist
*/
private static final String BASE_MOVIE = "movie/";
private static final String BASE_PERSON = "person/";
@ -69,7 +69,7 @@ public class TheMovieDb {
*/
private final ApiUrl tmdbLatestMovie = new ApiUrl(this, "latest/movie");
private final ApiUrl tmdbNowPlaying = new ApiUrl(this, "movie/now-playing");
// - Populate Movie List
private final ApiUrl tmdbPopularMovieList = new ApiUrl(this, "movie/popular");
// - Top Rated Movies
// Company Info
// - Company Info
@ -134,6 +134,45 @@ public class TheMovieDb {
WebBrowser.setWebTimeoutRead(read);
}
/**
* Compare the MovieDB object with a title & year
*
* @param moviedb The moviedb object to compare too
* @param title The title of the movie to compare
* @param year The year of the movie to compare
* @return True if there is a match, False otherwise.
*/
public static boolean compareMovies(MovieDb moviedb, String title, String year) {
if ((moviedb == null) || (StringUtils.isBlank(title))) {
return false;
}
if (StringUtils.isNotBlank(year) && !year.equalsIgnoreCase("UNKNOWN") && StringUtils.isNotBlank(moviedb.getReleaseDate())) {
// Compare with year
String movieYear = moviedb.getReleaseDate().substring(0, 4);
if (movieYear.equals(year)) {
if (moviedb.getOriginalTitle().equalsIgnoreCase(title)) {
return true;
}
if (moviedb.getTitle().equalsIgnoreCase(title)) {
return true;
}
}
}
// Compare without year
if (moviedb.getOriginalTitle().equalsIgnoreCase(title)) {
return true;
}
if (moviedb.getTitle().equalsIgnoreCase(title)) {
return true;
}
return false;
}
/**
* Search Movies This is a good starting point to start finding movies on
* TMDb. The idea is to be a quick and light method so you can iterate
@ -603,59 +642,21 @@ public class TheMovieDb {
WrapperResultList resultList = mapper.readValue(webPage, WrapperResultList.class);
return resultList.getResults();
} catch (IOException ex) {
LOGGER.warn("Failed to get latest movie: " + ex.getMessage());
LOGGER.warn("Failed to get now playing movies: " + ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webPage, ex);
}
}
/**
* This method is used to retrieve the movies currently in theatres. This is
* a curated list that will normally contain 100 movies. The default
* response will return 20 movies.
*
* @return
* @throws MovieDbException
*/
public List<MovieDb> getNowPlayingMovies() throws MovieDbException {
return getNowPlayingMovies("");
}
/**
* Compare the MovieDB object with a title & year
*
* @param moviedb The moviedb object to compare too
* @param title The title of the movie to compare
* @param year The year of the movie to compare
* @return True if there is a match, False otherwise.
*/
public static boolean compareMovies(MovieDb moviedb, String title, String year) {
if ((moviedb == null) || (StringUtils.isBlank(title))) {
return false;
}
if (StringUtils.isNotBlank(year) && !year.equalsIgnoreCase("UNKNOWN") && StringUtils.isNotBlank(moviedb.getReleaseDate())) {
// Compare with year
String movieYear = moviedb.getReleaseDate().substring(0, 4);
if (movieYear.equals(year)) {
if (moviedb.getOriginalTitle().equalsIgnoreCase(title)) {
return true;
}
if (moviedb.getTitle().equalsIgnoreCase(title)) {
return true;
}
}
}
// Compare without year
if (moviedb.getOriginalTitle().equalsIgnoreCase(title)) {
return true;
}
public List<MovieDb> getPopularMovieList(String language) throws MovieDbException {
URL url = tmdbPopularMovieList.getIdUrl("", language);
String webPage = WebBrowser.request(url);
if (moviedb.getTitle().equalsIgnoreCase(title)) {
return true;
try {
WrapperResultList resultList = mapper.readValue(webPage, WrapperResultList.class);
return resultList.getResults();
} catch (IOException ex) {
LOGGER.warn("Failed to get popular movie list: " + ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webPage, ex);
}
return false;
}
}

@ -334,9 +334,19 @@ public class TheMovieDbTest {
* Test of getNowPlayingMovies method, of class TheMovieDb.
*/
@Test
public void testGetNowPlayingMovies() throws Exception {
public void testGetNowPlayingMovies() throws MovieDbException {
LOGGER.info("getNowPlayingMovies");
List<MovieDb> results = tmdb.getNowPlayingMovies();
assertTrue("No now playing movies foind", !results.isEmpty());
List<MovieDb> results = tmdb.getNowPlayingMovies("");
assertTrue("No now playing movies found", !results.isEmpty());
}
/**
* Test of getPopularMovieList method, of class TheMovieDb.
*/
@Test
public void testGetPopularMovieList() throws MovieDbException {
LOGGER.info("getPopularMovieList");
List<MovieDb> results = tmdb.getPopularMovieList("");
assertTrue("No popular movies found", !results.isEmpty());
}
}

Loading…
Cancel
Save