Merge pull request #19 from IGZJcMinarro/master

Update trailers method
master
Stuart Boston 11 years ago
commit 56a0cdb341

@ -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<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);
if (StringUtils.isNotBlank(language)) {
@ -863,7 +802,7 @@ public class TheMovieDbApi {
try {
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);
return results;
} catch (IOException ex) {

@ -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
*
@ -101,7 +93,7 @@ public class MovieDb extends AbstractJsonMapping {
private WrapperMovieKeywords keywords;
@JsonProperty("releases")
private WrapperReleaseInfo releases;
@JsonProperty("trailers")
@JsonProperty("videos")
private WrapperTrailers trailers;
@JsonProperty("translations")
private WrapperTranslations translations;
@ -334,7 +326,7 @@ public class MovieDb extends AbstractJsonMapping {
}
public List<Trailer> getTrailers() {
return trailers.getAll();
return trailers.getTrailers();
}
public List<Translation> getTranslations() {

@ -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();
}
}

@ -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<Trailer> quicktime;
@JsonProperty("youtube")
private List<Trailer> youtube;
public List<Trailer> getQuicktime() {
return quicktime;
}
@JsonProperty("results")
private List<Trailer> trailers;
public List<Trailer> getYoutube() {
return youtube;
}
public void setQuicktime(List<Trailer> quicktime) {
this.quicktime = quicktime;
public List<Trailer> getTrailers() {
return trailers;
}
public void setYoutube(List<Trailer> youtube) {
this.youtube = youtube;
public void setTrailers(List<Trailer> trailers) {
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;
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

Loading…
Cancel
Save