From f713bde372e8b5ff2bff9b174a6a3d1167a50435 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Thu, 5 Mar 2015 13:45:15 +0000 Subject: [PATCH] TV Seasons --- .../omertron/themoviedbapi/TheMovieDbApi.java | 6 +- .../themoviedbapi/methods/AbstractMethod.java | 2 +- .../themoviedbapi/methods/TmdbMovies.java | 6 +- .../themoviedbapi/methods/TmdbTV.java | 12 +- .../themoviedbapi/methods/TmdbTVSeasons.java | 90 +++++++++-- .../{movie => media}/AlternativeTitle.java | 2 +- .../model/{movie => media}/Trailer.java | 2 +- .../model/{movie => media}/Translation.java | 2 +- .../model/{movie => media}/Video.java | 2 +- .../themoviedbapi/model/movie/MovieDb.java | 3 + .../themoviedbapi/model/tv/TVEpisodeInfo.java | 64 ++++++++ .../themoviedbapi/model/tv/TVSeasonInfo.java | 63 ++++++++ .../wrapper/WrapperAlternativeTitles.java | 2 +- .../wrapper/WrapperTranslations.java | 2 +- .../themoviedbapi/wrapper/WrapperVideos.java | 4 +- .../themoviedbapi/methods/TmdbMoviesTest.java | 6 +- .../methods/TmdbTVEpisodesTest.java | 16 +- .../methods/TmdbTVSeasonsTest.java | 142 +++++++++++++----- .../themoviedbapi/methods/TmdbTVTest.java | 6 +- 19 files changed, 342 insertions(+), 90 deletions(-) rename src/main/java/com/omertron/themoviedbapi/model/{movie => media}/AlternativeTitle.java (97%) rename src/main/java/com/omertron/themoviedbapi/model/{movie => media}/Trailer.java (98%) rename src/main/java/com/omertron/themoviedbapi/model/{movie => media}/Translation.java (98%) rename src/main/java/com/omertron/themoviedbapi/model/{movie => media}/Video.java (98%) create mode 100644 src/main/java/com/omertron/themoviedbapi/model/tv/TVEpisodeInfo.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model/tv/TVSeasonInfo.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 8a6959014..b5a0d1a06 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -64,12 +64,12 @@ import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.model.media.MediaBasic; import com.omertron.themoviedbapi.model.media.MediaCreditList; import com.omertron.themoviedbapi.model.media.MediaState; -import com.omertron.themoviedbapi.model.movie.AlternativeTitle; +import com.omertron.themoviedbapi.model.media.AlternativeTitle; import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.movie.MovieDb; import com.omertron.themoviedbapi.model.movie.ReleaseInfo; -import com.omertron.themoviedbapi.model.movie.Translation; -import com.omertron.themoviedbapi.model.movie.Video; +import com.omertron.themoviedbapi.model.media.Translation; +import com.omertron.themoviedbapi.model.media.Video; import com.omertron.themoviedbapi.model.network.Network; import com.omertron.themoviedbapi.model.person.ContentRating; import com.omertron.themoviedbapi.model.person.CreditInfo; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 711e22e7d..7766c4630 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -28,7 +28,7 @@ import com.omertron.themoviedbapi.model.collection.Collection; import com.omertron.themoviedbapi.model.company.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.list.UserList; -import com.omertron.themoviedbapi.model.movie.AlternativeTitle; +import com.omertron.themoviedbapi.model.media.AlternativeTitle; import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.movie.MovieDb; import com.omertron.themoviedbapi.model.person.ContentRating; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index c863b27a9..cd4cd38e2 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -27,11 +27,11 @@ import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.model.media.MediaCreditList; import com.omertron.themoviedbapi.model.media.MediaState; -import com.omertron.themoviedbapi.model.movie.AlternativeTitle; +import com.omertron.themoviedbapi.model.media.AlternativeTitle; import com.omertron.themoviedbapi.model.movie.MovieDb; import com.omertron.themoviedbapi.model.movie.ReleaseInfo; -import com.omertron.themoviedbapi.model.movie.Translation; -import com.omertron.themoviedbapi.model.movie.Video; +import com.omertron.themoviedbapi.model.media.Translation; +import com.omertron.themoviedbapi.model.media.Video; import com.omertron.themoviedbapi.model.review.Review; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java index ee85eb28e..af756ccfa 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java @@ -26,9 +26,9 @@ import com.omertron.themoviedbapi.model.artwork.Artwork; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.media.MediaCreditList; import com.omertron.themoviedbapi.model.media.MediaState; -import com.omertron.themoviedbapi.model.movie.AlternativeTitle; -import com.omertron.themoviedbapi.model.movie.Translation; -import com.omertron.themoviedbapi.model.movie.Video; +import com.omertron.themoviedbapi.model.media.AlternativeTitle; +import com.omertron.themoviedbapi.model.media.Translation; +import com.omertron.themoviedbapi.model.media.Video; import com.omertron.themoviedbapi.model.person.ContentRating; import com.omertron.themoviedbapi.model.person.ExternalID; import com.omertron.themoviedbapi.model.tv.TVBasic; @@ -158,7 +158,7 @@ public class TmdbTV extends AbstractMethod { try { return MAPPER.readValue(webpage, WrapperChanges.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie changes", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); } } @@ -198,7 +198,7 @@ public class TmdbTV extends AbstractMethod { try { return MAPPER.readValue(webpage, MediaCreditList.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie credits", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get credits", url, ex); } } @@ -393,7 +393,7 @@ public class TmdbTV extends AbstractMethod { try { return MAPPER.readValue(webpage, TVInfo.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get latest movie", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get latest TV show", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbTVSeasons.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTVSeasons.java index 71d72be50..1208b0584 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbTVSeasons.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTVSeasons.java @@ -20,13 +20,27 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; +import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER; +import com.omertron.themoviedbapi.model.artwork.Artwork; +import com.omertron.themoviedbapi.model.media.MediaCreditList; +import com.omertron.themoviedbapi.model.media.MediaState; +import com.omertron.themoviedbapi.model.media.Video; +import com.omertron.themoviedbapi.model.person.ExternalID; +import com.omertron.themoviedbapi.model.tv.TVSeasonInfo; +import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperChanges; +import com.omertron.themoviedbapi.wrapper.WrapperImages; +import com.omertron.themoviedbapi.wrapper.WrapperVideos; +import java.io.IOException; import java.net.URL; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the TV Methods @@ -57,7 +71,7 @@ public class TmdbTVSeasons extends AbstractMethod { * @return * @throws MovieDbException */ - public String getSeasonInfo(int tvID, int seasonNumber, String language, String... appendToResponse) throws MovieDbException { + public TVSeasonInfo getSeasonInfo(int tvID, int seasonNumber, String language, String... appendToResponse) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, tvID); parameters.add(Param.SEASON_NUMBER, seasonNumber); @@ -65,7 +79,14 @@ public class TmdbTVSeasons extends AbstractMethod { parameters.add(Param.APPEND, appendToResponse); URL url = new ApiUrl(apiKey, MethodBase.SEASON).buildUrl(parameters); - return null; + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, TVSeasonInfo.class); + } catch (IOException ex) { + LoggerFactory.getLogger("test").warn("{}", ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get TV SeasonInfo", url, ex); + } } /** @@ -77,14 +98,20 @@ public class TmdbTVSeasons extends AbstractMethod { * @return * @throws MovieDbException */ - public String getSeasonChanges(int tvID, String startDate, String endDate) throws MovieDbException { + public WrapperChanges getSeasonChanges(int tvID, String startDate, String endDate) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, tvID); parameters.add(Param.START_DATE, startDate); parameters.add(Param.END_DATE, endDate); URL url = new ApiUrl(apiKey, MethodBase.SEASON).subMethod(MethodSub.CHANGES).buildUrl(parameters); - return null; + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, WrapperChanges.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); + } } /** @@ -98,13 +125,19 @@ public class TmdbTVSeasons extends AbstractMethod { * @return * @throws MovieDbException */ - public String getSeasonAccountState(int tvID, String sessionID) throws MovieDbException { + public MediaState getSeasonAccountState(int tvID, String sessionID) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, tvID); parameters.add(Param.SESSION_ID, sessionID); URL url = new ApiUrl(apiKey, MethodBase.SEASON).subMethod(MethodSub.ACCOUNT_STATES).buildUrl(parameters); - return null; + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, MediaState.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get account state", url, ex); + } } /** @@ -115,13 +148,18 @@ public class TmdbTVSeasons extends AbstractMethod { * @return * @throws MovieDbException */ - public String getSeasonCredits(int tvID, int seasonNumber) throws MovieDbException { + public MediaCreditList getSeasonCredits(int tvID, int seasonNumber) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, tvID); parameters.add(Param.SEASON_NUMBER, seasonNumber); URL url = new ApiUrl(apiKey, MethodBase.SEASON).subMethod(MethodSub.CREDITS).buildUrl(parameters); - return null; + String webpage = httpTools.getRequest(url); + try { + return MAPPER.readValue(webpage, MediaCreditList.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get credits", url, ex); + } } /** @@ -134,14 +172,20 @@ public class TmdbTVSeasons extends AbstractMethod { * @return * @throws MovieDbException */ - public String getSeasonExternalID(int tvID, int seasonNumber, String language) throws MovieDbException { + public ExternalID getSeasonExternalID(int tvID, int seasonNumber, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, tvID); parameters.add(Param.SEASON_NUMBER, seasonNumber); parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.SEASON).subMethod(MethodSub.EXTERNAL_IDS).buildUrl(parameters); - return null; + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, ExternalID.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get external IDs", url, ex); + } } /** @@ -154,7 +198,7 @@ public class TmdbTVSeasons extends AbstractMethod { * @return * @throws MovieDbException */ - public String getSeasonImages(int tvID, int seasonNumber, String language, String... includeImageLanguage) throws MovieDbException { + public TmdbResultsList getSeasonImages(int tvID, int seasonNumber, String language, String... includeImageLanguage) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, tvID); parameters.add(Param.SEASON_NUMBER, seasonNumber); @@ -162,7 +206,16 @@ public class TmdbTVSeasons extends AbstractMethod { parameters.add(Param.APPEND, includeImageLanguage); URL url = new ApiUrl(apiKey, MethodBase.SEASON).subMethod(MethodSub.IMAGES).buildUrl(parameters); - return null; + String webpage = httpTools.getRequest(url); + + try { + WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get images", url, ex); + } } /** @@ -175,13 +228,22 @@ public class TmdbTVSeasons extends AbstractMethod { * @return * @throws MovieDbException */ - public String getSeasonVideos(int tvID, int seasonNumber, String language) throws MovieDbException { + public TmdbResultsList