Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 67b4efe77c | |||
| 917c3bb029 | |||
| 68cbc9b54b | |||
| e2f1008d01 | |||
| 51b202df2d | |||
| d84582d336 | |||
| 121838598d | |||
| cd09cf8dfe | |||
| 3a53039b3e | |||
| f7b37a1eb9 | |||
| 52c19f98d4 | |||
| 796459b816 |
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<groupId>com.omertron</groupId>
|
<groupId>com.omertron</groupId>
|
||||||
<artifactId>themoviedbapi</artifactId>
|
<artifactId>themoviedbapi</artifactId>
|
||||||
<version>3.8</version>
|
<version>3.9</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>API-The MovieDB</name>
|
<name>API-The MovieDB</name>
|
||||||
@@ -71,6 +71,8 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<distribution.format>zip</distribution.format>
|
<distribution.format>zip</distribution.format>
|
||||||
|
<version.jackson>2.3.0</version.jackson>
|
||||||
|
<version.slf4j>1.7.5</version.slf4j>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -85,35 +87,35 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
<version>2.2.3</version>
|
<version>${version.jackson}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
<version>2.2.3</version>
|
<version>${version.jackson}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.2.3</version>
|
<version>${version.jackson}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--LOGGING-->
|
<!--LOGGING-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.5</version>
|
<version>${version.slf4j}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-jdk14</artifactId>
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
<version>1.7.5</version>
|
<version>${version.slf4j}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--COMMON HTTP TOOLS-->
|
<!--COMMON HTTP TOOLS-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.yamj</groupId>
|
<groupId>org.yamj</groupId>
|
||||||
<artifactId>api-common</artifactId>
|
<artifactId>api-common</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@@ -174,7 +176,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.14.1</version>
|
<version>2.16</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- To skip tests by default -->
|
<!-- To skip tests by default -->
|
||||||
<skipTests>${skipTests}</skipTests>
|
<skipTests>${skipTests}</skipTests>
|
||||||
@@ -233,7 +235,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>versions-maven-plugin</artifactId>
|
<artifactId>versions-maven-plugin</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -277,7 +279,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>2.7</version>
|
<version>2.8.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -289,7 +291,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
<version>2.4</version>
|
<version>2.5.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -19,6 +19,79 @@
|
|||||||
*/
|
*/
|
||||||
package com.omertron.themoviedbapi;
|
package com.omertron.themoviedbapi;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType;
|
||||||
|
import com.omertron.themoviedbapi.model.Account;
|
||||||
|
import com.omertron.themoviedbapi.model.AlternativeTitle;
|
||||||
|
import com.omertron.themoviedbapi.model.Artwork;
|
||||||
|
import com.omertron.themoviedbapi.model.ArtworkType;
|
||||||
|
import com.omertron.themoviedbapi.model.ChangeKeyItem;
|
||||||
|
import com.omertron.themoviedbapi.model.ChangedItem;
|
||||||
|
import com.omertron.themoviedbapi.model.ChangedMovie;
|
||||||
|
import com.omertron.themoviedbapi.model.Collection;
|
||||||
|
import com.omertron.themoviedbapi.model.CollectionInfo;
|
||||||
|
import com.omertron.themoviedbapi.model.Company;
|
||||||
|
import com.omertron.themoviedbapi.model.Discover;
|
||||||
|
import com.omertron.themoviedbapi.model.Genre;
|
||||||
|
import com.omertron.themoviedbapi.model.JobDepartment;
|
||||||
|
import com.omertron.themoviedbapi.model.Keyword;
|
||||||
|
import com.omertron.themoviedbapi.model.KeywordMovie;
|
||||||
|
import com.omertron.themoviedbapi.model.ListItemStatus;
|
||||||
|
import com.omertron.themoviedbapi.model.MovieDb;
|
||||||
|
import com.omertron.themoviedbapi.model.MovieDbList;
|
||||||
|
import com.omertron.themoviedbapi.model.MovieDbListStatus;
|
||||||
|
import com.omertron.themoviedbapi.model.MovieList;
|
||||||
|
import com.omertron.themoviedbapi.model.Person;
|
||||||
|
import com.omertron.themoviedbapi.model.PersonCredit;
|
||||||
|
import com.omertron.themoviedbapi.model.ReleaseInfo;
|
||||||
|
import com.omertron.themoviedbapi.model.Reviews;
|
||||||
|
import com.omertron.themoviedbapi.model.StatusCode;
|
||||||
|
import com.omertron.themoviedbapi.model.TmdbConfiguration;
|
||||||
|
import com.omertron.themoviedbapi.model.TokenAuthorisation;
|
||||||
|
import com.omertron.themoviedbapi.model.TokenSession;
|
||||||
|
import com.omertron.themoviedbapi.model.Trailer;
|
||||||
|
import com.omertron.themoviedbapi.model.Translation;
|
||||||
|
import com.omertron.themoviedbapi.results.TmdbResultsList;
|
||||||
|
import com.omertron.themoviedbapi.results.TmdbResultsMap;
|
||||||
|
import com.omertron.themoviedbapi.tools.ApiUrl;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_ADULT;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_COUNTRY;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_END_DATE;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_ID;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_INCLUDE_ALL_MOVIES;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_LANGUAGE;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_PAGE;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_QUERY;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_SESSION;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_START_DATE;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_TOKEN;
|
||||||
|
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_YEAR;
|
||||||
|
import com.omertron.themoviedbapi.tools.WebBrowser;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperChanges;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperCollection;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperCompany;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperCompanyMovies;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperConfig;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperGenres;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperImages;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperJobList;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperKeywordMovies;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperKeywords;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperMovie;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperMovieCasts;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperMovieChanges;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperMovieDbList;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperMovieList;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperPerson;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperPersonCredits;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperPersonList;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperReleaseInfo;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperReviews;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperTrailers;
|
||||||
|
import com.omertron.themoviedbapi.wrapper.WrapperTranslations;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@@ -27,21 +100,11 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import static com.omertron.themoviedbapi.tools.ApiUrl.*;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.yamj.api.common.http.CommonHttpClient;
|
import org.yamj.api.common.http.CommonHttpClient;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType;
|
|
||||||
import com.omertron.themoviedbapi.model.*;
|
|
||||||
import com.omertron.themoviedbapi.results.TmdbResultsList;
|
|
||||||
import com.omertron.themoviedbapi.results.TmdbResultsMap;
|
|
||||||
import com.omertron.themoviedbapi.tools.ApiUrl;
|
|
||||||
import com.omertron.themoviedbapi.tools.WebBrowser;
|
|
||||||
import com.omertron.themoviedbapi.wrapper.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The MovieDb API
|
* The MovieDb API
|
||||||
@@ -163,7 +226,7 @@ public class TheMovieDbApi {
|
|||||||
* @param username
|
* @param username
|
||||||
* @param password
|
* @param password
|
||||||
*/
|
*/
|
||||||
public void setProxy(String host, String port, String username, String password) {
|
public void setProxy(String host, int port, String username, String password) {
|
||||||
// should be set in HTTP client already
|
// should be set in HTTP client already
|
||||||
if (httpClient != null) {
|
if (httpClient != null) {
|
||||||
return;
|
return;
|
||||||
@@ -426,7 +489,7 @@ public class TheMovieDbApi {
|
|||||||
|
|
||||||
apiUrl.addArgument(PARAM_SESSION, sessionId);
|
apiUrl.addArgument(PARAM_SESSION, sessionId);
|
||||||
|
|
||||||
HashMap<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("movie_id", movieId);
|
body.put("movie_id", movieId);
|
||||||
body.put("favorite", isFavorite);
|
body.put("favorite", isFavorite);
|
||||||
String jsonBody = convertToJson(body);
|
String jsonBody = convertToJson(body);
|
||||||
@@ -473,7 +536,7 @@ public class TheMovieDbApi {
|
|||||||
|
|
||||||
apiUrl.addArgument(PARAM_SESSION, sessionId);
|
apiUrl.addArgument(PARAM_SESSION, sessionId);
|
||||||
|
|
||||||
HashMap<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("movie_id", movieId);
|
body.put("movie_id", movieId);
|
||||||
body.put("movie_watchlist", add);
|
body.put("movie_watchlist", add);
|
||||||
String jsonBody = convertToJson(body);
|
String jsonBody = convertToJson(body);
|
||||||
@@ -565,7 +628,7 @@ public class TheMovieDbApi {
|
|||||||
return movie;
|
return movie;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.warn("Failed to get movie info: {}", ex.getMessage(), ex);
|
LOG.warn("Failed to get movie info: {}", ex.getMessage(), ex);
|
||||||
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
|
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, "Failed to get movie info", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1592,7 +1655,7 @@ public class TheMovieDbApi {
|
|||||||
* @throws MovieDbException
|
* @throws MovieDbException
|
||||||
*/
|
*/
|
||||||
public TmdbResultsList<Collection> searchCollection(String query, String language, int page) throws MovieDbException {
|
public TmdbResultsList<Collection> searchCollection(String query, String language, int page) throws MovieDbException {
|
||||||
ApiUrl apiUrl = new ApiUrl(apiKey, BASE_SEARCH, "collections");
|
ApiUrl apiUrl = new ApiUrl(apiKey, BASE_SEARCH, "collection");
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(query)) {
|
if (StringUtils.isNotBlank(query)) {
|
||||||
apiUrl.addArgument(PARAM_QUERY, query);
|
apiUrl.addArgument(PARAM_QUERY, query);
|
||||||
@@ -1819,7 +1882,7 @@ public class TheMovieDbApi {
|
|||||||
ApiUrl apiUrl = new ApiUrl(apiKey, "list");
|
ApiUrl apiUrl = new ApiUrl(apiKey, "list");
|
||||||
apiUrl.addArgument(PARAM_SESSION, sessionId);
|
apiUrl.addArgument(PARAM_SESSION, sessionId);
|
||||||
|
|
||||||
HashMap<String, String> body = new HashMap<String, String>();
|
Map<String, String> body = new HashMap<String, String>();
|
||||||
body.put("name", StringUtils.trimToEmpty(name));
|
body.put("name", StringUtils.trimToEmpty(name));
|
||||||
body.put("description", StringUtils.trimToEmpty(description));
|
body.put("description", StringUtils.trimToEmpty(description));
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ package com.omertron.themoviedbapi.model;
|
|||||||
*/
|
*/
|
||||||
public enum ArtworkType {
|
public enum ArtworkType {
|
||||||
|
|
||||||
POSTER, // Poster artwork
|
// Poster artwork
|
||||||
BACKDROP, // Fanart/backdrop
|
POSTER,
|
||||||
PROFILE // Person image
|
// Fanart/backdrop
|
||||||
|
BACKDROP,
|
||||||
|
// Person image
|
||||||
|
PROFILE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,12 +48,17 @@ public class Person extends AbstractJsonMapping {
|
|||||||
@JsonProperty("profile_path")
|
@JsonProperty("profile_path")
|
||||||
private String profilePath = DEFAULT_STRING;
|
private String profilePath = DEFAULT_STRING;
|
||||||
private PersonType personType = PersonType.PERSON;
|
private PersonType personType = PersonType.PERSON;
|
||||||
private String department = DEFAULT_STRING; // Crew
|
// Crew
|
||||||
private String job = DEFAULT_STRING; // Crew
|
private String department = DEFAULT_STRING;
|
||||||
private String character = DEFAULT_STRING; // Cast
|
// Crew
|
||||||
private int order = -1; // Cast
|
private String job = DEFAULT_STRING;
|
||||||
|
// Cast
|
||||||
|
private String character = DEFAULT_STRING;
|
||||||
|
// Cast
|
||||||
|
private int order = -1;
|
||||||
@JsonProperty("adult")
|
@JsonProperty("adult")
|
||||||
private boolean adult = false; // Person info
|
// Person info
|
||||||
|
private boolean adult = false;
|
||||||
@JsonProperty("also_known_as")
|
@JsonProperty("also_known_as")
|
||||||
private List<String> aka = new ArrayList<String>();
|
private List<String> aka = new ArrayList<String>();
|
||||||
@JsonProperty("biography")
|
@JsonProperty("biography")
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ package com.omertron.themoviedbapi.model;
|
|||||||
*/
|
*/
|
||||||
public enum PersonType {
|
public enum PersonType {
|
||||||
|
|
||||||
CAST, // A member of the cast
|
// A member of the cast
|
||||||
CREW, // A member of the crew
|
CAST,
|
||||||
PERSON // No specific type
|
// A member of the crew
|
||||||
|
CREW,
|
||||||
|
// No specific type
|
||||||
|
PERSON
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ public class Trailer extends AbstractJsonMapping {
|
|||||||
private String name;
|
private String name;
|
||||||
private String size;
|
private String size;
|
||||||
private String source;
|
private String source;
|
||||||
private String website; // The website of the trailer
|
// The website of the trailer
|
||||||
|
private String website;
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|||||||
+98
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2004-2013 Stuart Boston
|
||||||
|
*
|
||||||
|
* This file is part of TheMovieDB API.
|
||||||
|
*
|
||||||
|
* TheMovieDB API is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation;private either version 3 of the License;private or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* TheMovieDB API is distributed in the hope that it will be useful;private
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with TheMovieDB API. If not;private see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.omertron.themoviedbapi.model.comparator;
|
||||||
|
|
||||||
|
import com.omertron.themoviedbapi.model.PersonCredit;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two PersonCredits by date
|
||||||
|
*
|
||||||
|
* @author stuart.boston
|
||||||
|
*/
|
||||||
|
public class PersonCreditDateComparator implements Comparator<PersonCredit>, Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Pattern YEAR_PATTERN = Pattern.compile("(?:.*?)(\\d{4})(?:.*?)");
|
||||||
|
private final boolean ascending;
|
||||||
|
|
||||||
|
public PersonCreditDateComparator() {
|
||||||
|
this.ascending = Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PersonCreditDateComparator(boolean ascending) {
|
||||||
|
this.ascending = ascending;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(PersonCredit pc1, PersonCredit pc2) {
|
||||||
|
return compare(pc1, pc2, ascending);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two PersonCredits based on the respective years
|
||||||
|
*
|
||||||
|
* @param pc1
|
||||||
|
* @param pc2
|
||||||
|
* @param ascending
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int compare(PersonCredit pc1, PersonCredit pc2, boolean ascending) {
|
||||||
|
boolean valid1 = StringUtils.isNotBlank(pc1.getReleaseDate());
|
||||||
|
boolean valid2 = StringUtils.isNotBlank(pc2.getReleaseDate());
|
||||||
|
|
||||||
|
if (!valid1 && !valid2) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid1) {
|
||||||
|
return ascending ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid2) {
|
||||||
|
return ascending ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int year1 = extractYear(pc1.getReleaseDate());
|
||||||
|
int year2 = extractYear(pc2.getReleaseDate());
|
||||||
|
return ascending ? (year1 - year2) : (year2 - year1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* locate a 4 digit year in a date string
|
||||||
|
*
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static int extractYear(String date) {
|
||||||
|
int year = 0;
|
||||||
|
Matcher m = YEAR_PATTERN.matcher(date);
|
||||||
|
if (m.find()) {
|
||||||
|
year = Integer.valueOf(m.group(1)).intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Give up and return 0
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -30,7 +30,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||||||
*
|
*
|
||||||
* @author Stuart
|
* @author Stuart
|
||||||
*/
|
*/
|
||||||
public abstract class TmdbResults {
|
public abstract class AbstractResults {
|
||||||
|
|
||||||
private int id = 0;
|
private int id = 0;
|
||||||
private int page = 0;
|
private int page = 0;
|
||||||
@@ -100,6 +100,6 @@ public abstract class TmdbResults {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE);
|
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ import java.util.List;
|
|||||||
* @author Stuart
|
* @author Stuart
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public final class TmdbResultsList<T> extends TmdbResults {
|
public final class TmdbResultsList<T> extends AbstractResults {
|
||||||
|
|
||||||
private List<T> results;
|
private List<T> results;
|
||||||
|
|
||||||
@@ -47,4 +47,13 @@ public final class TmdbResultsList<T> extends TmdbResults {
|
|||||||
public void setResults(List<T> results) {
|
public void setResults(List<T> results) {
|
||||||
this.results = results;
|
this.results = results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalResults() {
|
||||||
|
if (super.getTotalResults() == 0) {
|
||||||
|
return results.size();
|
||||||
|
} else {
|
||||||
|
return super.getTotalResults();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import java.util.Map;
|
|||||||
* @param <K>
|
* @param <K>
|
||||||
* @param <V>
|
* @param <V>
|
||||||
*/
|
*/
|
||||||
public final class TmdbResultsMap<K, V> extends TmdbResults {
|
public final class TmdbResultsMap<K, V> extends AbstractResults {
|
||||||
|
|
||||||
private Map<K, V> results;
|
private Map<K, V> results;
|
||||||
|
|
||||||
@@ -44,4 +44,13 @@ public final class TmdbResultsMap<K, V> extends TmdbResults {
|
|||||||
public void setResults(Map<K, V> results) {
|
public void setResults(Map<K, V> results) {
|
||||||
this.results = results;
|
this.results = results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalResults() {
|
||||||
|
if (super.getTotalResults() == 0) {
|
||||||
|
return results.size();
|
||||||
|
} else {
|
||||||
|
return super.getTotalResults();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,12 +47,14 @@ public final class WebBrowser {
|
|||||||
private static final Map<String, String> BROWSER_PROPERTIES = new HashMap<String, String>();
|
private static final Map<String, String> BROWSER_PROPERTIES = new HashMap<String, String>();
|
||||||
private static final Map<String, Map<String, String>> COOKIES = new HashMap<String, Map<String, String>>();
|
private static final Map<String, Map<String, String>> COOKIES = new HashMap<String, Map<String, String>>();
|
||||||
private static String proxyHost = null;
|
private static String proxyHost = null;
|
||||||
private static String proxyPort = null;
|
private static int proxyPort = 0;
|
||||||
private static String proxyUsername = null;
|
private static String proxyUsername = null;
|
||||||
private static String proxyPassword = null;
|
private static String proxyPassword = null;
|
||||||
private static String proxyEncodedPassword = null;
|
private static String proxyEncodedPassword = null;
|
||||||
private static int webTimeoutConnect = 25000; // 25 second timeout
|
// 25 second timeout
|
||||||
private static int webTimeoutRead = 90000; // 90 second timeout
|
private static int webTimeoutConnect = 25000;
|
||||||
|
// 90 second timeout
|
||||||
|
private static int webTimeoutRead = 90000;
|
||||||
|
|
||||||
// Hide the constructor
|
// Hide the constructor
|
||||||
protected WebBrowser() {
|
protected WebBrowser() {
|
||||||
@@ -276,11 +278,11 @@ public final class WebBrowser {
|
|||||||
WebBrowser.proxyHost = myProxyHost;
|
WebBrowser.proxyHost = myProxyHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getProxyPort() {
|
public static int getProxyPort() {
|
||||||
return proxyPort;
|
return proxyPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setProxyPort(String myProxyPort) {
|
public static void setProxyPort(int myProxyPort) {
|
||||||
WebBrowser.proxyPort = myProxyPort;
|
WebBrowser.proxyPort = myProxyPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -890,7 +890,6 @@ public class TheMovieDbApiTest {
|
|||||||
/**
|
/**
|
||||||
* Test of getPersonPopular method, of class TheMovieDbApi.
|
* Test of getPersonPopular method, of class TheMovieDbApi.
|
||||||
*
|
*
|
||||||
* @throws MovieDbException
|
|
||||||
*/
|
*/
|
||||||
@Ignore("Not required")
|
@Ignore("Not required")
|
||||||
public void testGetPersonPopular_0args() {
|
public void testGetPersonPopular_0args() {
|
||||||
|
|||||||
Reference in New Issue
Block a user