diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 44408519a..6e2dc1388 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -22,76 +22,18 @@ 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.model.*; 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 com.omertron.themoviedbapi.wrapper.*; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.methods.HttpGet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.CommonHttpClient; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; @@ -100,11 +42,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.client.methods.HttpGet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.CommonHttpClient; + +import static com.omertron.themoviedbapi.tools.ApiUrl.*; /** * The MovieDb API @@ -849,7 +788,7 @@ public class TheMovieDbApi { * @throws MovieDbException */ public TmdbResultsList getMovieTrailers(int movieId, String language, String... appendToResponse) throws MovieDbException { - ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/trailers"); + ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/videos"); apiUrl.addArgument(PARAM_ID, movieId); if (StringUtils.isNotBlank(language)) { @@ -863,7 +802,7 @@ public class TheMovieDbApi { try { WrapperTrailers wrapper = mapper.readValue(webpage, WrapperTrailers.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); + TmdbResultsList results = new TmdbResultsList(wrapper.getTrailers()); results.copyWrapper(wrapper); return results; } catch (IOException ex) { diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index 4ee7e5b02..e88eea3ee 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -20,20 +20,12 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; -import com.omertron.themoviedbapi.wrapper.WrapperImages; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; -import com.omertron.themoviedbapi.wrapper.WrapperMovieCasts; -import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; -import com.omertron.themoviedbapi.wrapper.WrapperMovieList; -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.util.List; +import com.omertron.themoviedbapi.wrapper.*; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import java.util.List; + /** * Movie Bean * @@ -334,7 +326,7 @@ public class MovieDb extends AbstractJsonMapping { } public List getTrailers() { - return trailers.getAll(); + return trailers.getTrailers(); } public List getTranslations() { diff --git a/src/main/java/com/omertron/themoviedbapi/model/Trailer.java b/src/main/java/com/omertron/themoviedbapi/model/Trailer.java index f6a420978..1c82c4a5f 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Trailer.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Trailer.java @@ -19,6 +19,7 @@ */ package com.omertron.themoviedbapi.model; +import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -37,13 +38,21 @@ public class Trailer extends AbstractJsonMapping { /* * Properties */ + private String id; private String name; private String size; - private String source; + private String key; // The website of the trailer - private String website; + private String site; private String type; + @JsonProperty("iso_639_1") + private String language; + + public String getId() { + return id; + } + public String getName() { return name; } @@ -52,18 +61,26 @@ public class Trailer extends AbstractJsonMapping { return size; } - public String getSource() { - return source; + public String getKey() { + return key; } - public String getWebsite() { - return website; + public String getSite() { + return site; } public String getType() { return type; } + public String getLanguage() { + return language; + } + + public void setId(String id) { + this.id = id; + } + public void setName(String name) { this.name = name; } @@ -72,26 +89,32 @@ public class Trailer extends AbstractJsonMapping { this.size = size; } - public void setSource(String source) { - this.source = source; + public void setKey(String key) { + this.key = key; } - public void setWebsite(String website) { - this.website = website; + public void setSite(String site) { + this.site = site; } public void setType(String type) { this.type = type; } + public void setLanguage(String language) { + this.language = language; + } + @Override public boolean equals(Object obj) { if (obj instanceof Trailer) { final Trailer other = (Trailer) obj; return new EqualsBuilder() + .append(id, other.id) .append(name, other.name) .append(size, other.size) - .append(source, other.source) + .append(key, other.key) + .append(language, other.language) .isEquals(); } else { return false; @@ -101,10 +124,12 @@ public class Trailer extends AbstractJsonMapping { @Override public int hashCode() { return new HashCodeBuilder() + .append(id) .append(name) .append(size) - .append(source) - .append(website) + .append(key) + .append(site) + .append(language) .toHashCode(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTrailers.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTrailers.java index 969c9d99e..66956d338 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTrailers.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperTrailers.java @@ -21,8 +21,8 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; import com.omertron.themoviedbapi.model.Trailer; + import java.io.Serializable; -import java.util.ArrayList; import java.util.List; /** @@ -32,51 +32,15 @@ import java.util.List; public class WrapperTrailers extends AbstractWrapperId implements Serializable { private static final long serialVersionUID = 1L; - @JsonProperty("quicktime") - private List quicktime; - @JsonProperty("youtube") - private List youtube; - - public List getQuicktime() { - return quicktime; - } - - public List getYoutube() { - return youtube; - } - - public void setQuicktime(List quicktime) { - this.quicktime = quicktime; - } - - public void setYoutube(List youtube) { - this.youtube = youtube; - } - - /** - * Get a combined list of the trailers with their source - * - * @return - */ - public List getAll() { - List trailers = new ArrayList(); - - // Add the trailer to the return list along with it's source - if (quicktime != null) { - for (Trailer trailer : quicktime) { - trailer.setWebsite(Trailer.WEBSITE_QUICKTIME); - trailers.add(trailer); - } - } - - // Add the trailer to the return list along with it's source - if (youtube != null) { - for (Trailer trailer : youtube) { - trailer.setWebsite(Trailer.WEBSITE_YOUTUBE); - trailers.add(trailer); - } - } + @JsonProperty("results") + private List trailers; + public List getTrailers() { return trailers; } + + public void setTrailers(List trailers) { + this.trailers = trailers; + } + } diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index d290ce0c3..b204033a0 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -19,57 +19,21 @@ */ package com.omertron.themoviedbapi; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.List; -import java.util.Random; - +import com.omertron.themoviedbapi.model.*; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.results.TmdbResultsMap; import org.apache.commons.lang3.StringUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.apache.commons.lang3.math.NumberUtils; +import org.junit.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.omertron.themoviedbapi.model.Account; -import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; -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.MovieDb; -import com.omertron.themoviedbapi.model.MovieDbList; -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 java.io.File; +import java.util.List; import java.util.Properties; -import org.apache.commons.lang3.math.NumberUtils; +import java.util.Random; + +import static org.junit.Assert.*; /** * Test cases for TheMovieDbApi API