From 018c2b6bc53c416b57a32b92a91f32ed1ee772f0 Mon Sep 17 00:00:00 2001 From: Omertron Date: Wed, 25 Jan 2012 14:59:14 +0000 Subject: [PATCH] Remove v2.1 files --- .../moviejukebox/themoviedb/TheMovieDb.java | 656 ---------------- .../themoviedb/model/Artwork.java | 183 ----- .../themoviedb/model/Category.java | 79 -- .../themoviedb/model/Country.java | 68 -- .../themoviedb/model/Filmography.java | 96 --- .../themoviedb/model/Language.java | 81 -- .../themoviedb/model/MovieDB.java | 380 --------- .../moviejukebox/themoviedb/model/Person.java | 451 ----------- .../moviejukebox/themoviedb/model/Studio.java | 68 -- .../themoviedb/tools/DOMHelper.java | 107 --- .../themoviedb/tools/LogFormatter.java | 46 -- .../themoviedb/tools/ModelTools.java | 177 ----- .../themoviedb/tools/MovieDbParser.java | 739 ------------------ .../themoviedb/tools/WebBrowser.java | 332 -------- .../themoviedb/TheMovieDbTest.java | 487 ------------ 15 files changed, 3950 deletions(-) delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Artwork.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Category.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Country.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Filmography.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Language.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/MovieDB.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Person.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Studio.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/DOMHelper.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/LogFormatter.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/ModelTools.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/MovieDbParser.java delete mode 100644 themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/WebBrowser.java delete mode 100644 themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java deleted file mode 100644 index cf675fc7a..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java +++ /dev/null @@ -1,656 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.ConsoleHandler; -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; -import com.moviejukebox.themoviedb.tools.LogFormatter; -import com.moviejukebox.themoviedb.tools.WebBrowser; - -/** - * This is the main class for the API to connect to TheMovieDb.org. - * The implementation is for v2.1 of the API as detailed here: - * http://api.themoviedb.org/2.1 - * - * @author Stuart.Boston - * @version 1.3 - */ -public class TheMovieDb { - private String apiKey; - private static Logger logger = null; - private static LogFormatter tmdbFormatter = new LogFormatter(); - private static ConsoleHandler tmdbConsoleHandler = new ConsoleHandler(); - private static final String API_SITE = "http://api.themoviedb.org/2.1/"; - private static final String DEFAULT_LANGUAGE = "en-US"; - - /** - * Constructor with default logger. - * @param apiKey - */ - public TheMovieDb(String apiKey) { - setLogger(Logger.getLogger("TheMovieDB")); - if (!isValidString(apiKey)) { - logger.severe("TheMovieDb was initialized with a wrong API key!"); - } - setApiKey(apiKey); - } - - /* - * API Methods - * http://api.themoviedb.org/2.1 - * Note: This is currently a read-only interface and as such, no write methods exist. - */ - - /* - * 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_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"; - - /** - * 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 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; - } - - public static Logger getLogger() { - return logger; - } - - /** - * Build comma separated ids for Movie.getLatest and Movie.getVersion. - * @param ids a List of ids - * @return - */ - private String buildIds(List ids) { - StringBuilder builder = new StringBuilder(); - - for (int i = 0; i < ids.size(); i++) { - if (i == 0) { - builder.append(ids.get(i)); - continue; - } - builder.append(",").append(ids.get(i)); - } - return builder.toString(); - } - - /** - * 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 - */ - private String buildUrl(String prefix, String searchTerm, String language) { - StringBuilder url = new StringBuilder(); - - - - url.append(API_SITE); - url.append(prefix); - url.append("/"); - if (language.length() > 2) { - url.append(language.substring(0, 2)); - } else { - url.append(language); - } - url.append("/xml/"); - url.append(apiKey); - - if (!isValidString(searchTerm)) { - return url.toString(); - } - - if (prefix.equals(MOVIE_BROWSE)) { - url.append("?"); - } else { - url.append("/"); - } - - // Try to encode the search term to append - try { - url.append(URLEncoder.encode(searchTerm, "UTF-8")); - } catch (UnsupportedEncodingException e) { - url.append(searchTerm); - } - - return url.toString(); - } - - /** - * Return the API key. - * @return - */ - public String getApiKey() { - return apiKey; - } - - /** - * Retrieve a list of valid genres within TMDb. - * @param language the two digit language code. E.g. en=English - * @return - */ - public List getCategories(String language) { - return MovieDbParser.parseCategories(this.buildUrl(GENRES_GET_LIST, "", language)); - } - - /** - * Return the TMDb default language: en-US. - * @return - */ - public String getDefaultLanguage() { - return DEFAULT_LANGUAGE; - } - - public List getTranslations(String movieId, String language) { - return MovieDbParser.parseLanguages(this.buildUrl(MOVIE_GET_TRANSLATIONS, movieId, language)); - } - - /** - * Browse the database using optional parameters. - * http://api.themoviedb.org/2.1/methods/Movie.browse - * - * @param orderBy either rating, - * release or title - * @param order how results are ordered. Either asc or - * desc - * @param parameters a Map of optional parameters. See the complete list - * in the url above. - * @param language the two digit language code. E.g. en=English - * @return a list of MovieDB objects - */ - public List moviedbBrowse(String orderBy, String order, Map parameters, String language) { - - List movies = new ArrayList(); - if (!isValidString(orderBy) || (!isValidString(order)) - || (parameters == null) || parameters.isEmpty()) { - return movies; - } - - List validParameters = new ArrayList(); - validParameters.add("per_page"); - validParameters.add("page"); - validParameters.add("query"); - validParameters.add("min_votes"); - validParameters.add("rating_min"); - validParameters.add("rating_max"); - validParameters.add("genres"); - validParameters.add("genres_selector"); - validParameters.add("release_min"); - validParameters.add("release_max"); - validParameters.add("year"); - validParameters.add("certifications"); - validParameters.add("companies"); - validParameters.add("countries"); - - - StringBuilder searchUrl = new StringBuilder(); - searchUrl.append("order_by=").append(orderBy); - searchUrl.append("&order=").append(order); - - if(!parameters.isEmpty()) { - for (String key : validParameters) { - if (parameters.containsKey(key)) { - searchUrl.append("&").append(key).append("=").append(parameters.get(key)); - } - } - } - - // Get the search url - String baseUrl = buildUrl(MOVIE_BROWSE, "", language); - - // Now append the parameter url to the end of the search url - searchUrl.insert(0, "?"); - searchUrl.insert(0, baseUrl); - - return MovieDbParser.parseMovies(searchUrl.toString()); - - } - - /** - * Browse the database using the default parameters. - * http://api.themoviedb.org/2.1/methods/Movie.browse - * - * @param orderBy either rating, - * release or title - * @param order how results are ordered. Either asc or - * desc - * @param language the two digit language code. E.g. en=English - * @return a list of MovieDB objects - */ - public List moviedbBrowse(String orderBy, String order, String language) { - return moviedbBrowse(orderBy, order, new HashMap(), language); - } - - /** - * 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_GET_IMAGES, movieId, language); - return MovieDbParser.parseMovie(searchUrl); - } - - /** - * 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); - } - - /** - * Gets all the information for a given TheMovieDb ID - * - * @param movie - * An existing MovieDB object to populate with the data - * @param tmdbID - * The Movie Db ID for the movie to get 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, MovieDB movie, String language) { - // If the tmdbID is invalid, then exit - if (!isValidString(tmdbID)) { - return movie; - } - - String searchUrl = buildUrl(MOVIE_GET_INFO, tmdbID, language); - MovieDB foundMovie = MovieDbParser.parseMovie(searchUrl); - - if (foundMovie == null && !language.equalsIgnoreCase(DEFAULT_LANGUAGE)) { - logger.fine("Trying to get the '" + DEFAULT_LANGUAGE + "' version"); - searchUrl = buildUrl(MOVIE_GET_INFO, tmdbID, DEFAULT_LANGUAGE); - foundMovie = MovieDbParser.parseMovie(searchUrl); - } - - return foundMovie; - } - - /** - * 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) { - return moviedbGetInfo(tmdbID, new MovieDB(), language); - } - - /** - * 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 - * the database and want to know which id to stop at.
- * The MovieDB object returned only has its title, TMDb id, IMDB id, - * version and last modified date initialized. - * @param language the two digit language code. E.g. en=English - * @return - */ - public MovieDB moviedbGetLatest(String language) { - String searchUrl = buildUrl(MOVIE_GET_LATEST, "", language); - return MovieDbParser.parseLatestMovie(searchUrl); - } - - /** - * 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.
- * The MovieDB object returned only has its title, TMDb id, IMDB id, - * version and last modified date initialized. - * @param movieIds the ID of the TMDb movie you are looking for. - * This field supports an integer value (TMDb movie id) an - * IMDB ID or a combination of both. - * @param language the two digit language code. E.g. en=English - * @return - */ - public List moviedbGetVersion(List movieIds, String language) { - List movies = new ArrayList(); - - if ((movieIds == null) || movieIds.isEmpty()) { - return movies; - } - - String url = buildUrl(MOVIE_GET_VERSION, this.buildIds(movieIds), language); - return MovieDbParser.parseMovieGetVersion(url); - - } - - /** - * 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.
- * 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 movies = this.moviedbGetVersion(Arrays.asList(movieId), language); - if (movies.isEmpty()) { - return new MovieDB(); - } - return movies.get(0); - } - - /** - * 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 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_IMDB_LOOKUP, imdbID, language); - return MovieDbParser.parseMovie(searchUrl); - } - - /** - * 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 moviedbSearch(String movieTitle, String language) { - // If the title is null, then exit - if (!isValidString(movieTitle)) { - return new ArrayList(); - } - - String searchUrl = buildUrl(MOVIE_SEARCH, movieTitle, language); - return MovieDbParser.parseMovies(searchUrl); - } - - /** - * The Person.getInfo method is used to retrieve the full filmography, known movies, - * images and things like birthplace for a specific person in the TMDb database. - * - * @param personID - * @param language - * @return - */ - public ArrayList personGetInfo(String personID, String language) { - if (!isValidString(personID)) { - return new ArrayList(); - } - - String searchUrl = buildUrl(PERSON_GET_INFO, personID, language); - return MovieDbParser.parsePersonInfo(searchUrl); - } - - /** - * The Person.getLatest method is a simple method. It returns the ID of the - * last person created in the db. This is useful if you are scanning the - * database and want to know which id to stop at. - * @param language the two digit language code. E.g. en=English - * @return - */ - public Person personGetLatest(String language) { - 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 personIDs one or multiple Person TMDb ids - * @param language the two digit language code. E.g. en=English - * @return - */ - public List personGetVersion(List personIDs, String language) { - if ((personIDs == null) || (personIDs.isEmpty())) { - return new ArrayList(); - } - - String searchUrl = buildUrl(PERSON_GET_VERSION, this.buildIds(personIDs), language); - return MovieDbParser.parsePersonGetVersion(searchUrl); - } - - /** - * 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 people = this.personGetVersion(Arrays.asList(personID), language); - if (people.isEmpty()) { - return person; - } - - return people.get(0); - } - - /** - * 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 ArrayList personSearch(String personName, String language) { - if (!isValidString(personName)) { - return new ArrayList(); - } - - String searchUrl = buildUrl(PERSON_SEARCH, personName, language); - return MovieDbParser.parsePersonInfo(searchUrl); - } - - /** - * Set the TMDb API key. - * @param apiKey a valid TMDb API key. - */ - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - tmdbFormatter.addApiKey(apiKey); - } - - public void setLogger(Logger logger) { - if (logger == null) { - return; - } - - TheMovieDb.logger = logger; - tmdbConsoleHandler.setFormatter(tmdbFormatter); - tmdbConsoleHandler.setLevel(Level.FINE); - logger.addHandler(tmdbConsoleHandler); - logger.setUseParentHandlers(false); - logger.setLevel(Level.ALL); - } - - /** - * Set proxy parameters. - * @param host proxy host URL - * @param port proxy port - * @param username proxy username - * @param password proxy password - */ - public void setProxy(String host, String port, String username, String password) { - WebBrowser.setProxyHost(host); - WebBrowser.setProxyPort(port); - WebBrowser.setProxyUsername(username); - WebBrowser.setProxyPassword(password); - } - - /** - * Set web browser timeout. - * @param webTimeoutConnect - * @param webTimeoutRead - */ - public void setTimeout(int webTimeoutConnect, int webTimeoutRead) { - WebBrowser.setWebTimeoutConnect(webTimeoutConnect); - WebBrowser.setWebTimeoutRead(webTimeoutRead); - } - -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Artwork.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Artwork.java deleted file mode 100644 index 8cbed0983..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Artwork.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.model; - -import java.io.Serializable; - -/** - * This is the new bean for the Artwork - * - * @author Stuart.Boston - * - */ -public class Artwork implements Comparable, Serializable { - private static final long serialVersionUID = 1L; - - public static final String ARTWORK_TYPE_POSTER = "poster"; - public static final String ARTWORK_TYPE_BACKDROP = "backdrop"; - public static final String ARTWORK_TYPE_PERSON = "profile"; - public static final String[] ARTWORK_TYPES = {ARTWORK_TYPE_POSTER, ARTWORK_TYPE_BACKDROP, ARTWORK_TYPE_PERSON}; - - public static final String ARTWORK_SIZE_ORIGINAL = "original"; - public static final String ARTWORK_SIZE_THUMB = "thumb"; - public static final String ARTWORK_SIZE_MID = "mid"; - public static final String ARTWORK_SIZE_COVER = "cover"; - public static final String ARTWORK_SIZE_POSTER = "poster"; - public static final String ARTWORK_SIZE_PROFILE = "profile"; - public static final String[] ARTWORK_SIZES = {ARTWORK_SIZE_ORIGINAL, ARTWORK_SIZE_THUMB, ARTWORK_SIZE_MID, ARTWORK_SIZE_COVER, ARTWORK_SIZE_POSTER, ARTWORK_SIZE_PROFILE}; - - private String type; - private String size; - private String url; - private int id; - - public String[] getArtworkSizes() { - return ARTWORK_SIZES; - } - - public String[] getArtworkTypes() { - return ARTWORK_TYPES; - } - - public String getType() { - if (type == null) { - return MovieDB.UNKNOWN; - } else { - return type; - } - } - - public void setType(String type) { - this.type = type; - } - - public String getSize() { - if (size == null) { - return MovieDB.UNKNOWN; - } else { - return size; - } - } - - public void setSize(String size) { - this.size = size; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public int getId() { - return id; - } - - public void setId(String id) { - try { - this.id = Integer.parseInt(id); - } catch (Exception ignore) { - // If there is an issue with casting the Id then use Zero - this.id = 0; - } - } - - public void setId(int id) { - this.id = id; - } - - @Override - public int compareTo(Object otherArtwork) throws ClassCastException { - if (!(otherArtwork instanceof Artwork)) { - throw new ClassCastException("TheMovieDB API: An Artwork object is expected."); - } - - int anotherId = ((Artwork) otherArtwork).getId(); - return this.id - anotherId; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[Artwork=[type="); - builder.append(type); - builder.append("][size="); - builder.append(size); - builder.append("][url="); - builder.append(url); - builder.append("][id="); - builder.append(id); - builder.append("]]"); - return builder.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - result = prime * result + ((size == null) ? 0 : size.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + ((url == null) ? 0 : url.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null) { - return false; - } - - if (!(obj instanceof Artwork)) { - return false; - } - - Artwork other = (Artwork)obj; - - if (id != other.id) { - return false; - } - - if (size == null) { - if (other.size != null) { - return false; - } - } else if (!size.equals(other.size)) { - return false; - } - - if (type == null) { - if (other.type != null) { - return false; - } - } else if (!type.equals(other.type)) { - return false; - } - - if (url == null) { - if (other.url != null) { - return false; - } - } else if (!url.equals(other.url)) { - return false; - } - - return true; - } - } diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Category.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Category.java deleted file mode 100644 index 3958d8c3f..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Category.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.model; - -import java.io.Serializable; - -/** - * Category from TheMovieDB.org - * - * @author Stuart.Boston - * - */ -public class Category implements Serializable { - private static final long serialVersionUID = 1L; - - private static final String UNKNOWN = MovieDB.UNKNOWN; - - private String type = UNKNOWN; - private String name = UNKNOWN; - private String url = UNKNOWN; - private String id = UNKNOWN; - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public String getUrl() { - return url; - } - - public void setId(String id) { - this.id = id; - } - - public void setName(String name) { - this.name = name; - } - - public void setType(String type) { - this.type = type; - } - - public void setUrl(String url) { - this.url = url; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[Category=[type="); - builder.append(type); - builder.append("][name="); - builder.append(name); - builder.append("][url="); - builder.append(url); - builder.append("][id="); - builder.append(id); - builder.append("]]"); - return builder.toString(); - } -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Country.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Country.java deleted file mode 100644 index 1e59e92e5..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Country.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.model; - -import java.io.Serializable; - -/** - * Country from the MovieDB.org - * - * @author Stuart.Boston - * - */ -public class Country implements Serializable { - private static final long serialVersionUID = 1L; - - private static final String UNKNOWN = MovieDB.UNKNOWN; - - private String url = UNKNOWN; - private String name = UNKNOWN; - private String code = UNKNOWN; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[Country=[url="); - builder.append(url); - builder.append("][name="); - builder.append(name); - builder.append("][code="); - builder.append(code); - builder.append("]]"); - return builder.toString(); - } -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Filmography.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Filmography.java deleted file mode 100644 index 0e7e496be..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Filmography.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ - -package com.moviejukebox.themoviedb.model; - -import java.io.Serializable; - -public class Filmography implements Serializable { - private static final long serialVersionUID = 1L; - - private static final String UNKNOWN = MovieDB.UNKNOWN; - - private String url = UNKNOWN; - private String name = UNKNOWN; - private String department = UNKNOWN; - private String character = UNKNOWN; - private String job = UNKNOWN; - private String id = UNKNOWN; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDepartment() { - return department; - } - - public void setDepartment(String department) { - this.department = department; - } - - public String getCharacter() { - return character; - } - - public void setCharacter(String character) { - this.character = character; - } - - public String getJob() { - return job; - } - - public void setJob(String job) { - this.job = job; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[Filmography=[url="); - builder.append(url); - builder.append("][name="); - builder.append(name); - builder.append("][department="); - builder.append(department); - builder.append("][character="); - builder.append(character); - builder.append("][job="); - builder.append(job); - builder.append("][id="); - builder.append(id); - builder.append("]]"); - return builder.toString(); - } -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Language.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Language.java deleted file mode 100644 index 5fe0b8efb..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Language.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.model; - -import java.io.Serializable; - -/** - * Language from TheMovieDB.org - * @author stuart.boston - * - */ -public class Language implements Serializable { - private static final long serialVersionUID = 1L; - - private static final String UNKNOWN = MovieDB.UNKNOWN; - - private String isoCode = UNKNOWN; // The iso 639.1 Language code - private String englishName = UNKNOWN; - private String nativeName = UNKNOWN; - - public Language() { - this.isoCode = UNKNOWN; - this.englishName = UNKNOWN; - this.nativeName = UNKNOWN; - } - - public Language(String isoCode, String englishName, String nativeName) { - this.isoCode = isoCode; - this.englishName = englishName; - this.nativeName = nativeName; - } - - public String getEnglishName() { - return englishName; - } - - public String getIsoCode() { - return isoCode; - } - - public String getNativeName() { - return nativeName; - } - - public void setEnglishName(String englishName) { - this.englishName = englishName; - } - - public void setIsoCode(String isoCode) { - this.isoCode = isoCode; - } - - public void setNativeName(String nativeName) { - this.nativeName = nativeName; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[Language=[isoCode="); - builder.append(isoCode); - builder.append("][englishName="); - builder.append(englishName); - builder.append("][nativeName="); - builder.append(nativeName); - builder.append("]]"); - return builder.toString(); - } - - -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/MovieDB.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/MovieDB.java deleted file mode 100644 index d8a1cad8f..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/MovieDB.java +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.model; - -import com.moviejukebox.themoviedb.TheMovieDb; -import java.io.Serializable; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Date; - -import com.moviejukebox.themoviedb.tools.ModelTools; -import java.util.logging.Logger; - -/** - * This is the Movie Search bean for the MovieDb.org search - * - * @author Stuart.Boston - */ - -public class MovieDB extends ModelTools implements Serializable { - private static final long serialVersionUID = 1L; - private static final Logger logger = TheMovieDb.getLogger(); - - public static final String UNKNOWN = "UNKNOWN"; - - private String popularity = UNKNOWN; - private String translated = UNKNOWN; - private String adult = UNKNOWN; - private String language = UNKNOWN; - private String title = UNKNOWN; // "name" in the XML - private String originalName = UNKNOWN; // "original_name" in the XML - private String alternativeName = UNKNOWN; // "alternative_name" in the XML - private String type = UNKNOWN; - private String id = UNKNOWN; - private String imdb = UNKNOWN; // "imdb_id" in the XML - private String url = UNKNOWN; - private String overview = UNKNOWN; - private String rating = UNKNOWN; - private String tagline = UNKNOWN; - private String certification = UNKNOWN; - private String releaseDate = UNKNOWN; // "released" in the XML - private String runtime = UNKNOWN; - private String budget = UNKNOWN; - private String revenue = UNKNOWN; - private String homepage = UNKNOWN; - private String trailer = UNKNOWN; - private int version = -1; - private Date lastModifiedAt; - private List categories = new ArrayList(); - private List studios = new ArrayList(); - private List countries = new ArrayList(); - private List people = new ArrayList(); - - public String getPopularity() { - return popularity; - } - - public void setPopularity(String popularity) { - this.popularity = popularity; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getImdb() { - return imdb; - } - - public void setImdb(String imdb) { - this.imdb = imdb; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getOverview() { - return overview; - } - - public void setOverview(String overview) { - this.overview = overview; - } - - public String getReleaseDate() { - return releaseDate; - } - - public void setReleaseDate(String releaseDate) { - this.releaseDate = releaseDate; - } - - public String getRating() { - return rating; - } - - public void setRating(String rating) { - this.rating = rating; - } - - public String getRuntime() { - return runtime; - } - - public void setRuntime(String runtime) { - this.runtime = runtime; - } - - public String getBudget() { - return budget; - } - - public void setBudget(String budget) { - this.budget = budget; - } - - public String getRevenue() { - return revenue; - } - - public void setRevenue(String revenue) { - this.revenue = revenue; - } - - public String getHomepage() { - return homepage; - } - - public void setHomepage(String homepage) { - this.homepage = homepage; - } - - public String getTrailer() { - return trailer; - } - - public void setTrailer(String trailer) { - this.trailer = trailer; - } - - public List getProductionCountries() { - return countries; - } - - public void addProductionCountry(Country country) { - if (country != null) { - countries.add(country); - } - } - - public List getPeople() { - return people; - } - - public void addPerson(Person person) { - if (person != null) { - people.add(person); - } - } - - public List getCategories() { - return categories; - } - - public void addCategory(Category category) { - if (category != null) { - categories.add(category); - } - } - - public String getTranslated() { - return translated; - } - - public String getAdult() { - return adult; - } - - public String getLanguage() { - return language; - } - - public String getOriginalName() { - return originalName; - } - - public String getAlternativeName() { - return alternativeName; - } - - public String getTagline() { - return tagline; - } - - public String getCertification() { - return certification; - } - - public List getStudios() { - return studios; - } - - public List getCountries() { - return countries; - } - - public void setTranslated(String translated) { - this.translated = translated; - } - - public void setAdult(String adult) { - this.adult = adult; - } - - public void setLanguage(String language) { - this.language = language; - } - - public void setOriginalName(String originalName) { - this.originalName = originalName; - } - - public void setAlternativeName(String alternativeName) { - this.alternativeName = alternativeName; - } - - public void setTagline(String tagline) { - this.tagline = tagline; - } - - public void setCertification(String certification) { - this.certification = certification; - } - - public void setCategories(List categories) { - this.categories = categories; - } - - public void setStudios(List studios) { - this.studios = studios; - } - - public void addStudio(Studio studio) { - if (studio != null) { - this.studios.add(studio); - } - } - - public void setCountries(List countries) { - this.countries = countries; - } - - public void setPeople(List people) { - this.people = people; - } - - public Date getLastModifiedAt() { - return lastModifiedAt; - } - - public void setLastModifiedAt(Date lastModifiedAt) { - this.lastModifiedAt = lastModifiedAt; - } - - public void setLastModifiedAt(String lastModifiedAt) { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - setLastModifiedAt(df.parse(lastModifiedAt)); - } catch (ParseException ex) { - logger.fine("MovieDB: Error parsing date: " + lastModifiedAt); - } - } - - public int getVersion() { - return version; - } - - public void setVersion(int version) { - this.version = version; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[MovieDB=[popularity="); - builder.append(popularity); - builder.append("][translated="); - builder.append(translated); - builder.append("][adult="); - builder.append(adult); - builder.append("][language="); - builder.append(language); - builder.append("][title="); - builder.append(title); - builder.append("][originalName="); - builder.append(originalName); - builder.append("][alternativeName="); - builder.append(alternativeName); - builder.append("][type="); - builder.append(type); - builder.append("][id="); - builder.append(id); - builder.append("][imdb="); - builder.append(imdb); - builder.append("][url="); - builder.append(url); - builder.append("][overview="); - builder.append(overview); - builder.append("][rating="); - builder.append(rating); - builder.append("][tagline="); - builder.append(tagline); - builder.append("][certification="); - builder.append(certification); - builder.append("][releaseDate="); - builder.append(releaseDate); - builder.append("][runtime="); - builder.append(runtime); - builder.append("][budget="); - builder.append(budget); - builder.append("][revenue="); - builder.append(revenue); - builder.append("][homepage="); - builder.append(homepage); - builder.append("][trailer="); - builder.append(trailer); - builder.append("][version="); - builder.append(version); - builder.append("][lastModifiedAt="); - builder.append(lastModifiedAt); - builder.append("][categories="); - builder.append(categories); - builder.append("][studios="); - builder.append(studios); - builder.append("][countries="); - builder.append(countries); - builder.append("][people="); - builder.append(people); - builder.append("]]"); - return builder.toString(); - } -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Person.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Person.java deleted file mode 100644 index fb2598fbc..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Person.java +++ /dev/null @@ -1,451 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.model; - -import com.moviejukebox.themoviedb.TheMovieDb; -import java.io.Serializable; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import com.moviejukebox.themoviedb.tools.ModelTools; -import java.util.logging.Logger; - -/** - * This is the new bean for the Person - * - * @author Stuart.Boston - * - */ -public class Person extends ModelTools implements Serializable { - private static final long serialVersionUID = 1L; - private static final Logger logger = TheMovieDb.getLogger(); - - private static final String UNKNOWN = MovieDB.UNKNOWN; - - private String name = UNKNOWN; - private String character = UNKNOWN; - private String job = UNKNOWN; - private String id = UNKNOWN; - private String department = UNKNOWN; - private String biography = UNKNOWN; - private String url = UNKNOWN; - private int order = -1; - private int castId = -1; - private int version = -1; - private Date lastModifiedAt; - private int knownMovies = -1; - private Date birthday; - private String birthPlace = UNKNOWN; - private List filmography = new ArrayList(); - private List aka = new ArrayList(); - private List images = new ArrayList(); - - /** - * Add a single AKA - * @param alsoKnownAs - */ - public void addAka(String alsoKnownAs) { - this.aka.add(alsoKnownAs); - } - - /** - * Add a film for the person - * @param film - */ - public void addFilm(Filmography film) { - this.filmography.add(film); - } - - /** - * Add an artwork image to the person - * @param image - */ - public void addImage(Artwork image) { - if (image != null) { - this.images.add(image); - } - } - - /** - * Get all the AKA values - * @return - */ - public List getAka() { - return aka; - } - - /** - * Get the biography information - * @return - */ - public String getBiography() { - return biography; - } - - /** - * Get the birthday of the person - * @return - */ - public Date getBirthday() { - return birthday; - } - - /** - * Get the birthplace - * @return - */ - public String getBirthPlace() { - return birthPlace; - } - - /** - * get the cast ID - * @return - */ - public int getCastId() { - return castId; - } - - /** - * get the character - * @return - */ - public String getCharacter() { - return character; - } - - /** - * get the department - * @return - */ - public String getDepartment() { - return department; - } - - /** - * get the list of films - * @return - */ - public List getFilmography() { - return filmography; - } - - /** - * get the ID of the person - * @return - */ - public String getId() { - return id; - } - - /** - * get a list of images for the person - * @return - */ - public List getImages() { - return images; - } - - /** - * get the job - * @return - */ - public String getJob() { - return job; - } - - /** - * get the known movies - * @return - */ - public int getKnownMovies() { - return knownMovies; - } - - /** - * get the last modified date for the person - * @return - */ - public Date getLastModifiedAt() { - return lastModifiedAt; - } - - /** - * get the name - * @return - */ - public String getName() { - return name; - } - - /** - * get the order - * @return - */ - public int getOrder() { - return order; - } - - /** - * get the URL for the person - * @return - */ - public String getUrl() { - return url; - } - - /** - * get the version - * @return - */ - public int getVersion() { - return version; - } - - /** - * Set the AKA list for the person - * @param aka - */ - public void setAka(List aka) { - this.aka = aka; - } - - /** - * Set the biography - * @param biography - */ - public void setBiography(String biography) { - this.biography = biography; - } - - /** - * Set the person's birthday - * @param birthday - */ - public void setBirthday(Date birthday) { - this.birthday = birthday; - } - - /** - * Set the person's birthday - * @param sBirthday - */ - public void setBirthday(String sBirthday) { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - try { - setBirthday(df.parse(sBirthday)); - } catch (ParseException ex) { - logger.fine("TheMovieDB - Person: Error parsing birthday: " + sBirthday); - } - } - - /** - * Set the birth place - * @param birthPlace - */ - public void setBirthPlace(String birthPlace) { - this.birthPlace = birthPlace; - } - - /** - * Set the cast ID for the person - * @param castId - */ - public void setCastId(int castId) { - this.castId = castId; - } - - /** - * Set the cast ID for the person - * @param castId - */ - public void setCastId(String castId) { - try { - this.castId = Integer.parseInt(castId); - } catch (Exception ignore) { - this.castId = -1; - } - } - - /** - * Set the character - * @param character - */ - public void setCharacter(String character) { - this.character = character; - } - - /** - * set the Department - * @param department - */ - public void setDepartment(String department) { - this.department = department; - } - - /** - * Add a list of films - * @param filmography - */ - public void setFilmography(List filmography) { - this.filmography = filmography; - } - - /** - * Set the ID of the person - * @param id - */ - public void setId(String id) { - this.id = id; - } - - /** - * Set a list of images for the person - * @param images - */ - public void setImages(List images) { - this.images = images; - } - - /** - * Set the job for the person - * @param job - */ - public void setJob(String job) { - this.job = job; - } - - /** - * Set the known movie for the person - * @param knownMovies - */ - public void setKnownMovies(int knownMovies) { - this.knownMovies = knownMovies; - } - - /** - * Set the last modified date - * @param lastModifiedAt - */ - public void setLastModifiedAt(Date lastModifiedAt) { - this.lastModifiedAt = lastModifiedAt; - } - - /** - * Set the last modified date - * @param lastModifiedAt - */ - public void setLastModifiedAt(String lastModifiedAt) { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - try { - Date lma = df.parse(lastModifiedAt); - setLastModifiedAt(lma); - } catch (Exception ignore) { - return; - } - } - - /** - * Set the person's anme - * @param name - */ - public void setName(String name) { - this.name = name; - } - - /** - *Set the order - * @param order - */ - public void setOrder(int order) { - this.order = order; - } - - /** - * Set the order - * @param order - */ - public void setOrder(String order) { - try { - this.order = Integer.parseInt(order); - } catch (Exception ignore) { - this.order = -1; - } - } - - /** - * Set the URL - * @param url - */ - public void setUrl(String url) { - this.url = url; - } - - /** - * Set the version - * @param version - */ - public void setVersion(int version) { - this.version = version; - } - - /** - * Generate a String representation of the person - * @return - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[Person=[name="); - builder.append(name); - builder.append("][character="); - builder.append(character); - builder.append("][job="); - builder.append(job); - builder.append("][id="); - builder.append(id); - builder.append("][department="); - builder.append(department); - builder.append("][biography="); - builder.append(biography); - builder.append("][url="); - builder.append(url); - builder.append("][order="); - builder.append(order); - builder.append("][castId="); - builder.append(castId); - builder.append("][version="); - builder.append(version); - builder.append("][lastModifiedAt="); - builder.append(lastModifiedAt); - builder.append("][knownMovies="); - builder.append(knownMovies); - builder.append("][birthday="); - builder.append(birthday); - builder.append("][birthPlace="); - builder.append(birthPlace); - builder.append("][filmography="); - builder.append(filmography); - builder.append("][aka="); - builder.append(aka); - builder.append("][images="); - builder.append(images); - builder.append("]]"); - return builder.toString(); - } -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Studio.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Studio.java deleted file mode 100644 index 2804be103..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/model/Studio.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.model; - -import java.io.Serializable; - -/** - * Studio from the MovieDB.org - * - * @author Stuart.Boston - * - */ -public class Studio implements Serializable { - private static final long serialVersionUID = 1L; - - private static final String UNKNOWN = MovieDB.UNKNOWN; - - private String name = UNKNOWN; - private String url = UNKNOWN; - private String id = UNKNOWN; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[Studio=[name="); - builder.append(name); - builder.append("][url="); - builder.append(url); - builder.append("][id="); - builder.append(id); - builder.append("]]"); - return builder.toString(); - } -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/DOMHelper.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/DOMHelper.java deleted file mode 100644 index a9e4ea9d7..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/DOMHelper.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.tools; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.logging.Logger; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import com.moviejukebox.themoviedb.TheMovieDb; - -/** - * Generic set of routines to process the DOM model data - * @author Stuart.Boston - * - */ -public class DOMHelper { - private static final Logger logger = TheMovieDb.getLogger(); - - /** - * Gets the string value of the tag element name passed - * @param element - * @param tagName - * @return - */ - public static String getValueFromElement(Element element, String tagName) { - String returnValue = ""; - - try { - NodeList elementNodeList = element.getElementsByTagName(tagName); - Element tagElement = (Element) elementNodeList.item(0); - NodeList tagNodeList = tagElement.getChildNodes(); - returnValue = ((Node) tagNodeList.item(0)).getNodeValue(); - } catch (Exception ignore) { - return returnValue; - } - - return returnValue; - } - - /** - * Get a DOM document from the supplied URL - * @param url - * @return - * @throws IOException - * @throws ParserConfigurationException - * @throws SAXException - */ - public static Document getEventDocFromUrl(String url) - throws IOException, ParserConfigurationException, SAXException { - Document doc = null; - InputStream in = null; - String webPage = null; - - try { - boolean validWebPage = false; - webPage = WebBrowser.request(url); - - // There seems to be an error with some of the web pages that returns garbage - if (webPage.startsWith("() { - - @Override - public Object run() { - return System.getProperty("line.separator"); - } - }); - - @Override - public synchronized String format(LogRecord logRecord) { - String logMessage = logRecord.getMessage(); - - logMessage = "[TheMovieDb API] " + logMessage.replace(apiKey, "[APIKEY]") + EOL; - - Throwable thrown = logRecord.getThrown(); - if (thrown != null) { - logMessage = logMessage + thrown.toString(); - } - return logMessage; - } - - public void addApiKey(String apiKey) { - LogFormatter.apiKey = apiKey; - return; - } -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/ModelTools.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/ModelTools.java deleted file mode 100644 index 1f3f93d1f..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/ModelTools.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.tools; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.moviejukebox.themoviedb.model.Artwork; - -public class ModelTools { - private List artwork = new ArrayList(); - - /** - * Add a piece of artwork to the artwork array - * @param artworkType must be one of Artwork.ARTWORK_TYPES - * @param artworkSize must be one of Artwork.ARTWORK_SIZES - * @param artworkUrl - * @param posterId - */ - public void addArtwork(String artworkType, String artworkSize, String artworkUrl, String artworkId) { - if (validateElement(Artwork.ARTWORK_TYPES, artworkType) && validateElement(Artwork.ARTWORK_SIZES, artworkSize)) { - Artwork newArtwork = new Artwork(); - - newArtwork.setType(artworkType); - newArtwork.setSize(artworkSize); - newArtwork.setUrl(artworkUrl); - newArtwork.setId(artworkId); - - artwork.add(newArtwork); - Collections.sort(artwork); - } - return; - } - - /** - * Add a piece of artwork to the artwork array - * @param newArtwork an Artwork object to add to the array - */ - public void addArtwork(Artwork newArtwork) { - if (validateElement(Artwork.ARTWORK_TYPES, newArtwork.getType()) && validateElement(Artwork.ARTWORK_SIZES, newArtwork.getSize())) { - artwork.add(newArtwork); - Collections.sort(artwork); - } - return; - } - - /** - * Get the first artwork that matches the Type and Size - * @param artworkType - * @param artworkSize - * @return - */ - public Artwork getFirstArtwork(String artworkType, String artworkSize) { - return getArtwork(artworkType, artworkSize, 1); - } - - /** - * Check to see if element is contained in elementArray - * @param elementArray - * @param element - * @return - */ - private boolean validateElement(String[] elementArray, String element) { - boolean valid = false; - - for (String arrayEntry : elementArray) { - if (arrayEntry.equalsIgnoreCase(element)) { - valid = true; - break; - } - } - - return valid; - } - - /** - * Return all the artwork for a movie - * @return - */ - public List getArtwork() { - return artwork; - } - - /** - * Get all the artwork of a specific type - * @param artworkType - * @return - */ - public List getArtwork(String artworkType) { - // Validate the Type and Size arguments - if (!validateElement(Artwork.ARTWORK_TYPES, artworkType)) { - return null; - } - - List artworkList = new ArrayList(); - - for (Artwork singleArtwork : artwork) { - if (singleArtwork.getType().equalsIgnoreCase(artworkType)) { - artworkList.add(singleArtwork); - } - } - - return artworkList; - } - - /** - * Get all artwork of a specific Type and Size - * @param artworkType - * @param artworkSize - * @return - */ - public List getArtwork(String artworkType, String artworkSize) { - List artworkList = new ArrayList(); - // Validate the Type and Size arguments - if (!validateElement(Artwork.ARTWORK_TYPES, artworkType) && !validateElement(Artwork.ARTWORK_SIZES, artworkSize)) { - return null; - } - - for (Artwork singleArtwork : artwork) { - if (singleArtwork.getType().equalsIgnoreCase(artworkType) && singleArtwork.getSize().equalsIgnoreCase(artworkSize)) { - artworkList.add(singleArtwork); - } - } - - return artworkList; - } - - /** - * Return a specific artwork entry for a Type & Size - * @param artworkType - * @param artworkSize - * @param artworkNumber - * @return - */ - public Artwork getArtwork(String artworkType, String artworkSize, int artworkNumber) { - // Validate the Type and Size arguments - if (!validateElement(Artwork.ARTWORK_TYPES, artworkType) && !validateElement(Artwork.ARTWORK_SIZES, artworkSize)) { - return null; - } - - - int validArtworkNumber = artworkNumber; - // Validate the number - if (validArtworkNumber <= 0) { - validArtworkNumber = 0; - } else { - // Artwork elements start at 0 (Zero) - validArtworkNumber -= 1; - } - - List artworkList = getArtwork(artworkType, artworkSize); - - int artworkCount = artworkList.size(); - if (artworkCount < 1) { - return null; - } - - // If the number requested is greater than the array size, loop around until it's within scope - while (validArtworkNumber > artworkCount) { - validArtworkNumber = validArtworkNumber - artworkCount; - } - - return artworkList.get(validArtworkNumber); - } - -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/MovieDbParser.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/MovieDbParser.java deleted file mode 100644 index 24173b960..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/MovieDbParser.java +++ /dev/null @@ -1,739 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.tools; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import com.moviejukebox.themoviedb.TheMovieDb; -import com.moviejukebox.themoviedb.model.Artwork; -import com.moviejukebox.themoviedb.model.Category; -import com.moviejukebox.themoviedb.model.Country; -import com.moviejukebox.themoviedb.model.Filmography; -import com.moviejukebox.themoviedb.model.Language; -import com.moviejukebox.themoviedb.model.MovieDB; -import com.moviejukebox.themoviedb.model.Person; -import com.moviejukebox.themoviedb.model.Studio; - -/** - * The parser helper class for TheMovieDb API - * @author stuart.boston - */ -public class MovieDbParser { - - private static final Logger logger = TheMovieDb.getLogger(); - - private static final String NAME = "name"; - private static final String GENRE = "genre"; - private static final String ID = "id"; - private static final String URL = "url"; - private static final String LANGUAGE = "language"; - private static final String MOVIE = "movie"; - private static final String PERSON = "person"; - private static final String TYPE = "type"; - - /** - * Retrieve a list of valid genres within TMDb. - * @param doc a DOM document - * @return - */ - public static List parseCategories(String searchUrl) { - Document doc = null; - List categories = new ArrayList(); - - try { - doc = DOMHelper.getEventDocFromUrl(searchUrl); - } catch (Exception error) { - return categories; - } - - if (doc == null) { - return categories; - } - - NodeList genres = doc.getElementsByTagName(GENRE); - if ((genres == null) || genres.getLength() == 0) { - return categories; - } - - for (int i = 0; i < genres.getLength(); i++) { - Node node = genres.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; - Category category = new Category(); - category.setName(element.getAttribute(NAME)); - category.setId(DOMHelper.getValueFromElement(element, ID)); - category.setUrl(DOMHelper.getValueFromElement(element, URL)); - categories.add(category); - } - } - - return categories; - } - - /** - * Get the list of available languages - * @param url - * @return - */ - public static List parseLanguages(String url) { - List languages = new ArrayList(); - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(url); - } catch (Exception e) { - logger.severe("Movie.getTranslations error: " + e.getMessage()); - return languages; - } - - if (doc == null) { - return languages; - } - - NodeList nlLanguages = doc.getElementsByTagName(LANGUAGE); - - if ((nlLanguages == null) || nlLanguages.getLength() == 0) { - return languages; - } - - for (int i = 0; i < nlLanguages.getLength(); i++) { - Node node = nlLanguages.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; - languages.add(parseSimpleLanguage(element)); - } - } - - return languages; - } - - /** - * Parse a DOM document and returns the latest Movie. - * This method is used for Movie.getLatest and Movie.getVersion where only - * a few fields are initialized. - * @param doc - * @return - */ - public static MovieDB parseLatestMovie(String searchUrl) { - MovieDB movie = null; - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(searchUrl); - } catch (Exception error) { - logger.severe("GetLatest error: " + error.getMessage()); - return movie; - } - - if (doc == null) { - return movie; - } - - NodeList nlMovies = doc.getElementsByTagName(MOVIE); - - if ((nlMovies == null) || nlMovies.getLength() == 0) { - return movie; - } - - Node node = nlMovies.item(0); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; - movie = MovieDbParser.parseSimpleMovie(element); - } - - return movie; - } - - /** - * Parse a DOM document and return the person information - * @param url - * @return - */ - public static Person parseLatestPerson(String url) { - Person person = new Person(); - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(url); - } catch (Exception error) { - logger.severe("Person.getLatest error: " + error.getMessage()); - return person; - } - - if (doc == null) { - return person; - } - - NodeList nlMovies = doc.getElementsByTagName(PERSON); - - if ((nlMovies == null) || nlMovies.getLength() == 0) { - return person; - } - - Node node = nlMovies.item(0); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; - person = MovieDbParser.parseSimplePerson(element); - } - - return person; - } - - /** - * Returns the first MovieDB from the DOM Document. - * @param doc a DOM Document - * @return - */ - public static MovieDB parseMovie(String searchUrl) { - MovieDB movie = null; - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(searchUrl); - } catch (Exception error) { - logger.severe("TheMovieDb Error: " + error.getMessage()); - return movie; - } - - if (doc == null) { - return movie; - } - - NodeList nlMovies = doc.getElementsByTagName(MOVIE); - if ((nlMovies == null) || nlMovies.getLength() == 0) { - return movie; - } - - Node nMovie = nlMovies.item(0); - if (nMovie.getNodeType() == Node.ELEMENT_NODE) { - Element eMovie = (Element) nMovie; - movie = parseMovieInfo(eMovie); - } - - return movie; - } - - /** - * Parse the DOM document for movie information and return a list of movies - * @param url - * @return - */ - public static List parseMovieGetVersion(String url) { - List movies = new ArrayList(); - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(url); - } catch (Exception e) { - logger.severe("Movie.getVersion error: " + e.getMessage()); - return movies; - } - - if (doc == null) { - return movies; - } - - NodeList nlMovies = doc.getElementsByTagName(MOVIE); - - if ((nlMovies == null) || nlMovies.getLength() == 0) { - return movies; - } - - for (int i = 0; i < nlMovies.getLength(); i++) { - Node node = nlMovies.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; - movies.add(MovieDbParser.parseSimpleMovie(element)); - } - } - - return movies; - } - - /** - * Returns a MovieDB object from the Element - * @param movieElement - * @return - */ - private static MovieDB parseMovieInfo(Element movieElement) { - // Inspired by - // http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html - MovieDB movie = new MovieDB(); - NodeList subNodeList; - Node subNode; - Element subElement; - - try { - movie.setPopularity(DOMHelper.getValueFromElement(movieElement, "popularity")); - movie.setTranslated(DOMHelper.getValueFromElement(movieElement, "translated")); - movie.setAdult(DOMHelper.getValueFromElement(movieElement, "adult")); - movie.setLanguage(DOMHelper.getValueFromElement(movieElement, LANGUAGE)); - movie.setOriginalName(DOMHelper.getValueFromElement(movieElement, "original_name")); - movie.setTitle(DOMHelper.getValueFromElement(movieElement, NAME)); - movie.setAlternativeName(DOMHelper.getValueFromElement(movieElement, "alternative_name")); - movie.setType(DOMHelper.getValueFromElement(movieElement, TYPE)); - movie.setId(DOMHelper.getValueFromElement(movieElement, ID)); - movie.setImdb(DOMHelper.getValueFromElement(movieElement, "imdb_id")); - movie.setUrl(DOMHelper.getValueFromElement(movieElement, URL)); - movie.setOverview(DOMHelper.getValueFromElement(movieElement, "overview")); - movie.setRating(DOMHelper.getValueFromElement(movieElement, "rating")); - movie.setTagline(DOMHelper.getValueFromElement(movieElement, "tagline")); - movie.setCertification(DOMHelper.getValueFromElement(movieElement, "certification")); - movie.setReleaseDate(DOMHelper.getValueFromElement(movieElement, "released")); - movie.setRuntime(DOMHelper.getValueFromElement(movieElement, "runtime")); - movie.setBudget(DOMHelper.getValueFromElement(movieElement, "budget")); - movie.setRevenue(DOMHelper.getValueFromElement(movieElement, "revenue")); - movie.setHomepage(DOMHelper.getValueFromElement(movieElement, "homepage")); - movie.setTrailer(DOMHelper.getValueFromElement(movieElement, "trailer")); - - // Process the "categories" - subNodeList = movieElement.getElementsByTagName("categories"); - - for (int nodeLoop = 0; nodeLoop < subNodeList.getLength(); nodeLoop++) { - subNode = subNodeList.item(nodeLoop); - if (subNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) subNode; - - NodeList castList = subNode.getChildNodes(); - for (int i = 0; i < castList.getLength(); i++) { - Node personNode = castList.item(i); - if (personNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) personNode; - Category category = new Category(); - - category.setType(subElement.getAttribute(TYPE)); - category.setUrl(subElement.getAttribute(URL)); - category.setName(subElement.getAttribute(NAME)); - category.setId(subElement.getAttribute(ID)); - - movie.addCategory(category); - } - } - } - } - - // Process the "studios" - subNodeList = movieElement.getElementsByTagName("studios"); - - for (int nodeLoop = 0; nodeLoop < subNodeList.getLength(); nodeLoop++) { - subNode = subNodeList.item(nodeLoop); - if (subNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) subNode; - - NodeList studioList = subNode.getChildNodes(); - for (int i = 0; i < studioList.getLength(); i++) { - Node studioNode = studioList.item(i); - if (studioNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) studioNode; - Studio studio = new Studio(); - - studio.setUrl(subElement.getAttribute(URL)); - studio.setName(subElement.getAttribute(NAME)); - studio.setId(subElement.getAttribute(ID)); - - movie.addStudio(studio); - } - } - } - } - - // Process the "countries" - subNodeList = movieElement.getElementsByTagName("countries"); - - for (int nodeLoop = 0; nodeLoop < subNodeList.getLength(); nodeLoop++) { - subNode = subNodeList.item(nodeLoop); - if (subNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) subNode; - - NodeList countryList = subNode.getChildNodes(); - for (int i = 0; i < countryList.getLength(); i++) { - Node countryNode = countryList.item(i); - if (countryNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) countryNode; - Country country = new Country(); - - country.setName(subElement.getAttribute(NAME)); - country.setCode(subElement.getAttribute("code")); - country.setUrl(subElement.getAttribute(URL)); - - movie.addProductionCountry(country); - } - } - } - } - - // Process the "cast" - subNodeList = movieElement.getElementsByTagName("cast"); - - for (int nodeLoop = 0; nodeLoop < subNodeList.getLength(); nodeLoop++) { - subNode = subNodeList.item(nodeLoop); - if (subNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) subNode; - - NodeList castList = subNode.getChildNodes(); - for (int i = 0; i < castList.getLength(); i++) { - Node personNode = castList.item(i); - if (personNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) personNode; - Person person = new Person(); - - person.setName(subElement.getAttribute(NAME)); - person.setCharacter(subElement.getAttribute("character")); - person.setJob(subElement.getAttribute("job")); - person.setId(subElement.getAttribute(ID)); - person.addArtwork(Artwork.ARTWORK_TYPE_PERSON, - Artwork.ARTWORK_SIZE_THUMB, - subElement.getAttribute("thumb"), "-1"); - person.setDepartment(subElement.getAttribute("department")); - person.setUrl(subElement.getAttribute(URL)); - person.setOrder(subElement.getAttribute("order")); - person.setCastId(subElement.getAttribute("cast_id")); - - movie.addPerson(person); - } - } - } - } - - /* - * This processes the image elements. There are two formats to deal with: - * Movie.imdbLookup, Movie.getInfo & Movie.search: - * - * - * - * - * - * Movie.getImages: - * - * - * - * - * - * - * - * - * - * - * - * - * - */ - subNodeList = movieElement.getElementsByTagName("images"); - - for (int nodeLoop = 0; nodeLoop < subNodeList.getLength(); nodeLoop++) { - subNode = subNodeList.item(nodeLoop); - - if (subNode.getNodeType() == Node.ELEMENT_NODE) { - - NodeList artworkNodeList = subNode.getChildNodes(); - for (int artworkLoop = 0; artworkLoop < artworkNodeList.getLength(); artworkLoop++) { - Node artworkNode = artworkNodeList.item(artworkLoop); - if (artworkNode.getNodeType() == Node.ELEMENT_NODE) { - subElement = (Element) artworkNode; - - if (subElement.getNodeName().equalsIgnoreCase("image")) { - // This is the format used in Movie.imdbLookup, Movie.getInfo & Movie.search - Artwork artwork = new Artwork(); - artwork.setType(subElement.getAttribute(TYPE)); - artwork.setSize(subElement.getAttribute("size")); - artwork.setUrl(subElement.getAttribute(URL)); - artwork.setId(subElement.getAttribute(ID)); - movie.addArtwork(artwork); - } else if (subElement.getNodeName().equalsIgnoreCase("backdrop") - || subElement.getNodeName().equalsIgnoreCase("poster")) { - // This is the format used in Movie.getImages - String artworkId = subElement.getAttribute(ID); - String artworkType = subElement.getNodeName(); - - // We need to decode and loop round the child nodes to get the data - NodeList imageNodeList = subElement.getChildNodes(); - for (int imageLoop = 0; imageLoop < imageNodeList.getLength(); imageLoop++) { - Node imageNode = imageNodeList.item(imageLoop); - if (imageNode.getNodeType() == Node.ELEMENT_NODE) { - Element imageElement = (Element) imageNode; - Artwork artwork = new Artwork(); - artwork.setId(artworkId); - artwork.setType(artworkType); - artwork.setUrl(imageElement.getAttribute(URL)); - artwork.setSize(imageElement.getAttribute("size")); - movie.addArtwork(artwork); - } - } - } else { - // This is a classic, it should never happen error - logger.severe("UNKNOWN Image type: " + subElement.getNodeName()); - } - } - } - } - } - } catch (Exception error) { - logger.severe("ERROR: " + error.getMessage()); - final Writer eResult = new StringWriter(); - final PrintWriter printWriter = new PrintWriter(eResult); - error.printStackTrace(printWriter); - logger.severe(eResult.toString()); - } - return movie; - } - - /** - * Returns a list of MovieDB object parsed from the DOM Document - * even if there is only one movie - * @param doc DOM Document - * @return - */ - public static List parseMovies(String searchUrl) { - List movies = new ArrayList(); - - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(searchUrl); - } catch (Exception error) { - logger.severe("TheMovieDb Error: " + error.getMessage()); - return movies; - } - - if (doc == null) { - return movies; - } - - NodeList nlMovies = doc.getElementsByTagName(MOVIE); - - if ((nlMovies == null) || nlMovies.getLength() == 0) { - return movies; - } - - MovieDB movie = null; - - for (int i = 0; i < nlMovies.getLength(); i++) { - Node movieNode = nlMovies.item(i); - if (movieNode.getNodeType() == Node.ELEMENT_NODE) { - Element movieElement = (Element) movieNode; - movie = parseMovieInfo(movieElement); - if (movie != null) { - movies.add(movie); - } - } - } - return movies; - } - - /** - * Parse a DOM document and returns a list of Person - * @param doc a DOM document - * @return - */ - public static List parsePersonGetVersion(String searchUrl) { - List people = new ArrayList(); - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(searchUrl); - } catch (Exception error) { - logger.severe("PersonGetVersion error: " + error.getMessage()); - return people; - } - - if (doc == null) { - return people; - } - - NodeList movies = doc.getElementsByTagName(MOVIE); - if ((movies == null) || movies.getLength() == 0) { - return people; - } - - for (int i = 0; i < movies.getLength(); i++) { - Node node = movies.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; - people.add(MovieDbParser.parseSimplePerson(element)); - } - } - - return people; - } - - /** - * Parse the URL and return a list of the people found in the DOM document - */ - public static ArrayList parsePersonInfo(String searchUrl) { - ArrayList people = new ArrayList(); - Person person = null; - Document doc = null; - - try { - doc = DOMHelper.getEventDocFromUrl(searchUrl); - } catch (Exception error) { - logger.severe("PersonSearch error: " + error.getMessage()); - return people; - } - - if (doc == null) { - return people; - } - - NodeList personNodeList = doc.getElementsByTagName(PERSON); - - - if ((personNodeList == null) || personNodeList.getLength() == 0) { - return people; - } - - for (int loop = 0; loop < personNodeList.getLength(); loop++) { - Node personNode = personNodeList.item(loop); - person = new Person(); - - if (personNode == null) { - logger.finest("Person not found"); - return people; - } - - if (personNode.getNodeType() == Node.ELEMENT_NODE) { - try { - Element personElement = (Element) personNode; - - person.setName(DOMHelper.getValueFromElement(personElement, NAME)); - person.setId(DOMHelper.getValueFromElement(personElement, ID)); - person.setBiography(DOMHelper.getValueFromElement(personElement, "biography")); - - try { - person.setKnownMovies(Integer.parseInt(DOMHelper.getValueFromElement(personElement, "known_movies"))); - } catch (NumberFormatException error) { - person.setKnownMovies(0); - } - - person.setBirthday(DOMHelper.getValueFromElement(personElement, "birthday")); - person.setBirthPlace(DOMHelper.getValueFromElement(personElement, "birthplace")); - person.setUrl(DOMHelper.getValueFromElement(personElement, URL)); - person.setVersion(Integer.parseInt(DOMHelper.getValueFromElement(personElement, "version"))); - person.setLastModifiedAt(DOMHelper.getValueFromElement(personElement, "last_modified_at")); - - NodeList artworkNodeList = doc.getElementsByTagName("image"); - for (int nodeLoop = 0; nodeLoop < artworkNodeList.getLength(); nodeLoop++) { - Node artworkNode = artworkNodeList.item(nodeLoop); - if (artworkNode.getNodeType() == Node.ELEMENT_NODE) { - Element artworkElement = (Element) artworkNode; - Artwork artwork = new Artwork(); - artwork.setType(artworkElement.getAttribute(TYPE)); - artwork.setUrl(artworkElement.getAttribute(URL)); - artwork.setSize(artworkElement.getAttribute("size")); - artwork.setId(artworkElement.getAttribute(ID)); - person.addArtwork(artwork); - } - } - - NodeList filmNodeList = doc.getElementsByTagName(MOVIE); - for (int nodeLoop = 0; nodeLoop < filmNodeList.getLength(); nodeLoop++) { - Node filmNode = filmNodeList.item(nodeLoop); - if (filmNode.getNodeType() == Node.ELEMENT_NODE) { - Element filmElement = (Element) filmNode; - Filmography film = new Filmography(); - - film.setCharacter(filmElement.getAttribute("character")); - film.setDepartment(filmElement.getAttribute("department")); - film.setId(filmElement.getAttribute(ID)); - film.setJob(filmElement.getAttribute("job")); - film.setName(filmElement.getAttribute(NAME)); - film.setUrl(filmElement.getAttribute(URL)); - - person.addFilm(film); - } - } - - people.add(person); - } catch (Exception error) { - logger.severe("PersonInfo: " + error.getMessage()); - final Writer eResult = new StringWriter(); - final PrintWriter printWriter = new PrintWriter(eResult); - error.printStackTrace(printWriter); - logger.severe(eResult.toString()); - } - } - } - - return people; - } - - /** - * Parse a "simple" Language in the form: - * - * English - * English - * - * @param element - * @return - */ - private static Language parseSimpleLanguage(Element element) { - Language language = new Language(); - language.setIsoCode(element.getAttribute("iso_639_1")); - language.setEnglishName(DOMHelper.getValueFromElement(element, "english_name")); - language.setNativeName(DOMHelper.getValueFromElement(element, "native_name")); - return language; - } - - /** - * Parse a "simple" Movie in the form: - * - * Inception - * 36462 - * tt1375666 - * 11 - * 2010-07-26 17:06:18 - * - * @param element - * @return - */ - private static MovieDB parseSimpleMovie(Element element) { - MovieDB movie = new MovieDB(); - movie.setTitle(DOMHelper.getValueFromElement(element, NAME)); - movie.setId(DOMHelper.getValueFromElement(element, ID)); - movie.setImdb(DOMHelper.getValueFromElement(element, "imdb_id")); - movie.setVersion(Integer.valueOf(DOMHelper.getValueFromElement(element, "version"))); - movie.setLastModifiedAt(DOMHelper.getValueFromElement(element, "last_modified_at")); - return movie; - } - - /** - * Parse a "simple" Person in the form: - * - * John Joseph - * 111830 - * 3 - * 2010-07-19 10:59:13 - * - * @param element - * @return - */ - private static Person parseSimplePerson(Element element) { - Person person = new Person(); - person.setName(DOMHelper.getValueFromElement(element, NAME)); - person.setId(DOMHelper.getValueFromElement(element, ID)); - person.setVersion(Integer.valueOf(DOMHelper.getValueFromElement(element, "version"))); - person.setLastModifiedAt(DOMHelper.getValueFromElement(element, "last_modified_at")); - return person; - } - -} diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/WebBrowser.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/WebBrowser.java deleted file mode 100644 index f8459f622..000000000 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/tools/WebBrowser.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb.tools; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.Charset; -import java.nio.charset.UnsupportedCharsetException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.apache.commons.codec.binary.Base64; - -/** - * Web browser with simple cookies support - */ -public final class WebBrowser { - - private static Map browserProperties = new HashMap(); - private static Map> cookies = new HashMap>(); - private static String proxyHost = null; - private static String proxyPort = null; - private static String proxyUsername = null; - private static String proxyPassword = null; - private static String proxyEncodedPassword = null; - private static int webTimeoutConnect = 25000; // 25 second timeout - private static int webTimeoutRead = 90000; // 90 second timeout - - /** - * Constructor for WebBrowser. - * Does instantiates the browser properties. - */ - public WebBrowser() { - if (browserProperties.isEmpty()) { - browserProperties.put("User-Agent", "Mozilla/5.25 Netscape/5.0 (Windows; I; Win95)"); - } - } - - /** - * Request the web page at the specified URL - * @param url - * @return - * @throws IOException - */ - public static String request(String url) throws IOException { - return request(new URL(url)); - } - - /** - * Open a connection using proxy parameters if they exist. - * @param url - * @return - * @throws IOException - */ - public static URLConnection openProxiedConnection(URL url) throws IOException { - if (proxyHost != null) { - System.getProperties().put("proxySet", "true"); - System.getProperties().put("proxyHost", proxyHost); - System.getProperties().put("proxyPort", proxyPort); - } - - URLConnection cnx = url.openConnection(); - - if (proxyUsername != null) { - cnx.setRequestProperty("Proxy-Authorization", proxyEncodedPassword); - } - - return cnx; - } - - /** - * Request the web page at the specified URL - * @param url - * @return - * @throws IOException - */ - public static String request(URL url) throws IOException { - StringBuilder content = new StringBuilder(); - - BufferedReader in = null; - URLConnection cnx = null; - try { - cnx = openProxiedConnection(url); - - sendHeader(cnx); - readHeader(cnx); - - in = new BufferedReader(new InputStreamReader(cnx.getInputStream(), getCharset(cnx))); - String line; - while ((line = in.readLine()) != null) { - content.append(line); - } - } finally { - if (in != null) { - in.close(); - } - - if ((cnx != null) && (cnx instanceof HttpURLConnection)) { - ((HttpURLConnection) cnx).disconnect(); - } - - } - return content.toString(); - } - - /** - * Set the header information for the connection - * @param cnx - */ - private static void sendHeader(URLConnection cnx) { - // send browser properties - for (Map.Entry browserProperty : browserProperties.entrySet()) { - cnx.setRequestProperty(browserProperty.getKey(), browserProperty.getValue()); - } - // send cookies - String cookieHeader = createCookieHeader(cnx); - if (!cookieHeader.isEmpty()) { - cnx.setRequestProperty("Cookie", cookieHeader); - } - } - - /** - * Create the cookies for the header - * @param cnx - * @return - */ - private static String createCookieHeader(URLConnection cnx) { - String host = cnx.getURL().getHost(); - StringBuilder cookiesHeader = new StringBuilder(); - for (Map.Entry> domainCookies : cookies.entrySet()) { - if (host.endsWith(domainCookies.getKey())) { - for (Map.Entry cookie : domainCookies.getValue().entrySet()) { - cookiesHeader.append(cookie.getKey()); - cookiesHeader.append("="); - cookiesHeader.append(cookie.getValue()); - cookiesHeader.append(";"); - } - } - } - if (cookiesHeader.length() > 0) { - // remove last ; char - cookiesHeader.deleteCharAt(cookiesHeader.length() - 1); - } - return cookiesHeader.toString(); - } - - /** - * Read the header information into the cookies - * @param cnx - */ - private static void readHeader(URLConnection cnx) { - // read new cookies and update our cookies - for (Map.Entry> header : cnx.getHeaderFields().entrySet()) { - if ("Set-Cookie".equals(header.getKey())) { - for (String cookieHeader : header.getValue()) { - String[] cookieElements = cookieHeader.split(" *; *"); - if (cookieElements.length >= 1) { - String[] firstElem = cookieElements[0].split(" *= *"); - String cookieName = firstElem[0]; - String cookieValue = firstElem.length > 1 ? firstElem[1] : null; - String cookieDomain = null; - // find cookie domain - for (int i = 1; i < cookieElements.length; i++) { - String[] cookieElement = cookieElements[i].split(" *= *"); - if ("domain".equals(cookieElement[0])) { - cookieDomain = cookieElement.length > 1 ? cookieElement[1] : null; - break; - } - } - if (cookieDomain == null) { - // if domain isn't set take current host - cookieDomain = cnx.getURL().getHost(); - } - Map domainCookies = cookies.get(cookieDomain); - if (domainCookies == null) { - domainCookies = new HashMap(); - cookies.put(cookieDomain, domainCookies); - } - // add or replace cookie - domainCookies.put(cookieName, cookieValue); - } - } - } - } - } - - /** - * Determine the charset for the connection - * @param cnx - * @return - */ - private static Charset getCharset(URLConnection cnx) { - Charset charset = null; - // content type will be string like "text/html; charset=UTF-8" or "text/html" - String contentType = cnx.getContentType(); - if (contentType != null) { - // changed 'charset' to 'harset' in regexp because some sites send 'Charset' - Matcher m = Pattern.compile("harset *=[ '\"]*([^ ;'\"]+)[ ;'\"]*").matcher(contentType); - if (m.find()) { - String encoding = m.group(1); - try { - charset = Charset.forName(encoding); - } catch (UnsupportedCharsetException e) { - // there will be used default charset - } - } - } - if (charset == null) { - charset = Charset.defaultCharset(); - } - - return charset; - } - - /** - * Return the proxy host name - * @return - */ - public static String getProxyHost() { - return proxyHost; - } - - /** - * Set the proxy host name - * @param tvdbProxyHost - */ - public static void setProxyHost(String tvdbProxyHost) { - WebBrowser.proxyHost = tvdbProxyHost; - } - - /** - * Get the proxy port - * @return - */ - public static String getProxyPort() { - return proxyPort; - } - - /** - * Set the proxy port - * @param proxyPort - */ - public static void setProxyPort(String proxyPort) { - WebBrowser.proxyPort = proxyPort; - } - - /** - * Get the proxy username - * @return - */ - public static String getProxyUsername() { - return proxyUsername; - } - - /** - * Set the proxy username - * @param proxyUsername - */ - public static void setProxyUsername(String proxyUsername) { - WebBrowser.proxyUsername = proxyUsername; - } - - /** - * Get the proxy password - * @return - */ - public static String getProxyPassword() { - return proxyPassword; - } - - /** - * Set the proxy password. - * Note this will automatically encode the password - * @param proxyPassword - */ - public static void setProxyPassword(String proxyPassword) { - WebBrowser.proxyPassword = proxyPassword; - - if (proxyUsername != null) { - proxyEncodedPassword = proxyUsername + ":" + proxyPassword; - proxyEncodedPassword = "Basic " + new String(Base64.encodeBase64((proxyUsername + ":" + proxyPassword).getBytes())); - } - } - - /** - * Get the current web connect timeout value - * @return - */ - public static int getWebTimeoutConnect() { - return webTimeoutConnect; - } - - /** - * Get the current web read timeout value - * @return - */ - public static int getWebTimeoutRead() { - return webTimeoutRead; - } - - /** - * Set the web connect timeout value - * @param webTimeoutConnect - */ - public static void setWebTimeoutConnect(int webTimeoutConnect) { - WebBrowser.webTimeoutConnect = webTimeoutConnect; - } - - /** - * Set the web read timeout value - * @param webTimeoutRead - */ - public static void setWebTimeoutRead(int webTimeoutRead) { - WebBrowser.webTimeoutRead = webTimeoutRead; - } -} diff --git a/themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java b/themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java deleted file mode 100644 index 65765d4d7..000000000 --- a/themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Copyright (c) 2004-2012 YAMJ Members - * http://code.google.com/p/moviejukebox/people/list - * - * Web: http://code.google.com/p/moviejukebox/ - * - * This software is licensed under a Creative Commons License - * See this page: http://code.google.com/p/moviejukebox/wiki/License - * - * For any reuse or distribution, you must make clear to others the - * license terms of this work. - */ -package com.moviejukebox.themoviedb; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; - -import com.moviejukebox.themoviedb.model.Category; -import com.moviejukebox.themoviedb.model.MovieDB; -import com.moviejukebox.themoviedb.model.Person; - -/** - * JUnit tests for TheMovieDb class. The tester must enter its IMDb API key for - * these tests to work. Require JUnit 4.5. - * @author mledoze - */ -public class TheMovieDbTest { - - private static String apikey = ""; - private TheMovieDb tmdb; - - public TheMovieDbTest() { - } - - @Before - public void setUp() { - tmdb = new TheMovieDb(apikey); - } - - @Test - public void testGetApiKey() { - assertEquals(apikey, tmdb.getApiKey()); - } - - @Test - public void testGetDefaultLanguage() { - assertEquals("en-US", tmdb.getDefaultLanguage()); - } - - @Test - public void testMoviedbSearch() { - String title = "Inception"; - List movies = tmdb.moviedbSearch(title, "en"); - assertFalse(movies.isEmpty()); - assertEquals(title, movies.get(0).getTitle()); - } - - @Test - public void testMoviedbSearch_withWrongTitle() { - List movies = tmdb.moviedbSearch("à(é!àç'(è!çé(èçéè'(éàç!'(èéàç!(èç'", "en"); - assertTrue(movies.isEmpty()); - } - - @Test - public void testMoviedbSearch_withEmptyTitle() { - List movies = tmdb.moviedbSearch("", "en"); - assertTrue(movies.isEmpty()); - } - - @Test - public void testMoviedbSearch_withNullTitle() { - List movies = tmdb.moviedbSearch((String) null, "en"); - assertTrue(movies.isEmpty()); - } - - //*** Start moviedbBrowse - @Test - public void testMoviedbBrowseRatingAsc() { - Map params = new HashMap(); - params.put("year", "2011"); - - List movies = tmdb.moviedbBrowse("rating", "asc", params, "en"); - - assertFalse(movies.isEmpty()); - } - - @Test - public void testMoviedbBrowseReleaseAsc() { - Map params = new HashMap(); - params.put("year", "2011"); - - List movies = tmdb.moviedbBrowse("release", "asc", params, "en"); - assertFalse(movies.isEmpty()); - } - - @Test - public void testMoviedbBrowseTitleAsc() { - Map params = new HashMap(); - params.put("year", "2011"); - - List movies = tmdb.moviedbBrowse("title", "asc", params, "en"); - assertFalse(movies.isEmpty()); - } - - @Test - public void testMoviedbBrowseRatingDesc() { - Map params = new HashMap(); - params.put("year", "2011"); - - List movies = tmdb.moviedbBrowse("rating", "desc", params, "en"); - assertFalse(movies.isEmpty()); - } - - @Test - public void testMoviedbBrowseReleaseDesc() { - Map params = new HashMap(); - params.put("year", "2011"); - - List movies = tmdb.moviedbBrowse("release", "desc", params, "en"); - assertFalse(movies.isEmpty()); - } - - @Test - public void testMoviedbBrowseTitleDesc() { - Map params = new HashMap(); - params.put("year", "2011"); - - List movies = tmdb.moviedbBrowse("title", "desc", params, "en"); - assertFalse(movies.isEmpty()); - } - - @Test - public void testMoviedbBrowse_withEmptyOrderBy() { - assertTrue(tmdb.moviedbBrowse("", "asc", "en").isEmpty()); - } - - @Test - public void testMoviedbBrowse_withNullOrderBy() { - assertTrue(tmdb.moviedbBrowse((String) null, "asc", "en").isEmpty()); - } - - @Test - public void testMoviedbBrowse_withEmptyOrder() { - assertTrue(tmdb.moviedbBrowse("rating", "", "en").isEmpty()); - } - - @Test - public void testMoviedbBrowse_withNullOrder() { - assertTrue(tmdb.moviedbBrowse("rating", (String) null, "en").isEmpty()); - } - - @Test - public void testMoviedbBrowse_incorrectParameters() { - assertTrue(tmdb.moviedbBrowse("bla", "bla", "en").isEmpty()); - } - - @Test - public void testMoviedbBrowse_withNullParameters() { - assertTrue(tmdb.moviedbBrowse("rating", "asc", (Map) null, "en").isEmpty()); - } - - @Test - public void testMoviedbBrowse_withInvalidParameters() { - Map params = new HashMap(); - params.put("bla", "bla"); - params.put("yo", "yo"); - List movies = tmdb.moviedbBrowse("title", "desc", params, "en"); - - // even if parameters are incorrect we should get the result of - // the search with the default parameters (orderBy and order) so the - // list of movies is not empty - assertFalse(movies.isEmpty()); - } - //*** End moviedbBrowse - - @Test - public void testMoviedbImdbLookup() { - MovieDB movie = tmdb.moviedbImdbLookup("tt0137523", "en"); - assertEquals("Fight Club", movie.getTitle()); - assertEquals("550", movie.getId()); - assertEquals("tt0137523", movie.getImdb()); - assertEquals("138", movie.getRuntime()); - } - - @Test - public void testMoviedbImdbLookup_withEmptyId() { - MovieDB movie = tmdb.moviedbImdbLookup("", "en"); - assertTrue(movie.getTitle().equals(MovieDB.UNKNOWN)); - assertTrue(movie.getId().equals(MovieDB.UNKNOWN)); - assertTrue(movie.getImdb().equals(MovieDB.UNKNOWN)); - } - - @Test - public void testMoviedbImdbLookup_withNullId() { - MovieDB movie = tmdb.moviedbImdbLookup((String) null, "en"); - assertTrue(movie.getTitle().equals(MovieDB.UNKNOWN)); - assertTrue(movie.getId().equals(MovieDB.UNKNOWN)); - assertTrue(movie.getImdb().equals(MovieDB.UNKNOWN)); - } - - @Test - public void testMoviedbGetInfo() { - MovieDB movie = tmdb.moviedbGetInfo("187", "en"); - assertEquals("Sin City", movie.getTitle()); - assertEquals("187", movie.getId()); - assertEquals("tt0401792", movie.getImdb()); - assertEquals("124", movie.getRuntime()); - - } - - @Test - public void testMoviedbGetInfo_withExistingMovie() { - MovieDB movie = tmdb.moviedbGetInfo("200", new MovieDB(), "en"); - assertEquals("Star Trek: Insurrection", movie.getTitle()); - assertEquals("200", movie.getId()); - assertEquals("tt0120844", movie.getImdb()); - assertEquals("103", movie.getRuntime()); - } - - @Test - public void testMoviedbGetInfo_withNullMovie() { - MovieDB movie = tmdb.moviedbGetInfo("306", null, "en"); - assertEquals("Beverly Hills Cop III", movie.getTitle()); - assertEquals("306", movie.getId()); - assertEquals("tt0109254", movie.getImdb()); - assertEquals("104", movie.getRuntime()); - } - - @Test - public void testMoviedbGetInfo_withNullMovieAndEmptyId() { - MovieDB movie = tmdb.moviedbGetInfo("", null, "en"); - assertNull(movie); - } - - @Test - public void testMoviedbGetInfo_withNullMovieAndNullId() { - MovieDB movie = tmdb.moviedbGetInfo((String) null, null, "en"); - assertNull(movie); - } - - @Test - public void testMoviedbGetInfo_withInitializedMovie() { - MovieDB input = new MovieDB(); - String title = "The 300 Spartans"; - String id = "19972"; - input.setTitle(title); - MovieDB movie = tmdb.moviedbGetInfo(id, input, "en"); - assertEquals(title, movie.getTitle()); - assertEquals(id, movie.getId()); - } - - @Test - public void testMoviedbGetLatest() { - MovieDB movie = tmdb.moviedbGetLatest("en"); - assertFalse(movie.getTitle().equals(MovieDB.UNKNOWN)); - assertFalse(movie.getId().equals(MovieDB.UNKNOWN)); - assertFalse(movie.getImdb().equals(MovieDB.UNKNOWN)); - } - - @Test - public void testMoviedbGetVersion_String_String() { - MovieDB movie = tmdb.moviedbGetVersion("155", "en"); - assertEquals("The Dark Knight", movie.getTitle()); - assertEquals("155", movie.getId()); - assertEquals("tt0468569", movie.getImdb()); - } - - @Test - public void testMoviedbGetVersion_withWrongId() { - MovieDB movie = tmdb.moviedbGetVersion("0", "en"); - assertEquals(MovieDB.UNKNOWN, movie.getTitle()); - assertEquals(MovieDB.UNKNOWN, movie.getId()); - } - - @Test - public void testMoviedbGetVersion_withNullId() { - MovieDB movie = tmdb.moviedbGetVersion((String) null, "en"); - assertEquals(MovieDB.UNKNOWN, movie.getTitle()); - assertEquals(MovieDB.UNKNOWN, movie.getId()); - } - - @Test - public void testMoviedbGetVersion_withEmptyId() { - MovieDB movie = tmdb.moviedbGetVersion("", "en"); - assertEquals(MovieDB.UNKNOWN, movie.getTitle()); - assertEquals(MovieDB.UNKNOWN, movie.getId()); - } - - @Test - public void testMoviedbGetVersion_List_String() { - List ids = new ArrayList(); - ids.add("585"); - ids.add("11"); - List movies = tmdb.moviedbGetVersion(ids, "en"); - - assertEquals("Monsters, Inc.", movies.get(0).getTitle()); - assertEquals("585", movies.get(0).getId()); - assertEquals("tt0198781", movies.get(0).getImdb()); - - assertEquals("Star Wars: Episode IV - A New Hope", movies.get(1).getTitle()); - assertEquals("11", movies.get(1).getId()); - assertEquals("tt0076759", movies.get(1).getImdb()); - - } - - @Test - public void testMoviedbGetVersion_withEmptyList() { - List movies = tmdb.moviedbGetVersion(new ArrayList(), "en"); - assertTrue(movies.isEmpty()); - } - - @Test - public void testMoviedbGetVersion_withNullList() { - List movies = tmdb.moviedbGetVersion((List) null, "en"); - assertTrue(movies.isEmpty()); - } - - @Test - public void testMoviedbGetImages_String_String() { - } - - @Test - public void testMoviedbGetImages_3args() { - } - - @Test - public void testPersonSearch() { - ArrayList people = tmdb.personSearch("Tom Cruise", "en"); - - Person person = new Person(); - - for (Person foundPerson : people) { - if (foundPerson.getId().equals("500")) { - person = foundPerson; - break; - } - } - - assertEquals("Tom Cruise", person.getName()); - assertEquals("500", person.getId()); - } - - @Test - public void testPersonSearch_withEmptyName() { - ArrayList people = tmdb.personSearch("", "en"); - assertTrue(people.isEmpty()); - } - - @Test - public void testPersonSearch_withNullName() { - ArrayList people = tmdb.personSearch((String) null, "en"); - assertTrue(people.isEmpty()); - } - - @Test - public void testPersonGetInfo() { - ArrayList people = tmdb.personGetInfo("260", "en"); - - Person person = new Person(); - - for (Person foundPerson : people) { - if (foundPerson.getId().equals("260")) { - person = foundPerson; - break; - } - } - - assertEquals("Marco Pérez", person.getName()); - assertEquals("260", person.getId()); - } - - @Test - public void testPersonGetInfo_withEmptyId() { - ArrayList people = tmdb.personGetInfo("", "en"); - assertTrue(people.isEmpty()); - } - - @Test - public void testPersonGetInfo_withNullId() { - ArrayList people = tmdb.personGetInfo((String) null, "en"); - assertTrue(people.isEmpty()); - } - - @Test - public void testPersonGetLatest() { - Person person = tmdb.personGetLatest("en"); - assertFalse(person.getName().equals(MovieDB.UNKNOWN)); - } - - @Test - public void testPersonGetVersion() { - Person person = tmdb.personGetVersion("288", "en"); - assertEquals("Jon Seda", person.getName()); - assertEquals("288", person.getId()); - } - - @Test - public void testPersonGetVersion_withWrongId() { - Person person = tmdb.personGetVersion("0", "en"); - assertEquals(MovieDB.UNKNOWN, person.getName()); - assertEquals(MovieDB.UNKNOWN, person.getId()); - } - - @Test - public void testPersonGetVersion_withNullId() { - Person person = tmdb.personGetVersion((String) null, "en"); - assertEquals(MovieDB.UNKNOWN, person.getName()); - assertEquals(MovieDB.UNKNOWN, person.getId()); - } - - @Test - public void testPersonGetVersion_withEmptyId() { - Person person = tmdb.personGetVersion("", "en"); - assertEquals(MovieDB.UNKNOWN, person.getName()); - assertEquals(MovieDB.UNKNOWN, person.getId()); - } - - @Test - public void testPersonGetVersion_List_String() { - List ids = new ArrayList(); - ids.add("287"); - ids.add("5064"); - List people = tmdb.personGetVersion(ids, "en"); - - assertEquals("Brad Pitt", people.get(0).getName()); - assertEquals("287", people.get(0).getId()); - - assertEquals("Meryl Streep", people.get(1).getName()); - assertEquals("5064", people.get(1).getId()); - } - - @Test - public void testPersonGetVersion_withEmptyList() { - List people = tmdb.personGetVersion(new ArrayList(), "en"); - assertTrue(people.isEmpty()); - } - - @Test - public void testPersonGetVersion_withNullList() { - List people = tmdb.personGetVersion((List) null, "en"); - assertTrue(people.isEmpty()); - } - - @Test - public void testGetCategories() { - List genres = tmdb.getCategories("en"); - assertFalse(genres.isEmpty()); - assertTrue(genres.size() > 0); - } - - @Test - public void testFindMovie() { - } - - @Test - public void testCompareMovies() { - MovieDB movie = tmdb.moviedbGetInfo("27205", "en"); - assertTrue(TheMovieDb.compareMovies(movie, "Inception", "2010")); - } - - @Test - public void testCompareMovies_sameTitleAndDifferentYear() { - MovieDB movie = tmdb.moviedbGetInfo("27205", "en"); - assertFalse(TheMovieDb.compareMovies(movie, "Inception", "1999")); - } - - @Test - public void testCompareMovies_differentTitleAndSameYear() { - MovieDB movie = tmdb.moviedbGetInfo("27205", "en"); - assertFalse(TheMovieDb.compareMovies(movie, "xxx", "2010")); - } - - @Test - public void testCompareMovies_wrongArgument() { - assertFalse(TheMovieDb.compareMovies(null, "", "2010")); - } -}