added Person.getLatest
This commit is contained in:
@@ -48,17 +48,18 @@ public class TheMovieDb {
|
||||
private static ConsoleHandler tmdbConsoleHandler = new ConsoleHandler();
|
||||
private static final String apiSite = "http://api.themoviedb.org/2.1/";
|
||||
private static final String defaultLanguage = "en-US";
|
||||
private static final String MOVIE_SEARCH = "Movie.search";
|
||||
private static final String GENRES_GET_LIST = "Genres.getList";
|
||||
private static final String MOVIE_BROWSE = "Movie.browse";
|
||||
private static final String MOVIE_IMDB_LOOKUP = "Movie.imdbLookup";
|
||||
private static final String MOVIE_GET_INFO = "Movie.getInfo";
|
||||
private static final String MOVIE_GET_IMAGES = "Movie.getImages";
|
||||
private static final String MOVIE_GET_LATEST = "Movie.getLatest";
|
||||
private static final String MOVIE_GET_VERSION = "Movie.getVersion";
|
||||
private static final String PERSON_GET_VERSION = "Person.getVersion";
|
||||
private static final String MOVIE_IMDB_LOOKUP = "Movie.imdbLookup";
|
||||
private static final String MOVIE_SEARCH = "Movie.search";
|
||||
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";
|
||||
private static final String GENRES_GET_LIST = "Genres.getList";
|
||||
|
||||
public TheMovieDb(String apiKey) {
|
||||
setLogger(Logger.getLogger("TheMovieDB"));
|
||||
@@ -275,7 +276,11 @@ public class TheMovieDb {
|
||||
* @return
|
||||
*/
|
||||
public MovieDB moviedbGetVersion(String movieId, String language) {
|
||||
return this.moviedbGetVersion(Arrays.asList(movieId), language).get(0);
|
||||
List<MovieDB> movies = this.moviedbGetVersion(Arrays.asList(movieId), language);
|
||||
if (movies.isEmpty()) {
|
||||
return new MovieDB();
|
||||
}
|
||||
return movies.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +299,7 @@ public class TheMovieDb {
|
||||
public List<MovieDB> moviedbGetVersion(List<String> movieIds, String language) {
|
||||
List<MovieDB> movies = new ArrayList<MovieDB>();
|
||||
|
||||
if (movieIds.isEmpty()) {
|
||||
if ((movieIds == null) || movieIds.isEmpty()) {
|
||||
logger.warning("There are no Movie ids!");
|
||||
return movies;
|
||||
}
|
||||
@@ -371,6 +376,17 @@ public class TheMovieDb {
|
||||
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
|
||||
@@ -382,11 +398,17 @@ public class TheMovieDb {
|
||||
* @return
|
||||
*/
|
||||
public Person personGetVersion(String personID, String language) {
|
||||
Person person = new Person();
|
||||
if (!isValidString(personID)) {
|
||||
return new Person();
|
||||
return person;
|
||||
}
|
||||
|
||||
return this.personGetVersion(Arrays.asList(personID), language).get(0);
|
||||
List<Person> people = this.personGetVersion(Arrays.asList(personID), language);
|
||||
if (people.isEmpty()) {
|
||||
return person;
|
||||
}
|
||||
|
||||
return people.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,7 +421,7 @@ public class TheMovieDb {
|
||||
* @return
|
||||
*/
|
||||
public List<Person> personGetVersion(List<String> personIDs, String language) {
|
||||
if (personIDs.isEmpty()) {
|
||||
if ((personIDs == null) || (personIDs.isEmpty())) {
|
||||
logger.warning("There are no Person ids!");
|
||||
return new ArrayList<Person>();
|
||||
}
|
||||
|
||||
@@ -439,12 +439,7 @@ public class MovieDbParser {
|
||||
Node node = movies.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element element = (Element) node;
|
||||
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"));
|
||||
people.add(person);
|
||||
people.add(MovieDbParser.parseSimplePerson(element));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,6 +557,50 @@ public class MovieDbParser {
|
||||
return movies;
|
||||
}
|
||||
|
||||
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) {
|
||||
person = new Person();
|
||||
|
||||
Element element = (Element) node;
|
||||
person = MovieDbParser.parseSimplePerson(element);
|
||||
}
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a "simple" Movie in the form:
|
||||
* <movie>
|
||||
* <name>Inception</name>
|
||||
* <id>36462</id>
|
||||
* <imdb_id>tt1375666</imdb_id>
|
||||
* <version>11</version>
|
||||
* <last_modified_at>2010-07-26 17:06:18</last_modified_at>
|
||||
* </movie>
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
private static MovieDB parseSimpleMovie(Element element) {
|
||||
MovieDB movie = new MovieDB();
|
||||
movie.setTitle(DOMHelper.getValueFromElement(element, "name"));
|
||||
@@ -571,4 +610,24 @@ public class MovieDbParser {
|
||||
movie.setLastModifiedAt(DOMHelper.getValueFromElement(element, "last_modified_at"));
|
||||
return movie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a "simple" Person in the form:
|
||||
* <person>
|
||||
* <name>John Joseph</name>
|
||||
* <id>111830</id>
|
||||
* <version>3</version>
|
||||
* <last_modified_at>2010-07-19 10:59:13</last_modified_at>
|
||||
* </person>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user