Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package com.savvasdalkitsis.jtmdb;
   
   import java.io.IOException;
   import java.io.Serializable;
   import java.net.URL;
   import java.net.URLEncoder;
  import java.util.Date;
  import java.util.List;
  import java.util.Set;
  
  
  import  org.json.JSONArray;
  import  org.json.JSONException;
  import  org.json.JSONObject;
  
This is the class that represents a Movie. It also provides static methods for searching for a movie and for getting a specific movie. Has two "flavors". The normal one and a reduced one. The reduced is returned when searching for movies and is missing some fields that are present when getting the info for a specific movie.

Author(s):
Savvas Dalkitsis
  
  public class Movie implements Serializable {
  
  	private static final long serialVersionUID = -6360810410868514356L;
The name of the movie.
  
  	private String name;
The original name for the movie.
  
  	private String originalName;
The alternative name for the movie.
  
  	private String alternativeName;
The ID of the movie.
  
  	private int ID;
The imdb ID of the movie.
  
  	private String imdbID;
The url of the movie.
  
  	private URL url;
The movie overview.
  
  	private String overview;
The rating of the movie.
  
  	private double rating;
The release date of the movie.
  
  	private Date releasedDate;
The images of the movie.
  
  	private MovieImages images;
Is the movie translated.
  
  	private boolean translated;
Is the movie for adult audiences only.
  
  	private boolean adult;
The language of the Movie.
  
  	private String language;
The type of the Movie.
  
  	private String movieType;
The json string that created this Movie object.
  
  	private String jsonOrigin;
The movie certification.
 
 	private String certification;
The version of the Movie.
 
 	private int version;
The votes for this Movie.
 
 	private int votes;
The date of the last modification.
 
 	private Date lastModifiedAt;

Denotes whether the movie object is reduced.
 
 	private boolean isReduced;
 
 	// Only in full profile.
 
The movie tagline. Not present in reduced form.
 
 	private String tagline;
The movie runtime. Not present in reduced form.
 
 	private int runtime;
The movie budget. Not present in reduced form.
 
 	private int budget;
The movie revenue. Not present in reduced form.
 
 	private long revenue;
The movie homepage. Not present in reduced form.
 
 	private URL homepage;
The movie trailer. Not present in reduced form.
 
 	private URL trailer;
The movie cast. Not present in reduced form.
 
 	private Set<CastInfocast = new LinkedHashSet<CastInfo>();
The movie Genres. Not present in reduced form.
 
 	private Set<Genregenres = new LinkedHashSet<Genre>();
The movie Studios. Not present in reduced form.
 
 	private Set<Studiostudios = new LinkedHashSet<Studio>();
The movie Countries. Not present in reduced form.
 
 	private Set<Countrycountries = new LinkedHashSet<Country>();

Construct a movie object from a JSON object.

Parameters:
jsonObject The JSON object describing the Movie.
 
 	public Movie(JSONObject jsonObject) {
 		Log.log("Creating Movie object from JSONObject".);
 		parseJSON(jsonObject);
 	}

Construct a movie object from a JSON array containing the JSON object describing the Movie.

Parameters:
jsonObjectInArray A JSON array containing the JSON object describing the Movie.
 
 	public Movie(JSONArray jsonObjectInArray) {
 		Log.log("Creating Movie object from JSONArray".);
 		parseJSON(jsonObjectInArray);
 	}

Returns the language of the Movie.

Returns:
The language of the Movie.
 
 	public String getLanguage() {
 		return ;
 	}

Sets the language of the Movie.

Parameters:
language The language of the Movie.
 
 	public void setLanguage(String language) {
 		this. = language;
 	}

Returns the type of the Movie.

Returns:
The type of the Movie.
 
 	public String getMovieType() {
 		return ;
 	}

Sets the type of the Movie.

Parameters:
movieType The type of the Movie.
 
 	public void setMovieType(String movieType) {
 		this. = movieType;
 	}

Returns true if the Movie is translated.

Returns:
True if the Movie is translated.
 
 	public boolean isTranslated() {
 		return ;
 	}

Sets whether the Movie is translated.

Parameters:
translated The translated flag of the Movie.
 
 	public void setTranslated(boolean translated) {
 		this. = translated;
 	}

Returns true if the Movie is adult only.

Returns:
True if the Movie is adult only.
 
 	public boolean isAdult() {
 		return ;
 	}

Sets whether the Movie is adult only.

Parameters:
adult The adult flag of the Movie.
 
 	public void setAdult(boolean adult) {
 		this. = adult;
 	}

If true, the Movie object has reduced fields set (see class description Movie).

Returns:
True if the Movie has reduced fields set.
 
 	public boolean isReduced() {
 		return ;
 	}

Sets whether the Movie contains reduced information (see class description Movie).

Parameters:
isReduced True if the Movie has reduced fields set.
 
 	public void setReduced(boolean isReduced) {
 		this. = isReduced;
 	}

The json string that created this Movie object.

Returns:
The json string that created this Movie object.
 
 	public String getJsonOrigin() {
 		return ;
 	}

The prettyprinted json string that created this Movie object.

Parameters:
indentFactor The number of spaces to add to each level of indentation.
Returns:
The json string that created this Movie object.
 
 	public String getJsonOrigin(int indentFactor) {
 		try {
 			return new JSONObject().toString(indentFactor);
 		} catch (JSONException e) {
 			Log.log(e.);
 			return null;
 		}
 	}

The name of the Movie.

Returns:
The name of the Movie.
 
 	public String getName() {
 		return ;
 	}

The Movie alternative name.

Returns:
The Movie alternative name.
 
 	public String getAlternativeName() {
 		return ;
 	}

The Movie original name.

Returns:
The Movie original name.
 
 	public String getOriginalName() {
 		return ;
 	}

The Movie tagline. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie tagline. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public String getTagline() {
 		return ;
 	}

The Movie certification.

Returns:
The Movie certification.
 
 	public String getCertification() {
 		return ;
 	}

The Movie Genres. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie Genres. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public Set<GenregetGenres() {
 		return ;
 	}

The Movie Studio. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie Studio. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public Set<StudiogetStudios() {
 		return ;
 	}

The Movie Countries. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie Countries. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public Set<CountrygetCountries() {
 		return ;
 	}

The Movie ID.

Returns:
The Movie ID.
 
 	public int getID() {
 		return ;
 	}

The Movie Imdb ID.

Returns:
The Movie Imdb ID.
 
 	public String getImdbID() {
 		return ;
 	}

The Movie Url.

Returns:
The Movie Url.
 
 	public URL getUrl() {
 		return ;
 	}

The overview of the Movie.

Returns:
The overview of the Movie.
 
 	public String getOverview() {
 		return ;
 	}

The Movie rating.

Returns:
The Movie rating.
 
 	public double getRating() {
 		return ;
 	}

The Movie release Date.

Returns:
The Movie release Date.
 
 	public Date getReleasedDate() {
 		return ;
 	}

The Date of the last modification.

Returns:
The Date of the last modification.
 
 		return ;
 	}

The version of the Movie.

Returns:
The version of the Movie.
 
 	public int getVersion() {
 		return ;
 	}

The votes of the Movie.

Returns:
The votes of the Movie.
 
 	public int getVotes() {
 		return ;
 	}

The Movie runtime. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie runtime. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public int getRuntime() {
 		return ;
 	}

The Movie budget. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie budget. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public int getBudget() {
 		return ;
 	}

The Movie revenue. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie revenue. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public long getRevenue() {
 		return ;
 	}

The Movie home page. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie home page. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public URL getHomepage() {
 		return ;
 	}

The Movie trailer. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie trailer. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public URL getTrailer() {
 		return ;
 	}

The Movie cast. Not present in reduced form (see class description Movie and method isReduced()).

Returns:
The Movie cast. Not present in reduced form (see class description Movie and method isReduced()).
 
 	public Set<CastInfogetCast() {
 		return ;
 	}

The Movie images.

Returns:
The Movie images.
 
 	public MovieImages getImages() {
 		return ;
 	}

Sets the name of the Movie.

Parameters:
name The name of the Movie.
 
 	public void setName(String name) {
 		this. = name;
 	}

Sets the alternative name of the Movie.

Parameters:
alternativeName The alternative name of the Movie.
 
 	public void setAlternativeName(String alternativeName) {
 		this. = alternativeName;
 	}

Sets the original name of the Movie.

Parameters:
originalName The original name of the Movie.
 
 	public void setOriginalName(String originalName) {
 		this. = originalName;
 	}

Sets the tagline of the Movie.

Parameters:
tagline The tagline of the Movie.
 
 	public void setTagline(String tagline) {
 		this. = tagline;
 	}

Sets the certification of the Movie.

Parameters:
certification The certification of the Movie.
 
 	public void setCertification(String certification) {
 		this. = certification;
 	}

Sets the ID of the Movie.

Parameters:
iD The ID of the Movie.
 
 	public void setID(int iD) {
 		 = iD;
 	}

Sets the Imdb ID of the Movie.

Parameters:
imdbID The Imdb ID of the Movie.
 
 	public void setImdbID(String imdbID) {
 		this. = imdbID;
 	}

Sets the Url of the Movie.

Parameters:
url The Url of the Movie.
 
 	public void setUrl(URL url) {
 		this. = url;
 	}

Sets the overview of the Movie.

Parameters:
overview The overview of the Movie.
 
 	public void setOverview(String overview) {
 		this. = overview;
 	}

Sets the rating of the Movie.

Parameters:
rating The rating of the Movie.
 
 	public void setRating(double rating) {
 		this. = rating;
 	}

Sets the release date of the Movie.

Parameters:
releasedDate The release date of the Movie.
 
 	public void setReleasedDate(Date releasedDate) {
 		this. = releasedDate;
 	}

Sets the date of the last modification.

Parameters:
lastModifiedAt The date of the last modification.
 
 	public void setLastModifiedAtDate(Date lastModifiedAt) {
 		this. = lastModifiedAt;
 	}

Sets the runtime of the Movie.

Parameters:
runtime The runtime of the Movie.
 
 	public void setRuntime(int runtime) {
 		this. = runtime;
 	}

Sets the budget of the Movie.

Parameters:
budget The budget of the Movie.
 
 	public void setBudget(int budget) {
 		this. = budget;
 	}

Sets the revenue of the Movie.

Parameters:
revenue The revenue of the Movie.
 
 	public void setRevenue(long revenue) {
 		this. = revenue;
 	}

Sets the home page of the Movie.

Parameters:
homepage The home page of the Movie.
 
 	public void setHomepage(URL homepage) {
 		this. = homepage;
 	}

Sets the trailer of the Movie.

Parameters:
trailer The trailer of the Movie.
 
 	public void setTrailer(URL trailer) {
 		this. = trailer;
 	}

Sets the cast of the Movie.

Parameters:
cast The cast of the Movie.
 
 	public void setCast(Set<CastInfocast) {
 		this..clear();
 		this..addAll(cast);
 	}

Sets the version of the Movie.

Parameters:
version The version of the Movie.
 
 	public void setVersion(int version) {
 		this. = version;
 	}

Sets the votes of the Movie.

Parameters:
votes The votes of the Movie.
 
 	public void setVotes(int votes) {
 		this. = votes;
 	}

Adds the cast to the Movie.

Parameters:
cast The cast of the Movie to add.
 
 	public void addCast(Set<CastInfocast) {
 		this..addAll(cast);
 	}

Set the genres of the Movie.

Parameters:
genres The genres of the Movie.
 
 	public void setGenres(Set<Genregenres) {
 		this..clear();
 		this..addAll(genres);
 	}

Adds the studios to the Movie.

Parameters:
studios The studios of the Movie to add.
 
 	public void addStudios(Set<Studiostudios) {
 		this..addAll(studios);
 	}

Set the studios of the Movie.

Parameters:
studios The studios of the Movie.
 
 	public void setStudios(Set<Studiostudios) {
 		this..clear();
 		this..addAll(studios);
 	}

Adds the countries to the Movie.

Parameters:
countries The countries of the Movie to add.
 
 	public void addCountries(Set<Countrycountries) {
 		this..addAll(countries);
 	}

Set the countries of the Movie.

Parameters:
countries The countries of the Movie.
 
 	public void setCountries(Set<Countrycountries) {
 		this..clear();
 		this..addAll(countries);
 	}

Adds the genres to the Movie.

Parameters:
genres The genres of the Movie to add.
 
 	public void addGenres(Set<Genregenres) {
 		this..addAll(genres);
 	}

Sets the images of the Movie.

Parameters:
images The images of the Movie.
 
 	public void setImages(MovieImages images) {
 		this. = images;
 	}

Returns a list of movies in the box office (full flavors). Returns a list of Movie objects with the full form (see class description Movie and method isReduced()). Will return null if a valid API key was not supplied to the GeneralSettings

This method relies on parsing the home page HTML of themoviedb.org. So it is not 100% stable as the syntax of the web page may change.

Returns:
A list of Movie objects in the box office with the full form (see class description Movie and method isReduced() ).Will return null if a valid API key was not supplied to the GeneralSettings
Throws:
JSONException
IOException
 
 	public static List<MovieboxOffice() throws IOException, JSONException {
 		Log.log("Requesting the box office from the site.".);
 		Set<Integerids = parseHTML(0);
 
 		List<Moviemovies = new LinkedList<Movie>();
 		if (!ids.isEmpty()) {
 			for (int id : ids.toArray(new Integer[0])) {
 				movies.add(getInfo(id));
 			}
 		}
 		return movies;
 	}

Returns a set of the IDs of the movies in the box office. Will return null if a valid API key was not supplied to the GeneralSettings

This method relies on parsing the home page HTML of themoviedb.org. So it is not 100% stable as the syntax of the web page may change.

Returns:
A set of the IDs of the movies in the box office. Will return null if a valid API key was not supplied to the GeneralSettings
Throws:
IOException
JSONException
 
 	public static Set<IntegerboxOfficeIDs() throws IOException {
 		Log.log("Requesting the box office ids from the site.",
 		return parseHTML(0);
 	}

Returns a list of the most popular movies (full flavors). Returns a list of Movie objects with the full form (see class description Movie and method isReduced()). Will return null if a valid API key was not supplied to the GeneralSettings

This method relies on parsing the home page HTML of themoviedb.org. So it is not 100% stable as the syntax of the web page may change.

Returns:
A list of the most popular Movie objects with the full form (see class description Movie and method isReduced() ).Will return null if a valid API key was not supplied to the GeneralSettings
Throws:
JSONException
IOException
 
 	public static List<MoviemostPopular() throws IOException, JSONException {
 		Log.log("Requesting the most popular movies from the site.",
 		Set<Integerids = parseHTML(1);
 
 		List<Moviemovies = new LinkedList<Movie>();
 		if (!ids.isEmpty()) {
 			for (int id : ids.toArray(new Integer[0])) {
 				movies.add(getInfo(id));
 			}
 		}
 		return movies;
 	}

Returns a set of the IDs of the most popular movies. Will return null if a valid API key was not supplied to the GeneralSettings

This method relies on parsing the home page HTML of themoviedb.org. So it is not 100% stable as the syntax of the web page may change.

Returns:
A set of the IDs of the most popular movies. Will return null if a valid API key was not supplied to the GeneralSettings
Throws:
IOException
JSONException
 
 	public static Set<IntegermostPopularIDs() throws IOException {
 		Log.log("Requesting the most popular movies' ids from the site.",
 		return parseHTML(1);
 	}

This method gets the HTML of the home page of themoviedatabase.org and parses it for a list of movies in the box office or in the most popular list.

Parameters:
part The part of the HTML to parse. 0 is for the box office and 1 is for the most popular.
Returns:
A list of movies.
Throws:
IOException
 
 	private static Set<IntegerparseHTML(int partthrows IOException {
 		Log.log("Parsing the site homepage.".);
 		Set<Integerids = new LinkedHashSet<Integer>();
 		try {
 			String xmlString = Utilities.readUrlResponse(call);
 
 			String[] parts = xmlString.toString().split("first most-popular");
 
 			Pattern p = Pattern.compile("/movie/(\\d+)");
 			Matcher match = p.matcher(parts[part]);
 			while (match.find()) {
 				try {
 					int id = Integer.parseInt(match.group(1));
 					ids.add(id);
 				} catch (NumberFormatException e) {
 					Log.log("Could not parse integer for Movie ID",
 					Log.log(e.);
 				}
 			}
 		} catch (IOException e) {
 			Log.log(e.);
 			throw e;
 		}
 		return ids;
 	}

Searches for movies and returns full flavors. The string supplied can contain spaces. Returns a list of Movie objects with the full form (see class description Movie and method isReduced()). Will return null if a valid API key was not supplied to the GeneralSettings

Parameters:
name The name of the movie to search for.
Returns:
A list of Movie objects with the full form (see class description Movie and method isReduced()).Will return null if a valid API key was not supplied to the GeneralSettings
Throws:
IOException
JSONException
 
 	public static List<MoviedeepSearch(String namethrows IOException,
 			JSONException {
 		Log.log("Performing a deep Movie search for \"" + name + "\"",
 		try {
 			name = URLEncoder.encode(name"UTF-8");
 		} catch (UnsupportedEncodingException e) {
 			name = name.replaceAll(" ""%20");
 		}
 		if (GeneralSettings.getApiKey() != null
 				&& !GeneralSettings.getApiKey().equals("")) {
 			if (name != null && !name.equals("")) {
 				try {
 							+ GeneralSettings.getAPILocaleFormatted() + "/"
							+ GeneralSettings.getApiKey() + "/" + name);
					String jsonString = Utilities.readUrlResponse(call).trim();
					List<Movieresults = new LinkedList<Movie>();
					if ((jsonString.startsWith("[") || jsonString
							&& !jsonString.equals("[\"Nothing found.\"]")) {
						JSONArray jsonArray = new JSONArray(jsonString
						for (int i = 0; i < jsonArray.length(); i++) {
							results.add(getInfo(jsonArray.getJSONObject(i)
									.getInt("id")));
else {
						Log.log("Search for \"" + name
"\" returned no results".);
					return results;
catch (IOException e) {
					throw e;
catch (JSONException e) {
					throw e;
else {
				Log.log("Cannot search for a null or empty string",
else {
			Log.log("Error with the API key".);
		return null;
	}

Searches for movies. The string supplied can contain spaces. Returns a list of Movie objects with the reduced form (see class description Movie and method isReduced()). Will return null if a valid API key was not supplied to the GeneralSettings

Parameters:
name The name of the movie to search for.
Returns:
A list of Movie objects with the reduced form (see class description Movie and method isReduced()).Will return null if a valid API key was not supplied to the GeneralSettings
Throws:
IOException
JSONException
	public static List<Moviesearch(String namethrows IOException,
			JSONException {
		Log.log("Performing a Movie search for \"" + name + "\"",
		try {
			name = URLEncoder.encode(name"UTF-8");
			name = name.replaceAll(" ""%20");
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			if (name != null && !name.equals("")) {
				try {
							+ GeneralSettings.getAPILocaleFormatted() + "/"
							+ GeneralSettings.getApiKey() + "/" + name);
					String jsonString = Utilities.readUrlResponse(call).trim();
					List<Movieresults = new LinkedList<Movie>();
					if ((jsonString.startsWith("[") || jsonString
							&& !jsonString.equals("[\"Nothing found.\"]")) {
						JSONArray jsonArray = new JSONArray(jsonString
						for (int i = 0; i < jsonArray.length(); i++) {
							results.add(new Movie(jsonArray.getJSONObject(i)));
else {
						Log.log("Search for \"" + name
"\" returned no results".);
					return results;
catch (IOException e) {
					throw e;
catch (JSONException e) {
					throw e;
else {
				Log.log("Cannot search for a null or empty string",
else {
			Log.log("Error with the API key".);
		return null;
	public static List<MovieimdbLookup(String imdbIdthrows IOException,
			JSONException {
		Log.log("Performing a Movie search by IMDB-ID \"" + imdbId + "\"",
		try {
			imdbId = URLEncoder.encode(imdbId"UTF-8");
			imdbId = imdbId.replaceAll(" ""%20");
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			if (imdbId != null && !imdbId.equals("")) {
				try {
							+ GeneralSettings.getAPILocaleFormatted() + "/"
							+ GeneralSettings.getApiKey() + "/" + imdbId);
					String jsonString = Utilities.readUrlResponse(call).trim();
					List<Movieresults = new LinkedList<Movie>();
					if ((jsonString.startsWith("[") || jsonString
							&& !jsonString.equals("[\"Nothing found.\"]")) {
						JSONArray jsonArray = new JSONArray(jsonString
						for (int i = 0; i < jsonArray.length(); i++) {
							results.add(new Movie(jsonArray.getJSONObject(i)));
else {
						Log.log("Search for \"" + imdbId
"\" returned no results".);
					return results;
catch (IOException e) {
					throw e;
catch (JSONException e) {
					throw e;
else {
				Log.log("Cannot search for a null or empty string",
else {
			Log.log("Error with the API key".);
		return null;
		}

Gets the info for a specific Movie (by ID). Returns a Movie object with the normal form (see class description Movie and method isReduced()). Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.

Parameters:
ID The ID of the Movie.
Returns:
A Movie object with the normal form (see class description Movie and method isReduced()). Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.
Throws:
IOException
JSONException
	public static Movie getInfo(int IDthrows IOException, JSONException {
		Log.log("Getting info for Movie with id " + ID.);
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			try {
						+ GeneralSettings.getAPILocaleFormatted() + "/"
						+ GeneralSettings.getApiKey() + "/" + ID);
				String jsonString = Utilities.readUrlResponse(call).trim();
				if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
						&& !jsonString.equals("[\"Nothing found.\"]")) {
					JSONArray jsonArray = new JSONArray(jsonString.toString());
					return new Movie(jsonArray);
else {
					Log.log("Getting info for Movie with id " + ID
" returned no results".);
catch (IOException e) {
				throw e;
catch (JSONException e) {
				throw e;
else {
			Log.log("Error with the API key".);
		return null;
	}

Gets the images for a specific Movie (by ID). Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.

Parameters:
ID The ID of the Movie.
Returns:
The images for a specific Movie (by ID). Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.
Throws:
IOException
JSONException
	public static MovieImages getImages(int IDthrows IOException,
			JSONException {
		Log.log("Getting images for Movie with ID " + ID.);
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			try {
						+ GeneralSettings.getAPILocaleFormatted() + "/"
						+ GeneralSettings.getApiKey() + "/" + ID);
				String jsonString = Utilities.readUrlResponse(call).trim();
				if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
						&& !jsonString.equals("[\"Nothing found.\"]")) {
					JSONObject json = new JSONArray(jsonString.toString())
							.getJSONObject(0);
					String movieName = json.getString("name");
					int movieID = json.getInt("id");
					JSONArray postersArray = json.getJSONArray("posters");
					MovieImages images = new MovieImages(movieIDmovieName);
					for (int i = 0; i < postersArray.length(); i++) {
						JSONObject image = postersArray.getJSONObject(i)
								.getJSONObject("image");
						URL posterURL = null;
						try {
							posterURL = new URL(image.getString("url"));
catch (MalformedURLException e) {
						int posterW = -1;
						int posterH = -1;
						try {
							posterW = image.getInt("width");
catch (JSONException e) {
						try {
							posterH = image.getInt("height");
catch (JSONException e) {
						Dimension posterD = null;
						if (posterW > 0 && posterH > 0) {
							posterD = new Dimension(posterWposterH);
						String posterID = image.getString("id");
						String posterSize = image.getString("size");
						if (posterSize.equalsIgnoreCase("thumb")) {
							posterSizeEnum = ..;
else if (posterSize.equalsIgnoreCase("mid")) {
							posterSizeEnum = ..;
else if (posterSize.equalsIgnoreCase("cover")) {
							posterSizeEnum = ..;
						MoviePoster poster = null;
						for (MoviePoster p : images.posters) {
							if (p.getID().equals(posterID)) {
								poster = p;
						if (poster == null) {
							poster = new MoviePoster(posterID);
							images.posters.add(poster);
						poster.setImage(posterSizeEnum,
								new Pair<DimensionURL>(posterDposterURL));
					postersArray = json.getJSONArray("backdrops");
					for (int i = 0; i < postersArray.length(); i++) {
						JSONObject image = postersArray.getJSONObject(i)
								.getJSONObject("image");
						URL posterURL = null;
						try {
							posterURL = new URL(image.getString("url"));
catch (MalformedURLException e) {
						int posterW = -1;
						int posterH = -1;
						try {
							posterW = image.getInt("width");
catch (JSONException e) {
						try {
							posterH = image.getInt("height");
catch (JSONException e) {
						Dimension posterD = null;
						if (posterW > 0 && posterH > 0) {
							posterD = new Dimension(posterWposterH);
						String posterID = image.getString("id");
						String posterSize = image.getString("size");
						if (posterSize.equalsIgnoreCase("thumb")) {
							posterSizeEnum = ..;
else if (posterSize.equalsIgnoreCase("poster")) {
							posterSizeEnum = ..;
						MovieBackdrop backdrop = null;
						for (MovieBackdrop p : images.backdrops) {
							if (p.getID().equals(posterID)) {
								backdrop = p;
						if (backdrop == null) {
							backdrop = new MovieBackdrop(posterID);
							images.backdrops.add(backdrop);
						backdrop.setImage(posterSizeEnum,
								new Pair<DimensionURL>(posterDposterURL));
					return images;
else {
					Log.log("Search for images of Movie with id " + ID
" returned no results".);
catch (IOException e) {
				throw e;
catch (JSONException e) {
				throw e;
else {
			Log.log("Error with the API key".);
		return null;
	}

Gets the version information for a Movie by ID. Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.

Parameters:
ID The ID of the Movie to get the version for.
Returns:
Version information of a Movie by ID.
Throws:
IOException
JSONException
	public static MovieVersionInfo getVersion(int IDthrows IOException,
			JSONException {
		Log.log("Getting version for Movie with id " + ID.);
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			try {
						+ GeneralSettings.getAPILocaleFormatted() + "/"
						+ GeneralSettings.getApiKey() + "/" + ID);
				String jsonString = Utilities.readUrlResponse(call).trim();
				if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
						&& !jsonString.equals("[\"Nothing found.\"]")) {
					JSONArray jsonArray = new JSONArray(jsonString.toString());
					JSONObject jsonObject = jsonArray.getJSONObject(0);
					String name = jsonObject.getString("name");
					int movieID = jsonObject.getInt("id");
					int version = jsonObject.getInt("version");
					Date lastModified = null;
					try {
						lastModified = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss").parse(jsonObject
								.getString("last_modified_at"));
catch (ParseException e) {
					String imdbID = jsonObject.getString("imdb_id");
					return new MovieVersionInfo(namemovieIDversion,
							lastModifiedimdbID);
else {
					Log.log("Getting version for Movie with id " + ID
" returned no results".);
catch (IOException e) {
				throw e;
catch (JSONException e) {
				throw e;
else {
			Log.log("Error with the API key".);
		return null;
	}

Gets the version information for a list of Movies by ID. Will return null if a valid API key was not supplied to the GeneralSettings and will skip any IDs that did not correspond to a Movie.

Parameters:
IDs The list of Movie IDs to get version information for.
Returns:
Version information of a list of Movies by ID.
Throws:
IOException
JSONException
	public static List<MovieVersionInfogetVersion(int... IDs)
			throws IOException, JSONException {
		if (IDs == null || IDs.length == 0) {
			Log.log("Provided empty or null list of IDs for Movie.getVersion",
			return null;
		StringBuffer listIDs = new StringBuffer();
		for (int ID : IDs) {
			listIDs.append("," + ID);
		listIDs.delete(0, 1);
		Log.log("Getting version for Movies with ids " + listIDs.toString(),
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			try {
						+ GeneralSettings.getAPILocaleFormatted() + "/"
						+ GeneralSettings.getApiKey() + "/" + listIDs);
				String jsonString = Utilities.readUrlResponse(call).trim();
				if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
						&& !jsonString.equals("[\"Nothing found.\"]")) {
					JSONArray jsonArray = new JSONArray(jsonString.toString());
					for (int i = 0; i < jsonArray.length(); i++) {
						JSONObject jsonObject = jsonArray.getJSONObject(i);
						String name = jsonObject.getString("name");
						int movieID = jsonObject.getInt("id");
						int version = jsonObject.getInt("version");
						Date lastModified = null;
						try {
							lastModified = new SimpleDateFormat(
									"yyyy-MM-dd HH:mm:ss").parse(jsonObject
									.getString("last_modified_at"));
catch (ParseException e) {
						String imdbID = jsonObject.getString("imdb_id");
						versionInfo.add(new MovieVersionInfo(namemovieID,
								versionlastModifiedimdbID));
else {
					Log.log("Getting version for list of Movies with ids "
listIDs + " returned no results",
				return versionInfo;
catch (IOException e) {
				throw e;
catch (JSONException e) {
				throw e;
else {
			Log.log("Error with the API key".);
		return null;
	}

Gets the version information for the last Movie in the database. Will return null if a valid API key was not supplied to the GeneralSettings.

Returns:
Version information for the last Movie in the database.
Throws:
IOException
JSONException
	public static MovieVersionInfo getLatest() throws IOException,
			JSONException {
		Log.log("Getting latest Movie".);
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			try {
						+ GeneralSettings.getAPILocaleFormatted() + "/"
						+ GeneralSettings.getApiKey());
				String jsonString = Utilities.readUrlResponse(call).trim();
				if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
						&& !jsonString.equals("[\"Nothing found.\"]")) {
					JSONArray jsonArray = new JSONArray(jsonString.toString());
					JSONObject jsonObject = jsonArray.getJSONObject(0);
					String name = jsonObject.getString("name");
					int movieID = jsonObject.getInt("id");
					int version = jsonObject.getInt("version");
					Date lastModified = null;
					try {
						lastModified = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss").parse(jsonObject
								.getString("last_modified_at"));
catch (ParseException e) {
					String imdbID = jsonObject.getString("imdb_id");
					return new MovieVersionInfo(namemovieIDversion,
							lastModifiedimdbID);
else {
					Log.log("Getting latest Movie entry returned no results",
catch (IOException e) {
				throw e;
catch (JSONException e) {
				throw e;
else {
			Log.log("Error with the API key".);
		return null;
	}

Gets the translations for a specific Movie (by ID). Returns a Pair of objects. The first object is the MovieVersionInfo of the Movie and the second is a list of Translation objects. Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.

Parameters:
ID The ID of the Movie.
Returns:
A Pair of objects. The first object is the MovieVersionInfo of the Movie and the second is a list of Translation objects. Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.
Throws:
IOException
JSONException
			int IDthrows IOException, JSONException {
		return getTranslations("" + ID);
	}

Gets the translations for a specific Movie (by ID). Returns a Pair of objects. The first object is the MovieVersionInfo of the Movie and the second is a list of Translation objects. Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.

Parameters:
imdbID The Imdb ID of the Movie.
Returns:
A Pair of objects. The first object is the MovieVersionInfo of the Movie and the second is a list of Translation objects. Will return null if a valid API key was not supplied to the GeneralSettings or if the supplied ID did not correspond to a Movie.
Throws:
IOException
JSONException
			String imdbIDthrows IOException, JSONException {
		Log.log("Getting translations for Movie with id " + imdbID,
		if (GeneralSettings.getApiKey() != null
				&& !GeneralSettings.getApiKey().equals("")) {
			try {
						+ GeneralSettings.getAPILocaleFormatted() + "/"
						+ GeneralSettings.getApiKey() + "/" + imdbID);
				String jsonString = Utilities.readUrlResponse(call).trim();
				if ((jsonString.startsWith("[") || jsonString.startsWith("{"))
						&& !jsonString.equals("[\"Nothing found.\"]")) {
					JSONArray jsonArray = new JSONArray(jsonString.toString());
					JSONObject jsonObject = jsonArray.getJSONObject(0);
					String name = jsonObject.getString("name");
					int movieID = jsonObject.getInt("id");
					int version = jsonObject.getInt("version");
					Date lastModified = null;
					try {
						lastModified = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss").parse(jsonObject
								.getString("last_modified_at"));
catch (ParseException e) {
					String imdbIDTmp = jsonObject.getString("imdb_id");
					MovieVersionInfo versionInfo = new MovieVersionInfo(name,
							movieIDversionlastModifiedimdbIDTmp);
					JSONArray translations = jsonObject
							.getJSONArray("translations");
					List<TranslationtranslationsList = new LinkedList<Translation>();
					for (int i = 0; i < translations.length(); i++) {
						JSONObject translation = translations.getJSONObject(i);
						String englishName = translation
								.getString("english_name");
						String nativeName = translation
								.getString("native_name");
						String iso639_1 = translation.getString("iso_639_1");
						translationsList.add(new Translation(englishName,
								nativeNameiso639_1));
							versionInfotranslationsList);
else {
					Log.log("Getting translations for Movie with id " + imdbID
" returned no results".);
catch (IOException e) {
				throw e;
catch (JSONException e) {
				throw e;
else {
			Log.log("Error with the API key".);
		return null;
	}

Parses a JSON object wrapped in a JSON array and sets the Movie fields.

Parameters:
jsonArray The JSON array containing the JSON object that describes the Movie.
	public void parseJSON(JSONArray jsonArray) {
		try {
			parseJSON(jsonArray.getJSONObject(0));
catch (JSONException e) {
	}

Parses a JSON object and sets the Movie fields.

Parameters:
jsonObject The JSON object that describes the Movie.
	public boolean parseJSON(JSONObject jsonObject) {
		try {
			 = jsonObject.toString();
			setLanguage(jsonObject.getString("language"));
			setMovieType(jsonObject.getString("movie_type"));
			setTranslated(jsonObject.getBoolean("translated"));
			setAdult(jsonObject.getBoolean("adult"));
			setRating(jsonObject.getDouble("rating"));
			setAlternativeName(jsonObject.getString("alternative_name"));
			setOriginalName(jsonObject.getString("original_name"));
			setName(jsonObject.getString("name"));
			setOverview(jsonObject.getString("overview"));
			setID(jsonObject.getInt("id"));
			try {
				setUrl(new URL(jsonObject.getString("url")));
catch (MalformedURLException e) {
				setUrl(null);
			JSONArray postersArray = jsonObject.getJSONArray("posters");
			for (int i = 0; i < postersArray.length(); i++) {
				JSONObject image = postersArray.getJSONObject(i).getJSONObject(
						"image");
				URL posterURL = null;
				try {
					posterURL = new URL(image.getString("url"));
catch (MalformedURLException e) {
				int posterW = -1;
				int posterH = -1;
				try {
					posterW = image.getInt("width");
catch (JSONException e) {
				try {
					posterH = image.getInt("height");
catch (JSONException e) {
				Dimension posterD = null;
				if (posterW > 0 && posterH > 0) {
					posterD = new Dimension(posterWposterH);
				String posterID = image.getString("id");
				String posterSize = image.getString("size");
				if (posterSize.equalsIgnoreCase("thumb")) {
					posterSizeEnum = ..;
else if (posterSize.equalsIgnoreCase("mid")) {
					posterSizeEnum = ..;
else if (posterSize.equalsIgnoreCase("cover")) {
					posterSizeEnum = ..;