|
|
|
|
@ -25,6 +25,7 @@ import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
import com.moviejukebox.themoviedb.model.Category;
|
|
|
|
|
import com.moviejukebox.themoviedb.model.Language;
|
|
|
|
|
import com.moviejukebox.themoviedb.model.MovieDB;
|
|
|
|
|
import com.moviejukebox.themoviedb.model.Person;
|
|
|
|
|
import com.moviejukebox.themoviedb.tools.MovieDbParser;
|
|
|
|
|
@ -41,25 +42,140 @@ import com.moviejukebox.themoviedb.tools.WebBrowser;
|
|
|
|
|
*/
|
|
|
|
|
public class TheMovieDb {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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) || (!isValidString(title))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isValidString(year)) {
|
|
|
|
|
if (isValidString(moviedb.getReleaseDate())) {
|
|
|
|
|
// Compare with year
|
|
|
|
|
String movieYear = moviedb.getReleaseDate().substring(0, 4);
|
|
|
|
|
if (movieYear.equals(year)) {
|
|
|
|
|
if (moviedb.getOriginalName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (moviedb.getTitle().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try matching the alternative name too
|
|
|
|
|
if (moviedb.getAlternativeName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Compare without year
|
|
|
|
|
if (moviedb.getOriginalName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (moviedb.getTitle().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try matching the alternative name too
|
|
|
|
|
if (moviedb.getAlternativeName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Search a list of movies and return the one that matches the title & year
|
|
|
|
|
* @param movieList The list of movies to search
|
|
|
|
|
* @param title The title to search for
|
|
|
|
|
* @param year The year of the title to search for
|
|
|
|
|
* @return The matching movie
|
|
|
|
|
*/
|
|
|
|
|
public static MovieDB findMovie(Collection<MovieDB> movieList, String title, String year) {
|
|
|
|
|
if ((movieList == null) || (movieList.isEmpty()) || (!isValidString(title))) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (MovieDB moviedb : movieList) {
|
|
|
|
|
if (compareMovies(moviedb, title, year)) {
|
|
|
|
|
return moviedb;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Check the string passed to see if it contains a value.
|
|
|
|
|
* @param testString The string to test
|
|
|
|
|
* @return False if the string is empty, null or UNKNOWN, True otherwise
|
|
|
|
|
*/
|
|
|
|
|
private static boolean isValidString(String testString) {
|
|
|
|
|
if ((testString == null)
|
|
|
|
|
|| (testString.trim().equals(""))
|
|
|
|
|
|| (testString.equalsIgnoreCase(MovieDB.UNKNOWN))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private String apiKey;
|
|
|
|
|
private static Logger logger = null;
|
|
|
|
|
private static LogFormatter tmdbFormatter = new LogFormatter();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* API Methods
|
|
|
|
|
* http://api.themoviedb.org/2.1
|
|
|
|
|
* Note: This is currently a read-only interface and as such, no write methods exist.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private static ConsoleHandler tmdbConsoleHandler = new ConsoleHandler();
|
|
|
|
|
|
|
|
|
|
private static final String apiSite = "http://api.themoviedb.org/2.1/";
|
|
|
|
|
private static final String defaultLanguage = "en-US";
|
|
|
|
|
private static final String GENRES_GET_LIST = "Genres.getList";
|
|
|
|
|
/*
|
|
|
|
|
* Media
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
private static final String MEDIA_GET_INFO = "Media.getInfo";
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Movies
|
|
|
|
|
*/
|
|
|
|
|
private static final String MOVIE_BROWSE = "Movie.browse";
|
|
|
|
|
private static final String MOVIE_GET_INFO = "Movie.getInfo";
|
|
|
|
|
private static final String MOVIE_GET_IMAGES = "Movie.getImages";
|
|
|
|
|
private static final String MOVIE_GET_INFO = "Movie.getInfo";
|
|
|
|
|
private static final String MOVIE_GET_LATEST = "Movie.getLatest";
|
|
|
|
|
private static final String MOVIE_GET_TRANSLATIONS = "Movie.getTranslations";
|
|
|
|
|
private static final String MOVIE_GET_VERSION = "Movie.getVersion";
|
|
|
|
|
private static final String MOVIE_IMDB_LOOKUP = "Movie.imdbLookup";
|
|
|
|
|
private static final String MOVIE_SEARCH = "Movie.search";
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* People
|
|
|
|
|
*/
|
|
|
|
|
private static final String PERSON_GET_INFO = "Person.getInfo";
|
|
|
|
|
private static final String PERSON_GET_LATEST = "Person.getLatest";
|
|
|
|
|
private static final String PERSON_GET_VERSION = "Person.getVersion";
|
|
|
|
|
private static final String PERSON_SEARCH = "Person.search";
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Misc
|
|
|
|
|
*/
|
|
|
|
|
private static final String GENRES_GET_LIST = "Genres.getList";
|
|
|
|
|
|
|
|
|
|
public static Logger getLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor with default logger.
|
|
|
|
|
* @param apiKey
|
|
|
|
|
*/
|
|
|
|
|
public TheMovieDb(String apiKey) {
|
|
|
|
|
setLogger(Logger.getLogger("TheMovieDB"));
|
|
|
|
|
if (!isValidString(apiKey)) {
|
|
|
|
|
@ -77,44 +193,55 @@ public class TheMovieDb {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set proxy parameters.
|
|
|
|
|
* @param host proxy host URL
|
|
|
|
|
* @param port proxy port
|
|
|
|
|
* @param username proxy username
|
|
|
|
|
* @param password proxy password
|
|
|
|
|
* Build comma separated ids for Movie.getLatest and Movie.getVersion.
|
|
|
|
|
* @param ids a List of ids
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public void setProxy(String host, String port, String username, String password) {
|
|
|
|
|
WebBrowser.setProxyHost(host);
|
|
|
|
|
WebBrowser.setProxyPort(port);
|
|
|
|
|
WebBrowser.setProxyUsername(username);
|
|
|
|
|
WebBrowser.setProxyPassword(password);
|
|
|
|
|
private String buildIds(List<String> ids) {
|
|
|
|
|
String s = "";
|
|
|
|
|
for (int i = 0; i < ids.size(); i++) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
s += ids.get(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
s += "," + ids.get(i);
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set web browser timeout.
|
|
|
|
|
* @param webTimeoutConnect
|
|
|
|
|
* @param webTimeoutRead
|
|
|
|
|
* Build the URL that is used to get the XML from TMDb.
|
|
|
|
|
*
|
|
|
|
|
* @param prefix The search prefix before the movie title
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @param searchTerm The search key to use, e.g. movie title or IMDb ID
|
|
|
|
|
* @return The search URL
|
|
|
|
|
*/
|
|
|
|
|
public void setTimeout(int webTimeoutConnect, int webTimeoutRead) {
|
|
|
|
|
WebBrowser.setWebTimeoutConnect(webTimeoutConnect);
|
|
|
|
|
WebBrowser.setWebTimeoutRead(webTimeoutRead);
|
|
|
|
|
private String buildUrl(String prefix, String searchTerm, String language) {
|
|
|
|
|
String url = apiSite + prefix + "/" + language + "/xml/" + apiKey;
|
|
|
|
|
|
|
|
|
|
if (!isValidString(searchTerm)) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Logger getLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
String encodedSearchTerm;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
encodedSearchTerm = URLEncoder.encode(searchTerm, "UTF-8");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
encodedSearchTerm = searchTerm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLogger(Logger logger) {
|
|
|
|
|
if (logger == null) {
|
|
|
|
|
return;
|
|
|
|
|
if (prefix.equals(MOVIE_BROWSE)) {
|
|
|
|
|
url += "?";
|
|
|
|
|
} else {
|
|
|
|
|
url += "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TheMovieDb.logger = logger;
|
|
|
|
|
tmdbConsoleHandler.setFormatter(tmdbFormatter);
|
|
|
|
|
tmdbConsoleHandler.setLevel(Level.FINE);
|
|
|
|
|
logger.addHandler(tmdbConsoleHandler);
|
|
|
|
|
logger.setUseParentHandlers(false);
|
|
|
|
|
logger.setLevel(Level.ALL);
|
|
|
|
|
url += encodedSearchTerm;
|
|
|
|
|
|
|
|
|
|
logger.finest("Search URL: " + url);
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -126,12 +253,12 @@ public class TheMovieDb {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the TMDb API key.
|
|
|
|
|
* @param apiKey a valid TMDb API key.
|
|
|
|
|
* Retrieve a list of valid genres within TMDb.
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public void setApiKey(String apiKey) {
|
|
|
|
|
this.apiKey = apiKey;
|
|
|
|
|
tmdbFormatter.addApiKey(apiKey);
|
|
|
|
|
public List<Category> getCategories(String language) {
|
|
|
|
|
return MovieDbParser.parseCategories(this.buildUrl(GENRES_GET_LIST, "", language));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -142,36 +269,8 @@ public class TheMovieDb {
|
|
|
|
|
return defaultLanguage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches the database using the movie title passed
|
|
|
|
|
*
|
|
|
|
|
* @param movieTitle The title to search for
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @return A movie bean with the data extracted
|
|
|
|
|
*/
|
|
|
|
|
public List<MovieDB> moviedbSearch(String movieTitle, String language) {
|
|
|
|
|
// If the title is null, then exit
|
|
|
|
|
if (!isValidString(movieTitle)) {
|
|
|
|
|
return new ArrayList<MovieDB>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String searchUrl = buildUrl(MOVIE_SEARCH, movieTitle, language);
|
|
|
|
|
return MovieDbParser.parseMovies(searchUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Browse the database using the default parameters.
|
|
|
|
|
* http://api.themoviedb.org/2.1/methods/Movie.browse
|
|
|
|
|
*
|
|
|
|
|
* @param orderBy either <code>rating</code>,
|
|
|
|
|
* <code>release</code> or <code>title</code>
|
|
|
|
|
* @param order how results are ordered. Either <code>asc</code> or
|
|
|
|
|
* <code>desc</code>
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return a list of MovieDB objects
|
|
|
|
|
*/
|
|
|
|
|
public List<MovieDB> moviedbBrowse(String orderBy, String order, String language) {
|
|
|
|
|
return this.moviedbBrowse(orderBy, order, new HashMap<String, String>(), language);
|
|
|
|
|
public List<Language> getTranslations(String movieId, String language) {
|
|
|
|
|
return MovieDbParser.parseLanguages(this.buildUrl(MOVIE_GET_TRANSLATIONS, movieId, language));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -227,35 +326,51 @@ public class TheMovieDb {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searches the database using the IMDb reference
|
|
|
|
|
* Browse the database using the default parameters.
|
|
|
|
|
* http://api.themoviedb.org/2.1/methods/Movie.browse
|
|
|
|
|
*
|
|
|
|
|
* @param imdbID IMDb reference, must include the "tt" at the start
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @return A movie bean with the data extracted
|
|
|
|
|
* @param orderBy either <code>rating</code>,
|
|
|
|
|
* <code>release</code> or <code>title</code>
|
|
|
|
|
* @param order how results are ordered. Either <code>asc</code> or
|
|
|
|
|
* <code>desc</code>
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return a list of MovieDB objects
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbImdbLookup(String imdbID, String language) {
|
|
|
|
|
MovieDB movie = new MovieDB();
|
|
|
|
|
public List<MovieDB> moviedbBrowse(String orderBy, String order, String language) {
|
|
|
|
|
return this.moviedbBrowse(orderBy, order, new HashMap<String, String>(), language);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the imdbID is null, then exit
|
|
|
|
|
if (!isValidString(imdbID)) {
|
|
|
|
|
/**
|
|
|
|
|
* The Movie.getImages method is used to retrieve all of the backdrops and
|
|
|
|
|
* posters for a particular movie. This is useful to scan for updates, or
|
|
|
|
|
* new images if that's all you're after.
|
|
|
|
|
* @param movieId the TMDb or IMDB ID (starting with tt) of the movie you
|
|
|
|
|
* are searching for.
|
|
|
|
|
* @param movie a MovieDB object
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbGetImages(String movieId, MovieDB movie, String language) {
|
|
|
|
|
// If the searchTerm is null, then exit
|
|
|
|
|
if (!isValidString(movieId)) {
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String searchUrl = buildUrl(MOVIE_IMDB_LOOKUP, imdbID, language);
|
|
|
|
|
String searchUrl = buildUrl(MOVIE_GET_IMAGES, movieId, language);
|
|
|
|
|
return MovieDbParser.parseMovie(searchUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Passes a null MovieDB object to the full function
|
|
|
|
|
*
|
|
|
|
|
* @param tmdbID TheMovieDB ID of the movie to get the information for
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @return A movie bean with all of the information
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbGetInfo(String tmdbID, String language) {
|
|
|
|
|
MovieDB movie = null;
|
|
|
|
|
movie = moviedbGetInfo(tmdbID, movie, language);
|
|
|
|
|
return movie;
|
|
|
|
|
* The Movie.getImages method is used to retrieve all of the backdrops and
|
|
|
|
|
* posters for a particular movie. This is useful to scan for updates, or
|
|
|
|
|
* new images if that's all you're after.
|
|
|
|
|
* @param movieId the TMDb or IMDB ID (starting with tt) of the movie you
|
|
|
|
|
* are searching for.
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbGetImages(String movieId, String language) {
|
|
|
|
|
return moviedbGetImages(movieId, new MovieDB(), language);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -287,6 +402,19 @@ public class TheMovieDb {
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Passes a null MovieDB object to the full function
|
|
|
|
|
*
|
|
|
|
|
* @param tmdbID TheMovieDB ID of the movie to get the information for
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @return A movie bean with all of the information
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbGetInfo(String tmdbID, String language) {
|
|
|
|
|
MovieDB movie = null;
|
|
|
|
|
movie = moviedbGetInfo(tmdbID, movie, language);
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Movie.getLatest method is a simple method. It returns the ID of the
|
|
|
|
|
* last movie created in the database. This is useful if you are scanning
|
|
|
|
|
@ -300,25 +428,6 @@ public class TheMovieDb {
|
|
|
|
|
return MovieDbParser.parseLatestMovie(buildUrl(MOVIE_GET_LATEST, "", language));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Movie.getVersion method is used to retrieve the last modified time
|
|
|
|
|
* along with the current version number of the called object(s). This is
|
|
|
|
|
* useful if you've already called the object sometime in the past and
|
|
|
|
|
* simply want to do a quick check for updates. <br/>
|
|
|
|
|
* The MovieDB object returned only has its title, TMDb id, IMDB id,
|
|
|
|
|
* version and last modified date initialized.
|
|
|
|
|
* @param movieId the TMDb ID or IMDB ID of the movie
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbGetVersion(String movieId, String language) {
|
|
|
|
|
List<MovieDB> movies = this.moviedbGetVersion(Arrays.asList(movieId), language);
|
|
|
|
|
if (movies.isEmpty()) {
|
|
|
|
|
return new MovieDB();
|
|
|
|
|
}
|
|
|
|
|
return movies.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Movie.getVersion method is used to retrieve the last modified time
|
|
|
|
|
* along with the current version number of the called object(s). This is
|
|
|
|
|
@ -346,53 +455,58 @@ public class TheMovieDb {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Movie.getImages method is used to retrieve all of the backdrops and
|
|
|
|
|
* posters for a particular movie. This is useful to scan for updates, or
|
|
|
|
|
* new images if that's all you're after.
|
|
|
|
|
* @param movieId the TMDb or IMDB ID (starting with tt) of the movie you
|
|
|
|
|
* are searching for.
|
|
|
|
|
* The Movie.getVersion method is used to retrieve the last modified time
|
|
|
|
|
* along with the current version number of the called object(s). This is
|
|
|
|
|
* useful if you've already called the object sometime in the past and
|
|
|
|
|
* simply want to do a quick check for updates. <br/>
|
|
|
|
|
* The MovieDB object returned only has its title, TMDb id, IMDB id,
|
|
|
|
|
* version and last modified date initialized.
|
|
|
|
|
* @param movieId the TMDb ID or IMDB ID of the movie
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbGetImages(String movieId, String language) {
|
|
|
|
|
return moviedbGetImages(movieId, new MovieDB(), language);
|
|
|
|
|
public MovieDB moviedbGetVersion(String movieId, String language) {
|
|
|
|
|
List<MovieDB> movies = this.moviedbGetVersion(Arrays.asList(movieId), language);
|
|
|
|
|
if (movies.isEmpty()) {
|
|
|
|
|
return new MovieDB();
|
|
|
|
|
}
|
|
|
|
|
return movies.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Movie.getImages method is used to retrieve all of the backdrops and
|
|
|
|
|
* posters for a particular movie. This is useful to scan for updates, or
|
|
|
|
|
* new images if that's all you're after.
|
|
|
|
|
* @param movieId the TMDb or IMDB ID (starting with tt) of the movie you
|
|
|
|
|
* are searching for.
|
|
|
|
|
* @param movie a MovieDB object
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
* Searches the database using the IMDb reference
|
|
|
|
|
*
|
|
|
|
|
* @param imdbID IMDb reference, must include the "tt" at the start
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @return A movie bean with the data extracted
|
|
|
|
|
*/
|
|
|
|
|
public MovieDB moviedbGetImages(String movieId, MovieDB movie, String language) {
|
|
|
|
|
// If the searchTerm is null, then exit
|
|
|
|
|
if (!isValidString(movieId)) {
|
|
|
|
|
public MovieDB moviedbImdbLookup(String imdbID, String language) {
|
|
|
|
|
MovieDB movie = new MovieDB();
|
|
|
|
|
|
|
|
|
|
// If the imdbID is null, then exit
|
|
|
|
|
if (!isValidString(imdbID)) {
|
|
|
|
|
return movie;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String searchUrl = buildUrl(MOVIE_GET_IMAGES, movieId, language);
|
|
|
|
|
String searchUrl = buildUrl(MOVIE_IMDB_LOOKUP, imdbID, language);
|
|
|
|
|
return MovieDbParser.parseMovie(searchUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Person.search method is used to search for an actor, actress or production member.
|
|
|
|
|
* http://api.themoviedb.org/2.1/methods/Person.search
|
|
|
|
|
* Searches the database using the movie title passed
|
|
|
|
|
*
|
|
|
|
|
* @param personName
|
|
|
|
|
* @param language
|
|
|
|
|
* @return
|
|
|
|
|
* @param movieTitle The title to search for
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @return A movie bean with the data extracted
|
|
|
|
|
*/
|
|
|
|
|
public Person personSearch(String personName, String language) {
|
|
|
|
|
if (!isValidString(personName)) {
|
|
|
|
|
return new Person();
|
|
|
|
|
public List<MovieDB> moviedbSearch(String movieTitle, String language) {
|
|
|
|
|
// If the title is null, then exit
|
|
|
|
|
if (!isValidString(movieTitle)) {
|
|
|
|
|
return new ArrayList<MovieDB>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String searchUrl = buildUrl(PERSON_SEARCH, personName, language);
|
|
|
|
|
return MovieDbParser.parsePersonInfo(searchUrl);
|
|
|
|
|
String searchUrl = buildUrl(MOVIE_SEARCH, movieTitle, language);
|
|
|
|
|
return MovieDbParser.parseMovies(searchUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -423,30 +537,6 @@ public class TheMovieDb {
|
|
|
|
|
return MovieDbParser.parseLatestPerson(buildUrl(PERSON_GET_LATEST, "", language));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Person.getVersion method is used to retrieve the last modified time
|
|
|
|
|
* along with the current version number of the called object(s). This is
|
|
|
|
|
* useful if you've already called the object sometime in the past and
|
|
|
|
|
* simply want to do a quick check for updates.
|
|
|
|
|
*
|
|
|
|
|
* @param personID a Person TMDb id
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Person personGetVersion(String personID, String language) {
|
|
|
|
|
Person person = new Person();
|
|
|
|
|
if (!isValidString(personID)) {
|
|
|
|
|
return person;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Person> people = this.personGetVersion(Arrays.asList(personID), language);
|
|
|
|
|
if (people.isEmpty()) {
|
|
|
|
|
return person;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return people.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Person.getVersion method is used to retrieve the last modified time
|
|
|
|
|
* along with the current version number of the called object(s). This is
|
|
|
|
|
@ -467,147 +557,89 @@ public class TheMovieDb {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a list of valid genres within TMDb.
|
|
|
|
|
* The Person.getVersion method is used to retrieve the last modified time
|
|
|
|
|
* along with the current version number of the called object(s). This is
|
|
|
|
|
* useful if you've already called the object sometime in the past and
|
|
|
|
|
* simply want to do a quick check for updates.
|
|
|
|
|
*
|
|
|
|
|
* @param personID a Person TMDb id
|
|
|
|
|
* @param language the two digit language code. E.g. en=English
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<Category> getCategories(String language) {
|
|
|
|
|
return MovieDbParser.parseCategories(this.buildUrl(GENRES_GET_LIST, "", language));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Search a list of movies and return the one that matches the title & year
|
|
|
|
|
* @param movieList The list of movies to search
|
|
|
|
|
* @param title The title to search for
|
|
|
|
|
* @param year The year of the title to search for
|
|
|
|
|
* @return The matching movie
|
|
|
|
|
*/
|
|
|
|
|
public static MovieDB findMovie(Collection<MovieDB> movieList, String title, String year) {
|
|
|
|
|
if ((movieList == null) || (movieList.isEmpty()) || (!isValidString(title))) {
|
|
|
|
|
return null;
|
|
|
|
|
public Person personGetVersion(String personID, String language) {
|
|
|
|
|
Person person = new Person();
|
|
|
|
|
if (!isValidString(personID)) {
|
|
|
|
|
return person;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (MovieDB moviedb : movieList) {
|
|
|
|
|
if (compareMovies(moviedb, title, year)) {
|
|
|
|
|
return moviedb;
|
|
|
|
|
}
|
|
|
|
|
List<Person> people = this.personGetVersion(Arrays.asList(personID), language);
|
|
|
|
|
if (people.isEmpty()) {
|
|
|
|
|
return person;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
return people.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
* The Person.search method is used to search for an actor, actress or production member.
|
|
|
|
|
* http://api.themoviedb.org/2.1/methods/Person.search
|
|
|
|
|
*
|
|
|
|
|
* @param personName
|
|
|
|
|
* @param language
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static boolean compareMovies(MovieDB moviedb, String title, String year) {
|
|
|
|
|
if ((moviedb == null) || (!isValidString(title))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isValidString(year)) {
|
|
|
|
|
if (isValidString(moviedb.getReleaseDate())) {
|
|
|
|
|
// Compare with year
|
|
|
|
|
String movieYear = moviedb.getReleaseDate().substring(0, 4);
|
|
|
|
|
if (movieYear.equals(year)) {
|
|
|
|
|
if (moviedb.getOriginalName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (moviedb.getTitle().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try matching the alternative name too
|
|
|
|
|
if (moviedb.getAlternativeName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Compare without year
|
|
|
|
|
if (moviedb.getOriginalName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (moviedb.getTitle().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
public Person personSearch(String personName, String language) {
|
|
|
|
|
if (!isValidString(personName)) {
|
|
|
|
|
return new Person();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try matching the alternative name too
|
|
|
|
|
if (moviedb.getAlternativeName().equalsIgnoreCase(title)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
String searchUrl = buildUrl(PERSON_SEARCH, personName, language);
|
|
|
|
|
return MovieDbParser.parsePersonInfo(searchUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the URL that is used to get the XML from TMDb.
|
|
|
|
|
*
|
|
|
|
|
* @param prefix The search prefix before the movie title
|
|
|
|
|
* @param language The two digit language code. E.g. en=English
|
|
|
|
|
* @param searchTerm The search key to use, e.g. movie title or IMDb ID
|
|
|
|
|
* @return The search URL
|
|
|
|
|
* Set the TMDb API key.
|
|
|
|
|
* @param apiKey a valid TMDb API key.
|
|
|
|
|
*/
|
|
|
|
|
private String buildUrl(String prefix, String searchTerm, String language) {
|
|
|
|
|
String url = apiSite + prefix + "/" + language + "/xml/" + apiKey;
|
|
|
|
|
|
|
|
|
|
if (!isValidString(searchTerm)) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String encodedSearchTerm;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
encodedSearchTerm = URLEncoder.encode(searchTerm, "UTF-8");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
encodedSearchTerm = searchTerm;
|
|
|
|
|
public void setApiKey(String apiKey) {
|
|
|
|
|
this.apiKey = apiKey;
|
|
|
|
|
tmdbFormatter.addApiKey(apiKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prefix.equals(MOVIE_BROWSE)) {
|
|
|
|
|
url += "?";
|
|
|
|
|
} else {
|
|
|
|
|
url += "/";
|
|
|
|
|
public void setLogger(Logger logger) {
|
|
|
|
|
if (logger == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url += encodedSearchTerm;
|
|
|
|
|
|
|
|
|
|
logger.finest("Search URL: " + url);
|
|
|
|
|
return url;
|
|
|
|
|
TheMovieDb.logger = logger;
|
|
|
|
|
tmdbConsoleHandler.setFormatter(tmdbFormatter);
|
|
|
|
|
tmdbConsoleHandler.setLevel(Level.FINE);
|
|
|
|
|
logger.addHandler(tmdbConsoleHandler);
|
|
|
|
|
logger.setUseParentHandlers(false);
|
|
|
|
|
logger.setLevel(Level.ALL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build comma separated ids for Movie.getLatest and Movie.getVersion.
|
|
|
|
|
* @param ids a List of ids
|
|
|
|
|
* @return
|
|
|
|
|
* Set proxy parameters.
|
|
|
|
|
* @param host proxy host URL
|
|
|
|
|
* @param port proxy port
|
|
|
|
|
* @param username proxy username
|
|
|
|
|
* @param password proxy password
|
|
|
|
|
*/
|
|
|
|
|
private String buildIds(List<String> ids) {
|
|
|
|
|
String s = "";
|
|
|
|
|
for (int i = 0; i < ids.size(); i++) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
s += ids.get(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
s += "," + ids.get(i);
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
public void setProxy(String host, String port, String username, String password) {
|
|
|
|
|
WebBrowser.setProxyHost(host);
|
|
|
|
|
WebBrowser.setProxyPort(port);
|
|
|
|
|
WebBrowser.setProxyUsername(username);
|
|
|
|
|
WebBrowser.setProxyPassword(password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check the string passed to see if it contains a value.
|
|
|
|
|
* @param testString The string to test
|
|
|
|
|
* @return False if the string is empty, null or UNKNOWN, True otherwise
|
|
|
|
|
* Set web browser timeout.
|
|
|
|
|
* @param webTimeoutConnect
|
|
|
|
|
* @param webTimeoutRead
|
|
|
|
|
*/
|
|
|
|
|
private static boolean isValidString(String testString) {
|
|
|
|
|
if ((testString == null)
|
|
|
|
|
|| (testString.trim().equals(""))
|
|
|
|
|
|| (testString.equalsIgnoreCase(MovieDB.UNKNOWN))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
public void setTimeout(int webTimeoutConnect, int webTimeoutRead) {
|
|
|
|
|
WebBrowser.setWebTimeoutConnect(webTimeoutConnect);
|
|
|
|
|
WebBrowser.setWebTimeoutRead(webTimeoutRead);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|