Update trailers method

master
Jc Miñarro 11 years ago
parent 82c8b31f9f
commit 67496724ba

@ -22,76 +22,18 @@ package com.omertron.themoviedbapi;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType; import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType;
import com.omertron.themoviedbapi.model.Account; import com.omertron.themoviedbapi.model.*;
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.TmdbResultsList;
import com.omertron.themoviedbapi.results.TmdbResultsMap; import com.omertron.themoviedbapi.results.TmdbResultsMap;
import com.omertron.themoviedbapi.tools.ApiUrl; 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.tools.WebBrowser;
import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; import com.omertron.themoviedbapi.wrapper.*;
import com.omertron.themoviedbapi.wrapper.WrapperChanges; import org.apache.commons.lang3.StringUtils;
import com.omertron.themoviedbapi.wrapper.WrapperCollection; import org.apache.http.client.methods.HttpGet;
import com.omertron.themoviedbapi.wrapper.WrapperCompany; import org.slf4j.Logger;
import com.omertron.themoviedbapi.wrapper.WrapperCompanyMovies; import org.slf4j.LoggerFactory;
import com.omertron.themoviedbapi.wrapper.WrapperConfig; import org.yamj.api.common.http.CommonHttpClient;
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;
@ -100,11 +42,8 @@ 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 org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpGet; import static com.omertron.themoviedbapi.tools.ApiUrl.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.CommonHttpClient;
/** /**
* The MovieDb API * The MovieDb API
@ -849,7 +788,7 @@ public class TheMovieDbApi {
* @throws MovieDbException * @throws MovieDbException
*/ */
public TmdbResultsList<Trailer> getMovieTrailers(int movieId, String language, String... appendToResponse) throws MovieDbException { public TmdbResultsList<Trailer> 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); apiUrl.addArgument(PARAM_ID, movieId);
if (StringUtils.isNotBlank(language)) { if (StringUtils.isNotBlank(language)) {
@ -863,7 +802,7 @@ public class TheMovieDbApi {
try { try {
WrapperTrailers wrapper = mapper.readValue(webpage, WrapperTrailers.class); WrapperTrailers wrapper = mapper.readValue(webpage, WrapperTrailers.class);
TmdbResultsList<Trailer> results = new TmdbResultsList<Trailer>(wrapper.getAll()); TmdbResultsList<Trailer> results = new TmdbResultsList<Trailer>(wrapper.getTrailers());
results.copyWrapper(wrapper); results.copyWrapper(wrapper);
return results; return results;
} catch (IOException ex) { } catch (IOException ex) {

@ -20,20 +20,12 @@
package com.omertron.themoviedbapi.model; package com.omertron.themoviedbapi.model;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; import com.omertron.themoviedbapi.wrapper.*;
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 org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.util.List;
/** /**
* Movie Bean * Movie Bean
* *
@ -334,7 +326,7 @@ public class MovieDb extends AbstractJsonMapping {
} }
public List<Trailer> getTrailers() { public List<Trailer> getTrailers() {
return trailers.getAll(); return trailers.getTrailers();
} }
public List<Translation> getTranslations() { public List<Translation> getTranslations() {

@ -19,6 +19,7 @@
*/ */
package com.omertron.themoviedbapi.model; package com.omertron.themoviedbapi.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder;
@ -37,13 +38,21 @@ public class Trailer extends AbstractJsonMapping {
/* /*
* Properties * Properties
*/ */
private String id;
private String name; private String name;
private String size; private String size;
private String source; private String key;
// The website of the trailer // The website of the trailer
private String website; private String site;
private String type; private String type;
@JsonProperty("iso_639_1")
private String language;
public String getId() {
return id;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -52,18 +61,26 @@ public class Trailer extends AbstractJsonMapping {
return size; return size;
} }
public String getSource() { public String getKey() {
return source; return key;
} }
public String getWebsite() { public String getSite() {
return website; return site;
} }
public String getType() { public String getType() {
return type; return type;
} }
public String getLanguage() {
return language;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@ -72,26 +89,32 @@ public class Trailer extends AbstractJsonMapping {
this.size = size; this.size = size;
} }
public void setSource(String source) { public void setKey(String key) {
this.source = source; this.key = key;
} }
public void setWebsite(String website) { public void setSite(String site) {
this.website = website; this.site = site;
} }
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
public void setLanguage(String language) {
this.language = language;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Trailer) { if (obj instanceof Trailer) {
final Trailer other = (Trailer) obj; final Trailer other = (Trailer) obj;
return new EqualsBuilder() return new EqualsBuilder()
.append(id, other.id)
.append(name, other.name) .append(name, other.name)
.append(size, other.size) .append(size, other.size)
.append(source, other.source) .append(key, other.key)
.append(language, other.language)
.isEquals(); .isEquals();
} else { } else {
return false; return false;
@ -101,10 +124,12 @@ public class Trailer extends AbstractJsonMapping {
@Override @Override
public int hashCode() { public int hashCode() {
return new HashCodeBuilder() return new HashCodeBuilder()
.append(id)
.append(name) .append(name)
.append(size) .append(size)
.append(source) .append(key)
.append(website) .append(site)
.append(language)
.toHashCode(); .toHashCode();
} }
} }

@ -21,8 +21,8 @@ package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model.Trailer; import com.omertron.themoviedbapi.model.Trailer;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -32,51 +32,15 @@ import java.util.List;
public class WrapperTrailers extends AbstractWrapperId implements Serializable { public class WrapperTrailers extends AbstractWrapperId implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@JsonProperty("quicktime") @JsonProperty("results")
private List<Trailer> quicktime; private List<Trailer> trailers;
@JsonProperty("youtube")
private List<Trailer> youtube;
public List<Trailer> getQuicktime() {
return quicktime;
}
public List<Trailer> getYoutube() { public List<Trailer> getTrailers() {
return youtube; return trailers;
}
public void setQuicktime(List<Trailer> quicktime) {
this.quicktime = quicktime;
} }
public void setYoutube(List<Trailer> youtube) { public void setTrailers(List<Trailer> trailers) {
this.youtube = youtube; this.trailers = trailers;
} }
/**
* Get a combined list of the trailers with their source
*
* @return
*/
public List<Trailer> getAll() {
List<Trailer> trailers = new ArrayList<Trailer>();
// 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);
}
}
return trailers;
}
} }

@ -19,57 +19,21 @@
*/ */
package com.omertron.themoviedbapi; package com.omertron.themoviedbapi;
import static org.junit.Assert.assertEquals; import com.omertron.themoviedbapi.model.*;
import static org.junit.Assert.assertFalse; import com.omertron.themoviedbapi.results.TmdbResultsList;
import static org.junit.Assert.assertNotNull; import com.omertron.themoviedbapi.results.TmdbResultsMap;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.After; import org.apache.commons.lang3.math.NumberUtils;
import org.junit.AfterClass; import org.junit.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.io.File;
import java.util.List;
import java.util.Properties; 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 * Test cases for TheMovieDbApi API

Loading…
Cancel
Save