implemented personGetVersion in TheMovieDb and parsePersonGetVersion in DOMParser
This commit is contained in:
@@ -31,6 +31,7 @@ import com.moviejukebox.themoviedb.tools.DOMHelper;
|
||||
import com.moviejukebox.themoviedb.tools.DOMParser;
|
||||
import com.moviejukebox.themoviedb.tools.LogFormatter;
|
||||
import com.moviejukebox.themoviedb.tools.WebBrowser;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* This is the main class for the API to connect to TheMovieDb.org The implementation is for v2.1
|
||||
@@ -375,27 +376,50 @@ public class TheMovieDb {
|
||||
* 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
|
||||
* @param language
|
||||
* @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;
|
||||
return new Person();
|
||||
}
|
||||
|
||||
List<Person> people = new ArrayList<Person>();
|
||||
people = this.personGetVersion(Arrays.asList(personID), language);
|
||||
|
||||
return people.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time along with the current version of a Person.
|
||||
* @param personIDs one or multiple Person TMDb ids
|
||||
* @param language the two digit language code. E.g. en=English
|
||||
* @return
|
||||
*/
|
||||
public List<Person> personGetVersion(List<String> personIDs, String language) {
|
||||
List<Person> people = new ArrayList<Person>();
|
||||
|
||||
String ids = "";
|
||||
for (int i = 0; i < personIDs.size(); i++) {
|
||||
if (i == 0) {
|
||||
ids += personIDs.get(i);
|
||||
continue;
|
||||
}
|
||||
ids += "," + personIDs.get(i);
|
||||
}
|
||||
|
||||
Document doc = null;
|
||||
|
||||
try {
|
||||
String searchUrl = buildSearchUrl(PERSON_GET_VERSION, personID, language);
|
||||
String searchUrl = buildSearchUrl(PERSON_GET_VERSION, ids, language);
|
||||
doc = DOMHelper.getEventDocFromUrl(searchUrl);
|
||||
person = DOMParser.parsePersonGetVersion(doc);
|
||||
people = DOMParser.parsePersonGetVersion(doc);
|
||||
} catch (Exception error) {
|
||||
logger.severe("PersonGetVersion error: " + error.getMessage());
|
||||
}
|
||||
|
||||
return person;
|
||||
return people;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,10 +20,12 @@ package com.moviejukebox.themoviedb.model;
|
||||
*/
|
||||
public class Category {
|
||||
|
||||
private String type;
|
||||
private String name;
|
||||
private String url;
|
||||
private String id;
|
||||
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;
|
||||
|
||||
@@ -20,9 +20,11 @@ package com.moviejukebox.themoviedb.model;
|
||||
*/
|
||||
public class Country {
|
||||
|
||||
private String url;
|
||||
private String name;
|
||||
private String code;
|
||||
private static final String UNKNOWN = MovieDB.UNKNOWN;
|
||||
|
||||
private String url = UNKNOWN;
|
||||
private String name = UNKNOWN;
|
||||
private String code = UNKNOWN;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
|
||||
@@ -14,12 +14,15 @@
|
||||
package com.moviejukebox.themoviedb.model;
|
||||
|
||||
public class Filmography {
|
||||
private String url;
|
||||
private String name;
|
||||
private String department;
|
||||
private String character;
|
||||
private String job;
|
||||
private String id;
|
||||
|
||||
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;
|
||||
|
||||
@@ -20,9 +20,11 @@ package com.moviejukebox.themoviedb.model;
|
||||
*/
|
||||
public class Studio {
|
||||
|
||||
private String name;
|
||||
private String url;
|
||||
private String id;
|
||||
private static final String UNKNOWN = MovieDB.UNKNOWN;
|
||||
|
||||
private String name = UNKNOWN;
|
||||
private String url = UNKNOWN;
|
||||
private String id = UNKNOWN;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
||||
@@ -151,11 +151,6 @@ public class DOMParser {
|
||||
return person;
|
||||
}
|
||||
|
||||
public static Person parsePersonGetVersion(Document doc) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -375,6 +370,34 @@ public class DOMParser {
|
||||
return movie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a DOM document and returns a list of Person
|
||||
* @param doc a DOM document
|
||||
* @return
|
||||
*/
|
||||
public static List<Person> parsePersonGetVersion(Document doc) {
|
||||
List<Person> people = new ArrayList<Person>();
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return people;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of valid genres within TMDb.
|
||||
* @param doc a DOM document
|
||||
|
||||
Reference in New Issue
Block a user