Пример #1
0
        /// <summary>
        /// Retrieve a tv Show by id.
        /// </summary>
        /// <param name="id">TMDb id of the tv show to retrieve.</param>
        /// <param name="extraMethods">Enum flags indicating any additional data that should be fetched in the same request.</param>
        /// <param name="language">If specified the api will attempt to return a localized result. ex: en,it,es </param>
        /// <returns>The requested Tv Show</returns>
        public async Task <TvShow> GetTvShowAsync(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, string language = null)
        {
            if (extraMethods.HasFlag(TvShowMethods.AccountStates))
            {
                RequireSessionId(SessionType.UserSession);
            }

            RestRequest req = _client.Create("tv/{id}");

            req.AddUrlSegment("id", id.ToString(CultureInfo.InvariantCulture));

            if (extraMethods.HasFlag(TvShowMethods.AccountStates))
            {
                AddSessionId(req, SessionType.UserSession);
            }

            language = language ?? DefaultLanguage;
            if (!string.IsNullOrWhiteSpace(language))
            {
                req.AddParameter("language", language);
            }

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(TvShowMethods))
                                         .OfType <TvShowMethods>()
                                         .Except(new[] { TvShowMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

            if (appends != string.Empty)
            {
                req.AddParameter("append_to_response", appends);
            }

            RestResponse <TvShow> response = await req.ExecuteGet <TvShow>().ConfigureAwait(false);

            TvShow item = await response.GetDataObject().ConfigureAwait(false);

            // No data to patch up so return
            if (item == null)
            {
                return(null);
            }

            // Patch up data, so that the end user won't notice that we share objects between request-types.
            if (item.Translations != null)
            {
                item.Translations.Id = id;
            }

            if (item.AccountStates != null)
            {
                item.AccountStates.Id = item.Id;
                // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
                CustomDeserialization.DeserializeAccountStatesRating(item.AccountStates, await response.GetContent().ConfigureAwait(false));
            }

            return(item);
        }
Пример #2
0
        /// <summary>
        /// Retrieves all information for a specific tv show in relation to the current user account
        /// </summary>
        /// <param name="tvShowId">The id of the tv show to get the account states for</param>
        /// <remarks>Requires a valid user session</remarks>
        /// <exception cref="UserSessionRequiredException">Thrown when the current client object doens't have a user session assigned.</exception>
        public async Task <AccountState> GetTvShowAccountState(int tvShowId)
        {
            RequireSessionId(SessionType.UserSession);

            RestRequest request = new RestRequest("tv/{tvShowId}/{method}");

            request.AddUrlSegment("tvShowId", tvShowId.ToString(CultureInfo.InvariantCulture));
            request.AddUrlSegment("method", TvShowMethods.AccountStates.GetDescription());
            request.AddParameter("session_id", SessionId);

            IRestResponse <AccountState> response = await _client.ExecuteGetTaskAsync <AccountState>(request);

            // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
            if (response.Data != null)
            {
                CustomDeserialization.DeserializeAccountStatesRating(response.Data, response.Content);
            }

            return(response.Data);
        }
Пример #3
0
        public ResultContainer <TvEpisodeAccountState> GetTvSeasonAccountState(int tvShowId, int seasonNumber)
        {
            RequireSessionId(SessionType.UserSession);

            RestRequest req = new RestRequest("tv/{id}/season/{season_number}/account_states");

            req.AddUrlSegment("id", tvShowId.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("season_number", seasonNumber.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("method", MovieMethods.AccountStates.GetDescription());
            req.AddParameter("session_id", SessionId);

            IRestResponse <ResultContainer <TvEpisodeAccountState> > response = _client.Get <ResultContainer <TvEpisodeAccountState> >(req);

            // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
            if (response.Data != null)
            {
                CustomDeserialization.DeserializeAccountStatesRating(response.Data, response.Content);
            }

            return(response.Data);
        }
Пример #4
0
        /// <summary>
        /// Retrieves all information for a specific movie in relation to the current user account
        /// </summary>
        /// <param name="movieId">The id of the movie to get the account states for</param>
        /// <remarks>Requires a valid user session</remarks>
        /// <exception cref="UserSessionRequiredException">Thrown when the current client object doens't have a user session assigned.</exception>
        public async Task <AccountState> GetMovieAccountStateAsync(int movieId)
        {
            RequireSessionId(SessionType.UserSession);

            RestRequest req = _client.Create("movie/{movieId}/{method}");

            req.AddUrlSegment("movieId", movieId.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("method", MovieMethods.AccountStates.GetDescription());
            AddSessionId(req, SessionType.UserSession);

            RestResponse <AccountState> response = await req.ExecuteGet <AccountState>().ConfigureAwait(false);

            AccountState item = await response.GetDataObject().ConfigureAwait(false);

            // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
            if (item != null)
            {
                CustomDeserialization.DeserializeAccountStatesRating(item, await response.GetContent().ConfigureAwait(false));
            }

            return(item);
        }
Пример #5
0
        public async Task <ResultContainer <TvEpisodeAccountState> > GetTvSeasonAccountStateAsync(int tvShowId, int seasonNumber)
        {
            RequireSessionId(SessionType.UserSession);

            RestRequest req = _client.Create("tv/{id}/season/{season_number}/account_states");

            req.AddUrlSegment("id", tvShowId.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("season_number", seasonNumber.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("method", TvEpisodeMethods.AccountStates.GetDescription());
            AddSessionId(req, SessionType.UserSession);

            RestResponse <ResultContainer <TvEpisodeAccountState> > response = await req.ExecuteGet <ResultContainer <TvEpisodeAccountState> >().ConfigureAwait(false);

            ResultContainer <TvEpisodeAccountState> item = await response.GetDataObject().ConfigureAwait(false);

            // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
            if (item != null)
            {
                CustomDeserialization.DeserializeAccountStatesRating(item, await response.GetContent().ConfigureAwait(false));
            }

            return(item);
        }
Пример #6
0
        /// <summary>
        /// Retrieve a season for a specifc tv Show by id.
        /// </summary>
        /// <param name="tvShowId">TMDb id of the tv show the desired season belongs to.</param>
        /// <param name="seasonNumber">The season number of the season you want to retrieve. Note use 0 for specials.</param>
        /// <param name="extraMethods">Enum flags indicating any additional data that should be fetched in the same request.</param>
        /// <param name="language">If specified the api will attempt to return a localized result. ex: en,it,es </param>
        /// <returns>The requested season for the specified tv show</returns>
        public async Task <TvSeason> GetTvSeasonAsync(int tvShowId, int seasonNumber, TvSeasonMethods extraMethods = TvSeasonMethods.Undefined, string language = null)
        {
            if (extraMethods.HasFlag(TvSeasonMethods.AccountStates))
            {
                RequireSessionId(SessionType.UserSession);
            }

            RestRequest req = _client.Create("tv/{id}/season/{season_number}");

            req.AddUrlSegment("id", tvShowId.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("season_number", seasonNumber.ToString(CultureInfo.InvariantCulture));

            if (extraMethods.HasFlag(TvSeasonMethods.AccountStates))
            {
                AddSessionId(req, SessionType.UserSession);
            }

            language = language ?? DefaultLanguage;
            if (!string.IsNullOrWhiteSpace(language))
            {
                req.AddParameter("language", language);
            }

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(TvSeasonMethods))
                                         .OfType <TvSeasonMethods>()
                                         .Except(new[] { TvSeasonMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

            if (appends != string.Empty)
            {
                req.AddParameter("append_to_response", appends);
            }

            RestResponse <TvSeason> response = await req.ExecuteGet <TvSeason>().ConfigureAwait(false);

            TvSeason item = await response.GetDataObject().ConfigureAwait(false);

            // Nothing to patch up
            if (item == null)
            {
                return(null);
            }

            if (item.Episodes != null)
            {
                item.EpisodeCount = item.Episodes.Count;
            }

            if (item.Credits != null)
            {
                item.Credits.Id = item.Id ?? 0;
            }

            if (item.ExternalIds != null)
            {
                item.ExternalIds.Id = item.Id ?? 0;
            }

            if (item.AccountStates != null)
            {
                item.AccountStates.Id = item.Id ?? 0;
                // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
                CustomDeserialization.DeserializeAccountStatesRating(item.AccountStates, await response.GetContent().ConfigureAwait(false));
            }

            return(item);
        }
Пример #7
0
        /// <summary>
        /// Retrieves a movie by it's imdb Id
        /// </summary>
        /// <param name="imdbId">The Imdb id of the movie OR the TMDb id as string</param>
        /// <param name="language">Language to localize the results in.</param>
        /// <param name="extraMethods">A list of additional methods to execute for this request as enum flags</param>
        /// <returns>The requested movie or null if it could not be found</returns>
        /// <remarks>Requires a valid user session when specifying the extra method 'AccountStates' flag</remarks>
        /// <exception cref="UserSessionRequiredException">Thrown when the current client object doens't have a user session assigned, see remarks.</exception>
        public Movie GetMovie(string imdbId, string language, MovieMethods extraMethods = MovieMethods.Undefined)
        {
            if (extraMethods.HasFlag(MovieMethods.AccountStates))
            {
                RequireSessionId(SessionType.UserSession);
            }

            RestRequest request = new RestRequest("movie/{movieId}");

            request.AddUrlSegment("movieId", imdbId);
            if (extraMethods.HasFlag(MovieMethods.AccountStates))
            {
                request.AddParameter("session_id", SessionId);
            }

            if (language != null)
            {
                request.AddParameter("language", language);
            }

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(MovieMethods))
                                         .OfType <MovieMethods>()
                                         .Except(new[] { MovieMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

            if (appends != string.Empty)
            {
                request.AddParameter("append_to_response", appends);
            }

            IRestResponse <Movie> response = _client.Get <Movie>(request);

            // No data to patch up so return
            if (response.Data == null)
            {
                return(null);
            }

            // Patch up data, so that the end user won't notice that we share objects between request-types.
            if (response.Data.Videos != null)
            {
                response.Data.Videos.Id = response.Data.Id;
            }

            if (response.Data.AlternativeTitles != null)
            {
                response.Data.AlternativeTitles.Id = response.Data.Id;
            }

            if (response.Data.Credits != null)
            {
                response.Data.Credits.Id = response.Data.Id;
            }

            if (response.Data.Releases != null)
            {
                response.Data.Releases.Id = response.Data.Id;
            }

            if (response.Data.Keywords != null)
            {
                response.Data.Keywords.Id = response.Data.Id;
            }

            if (response.Data.Translations != null)
            {
                response.Data.Translations.Id = response.Data.Id;
            }

            if (response.Data.AccountStates != null)
            {
                response.Data.AccountStates.Id = response.Data.Id;
                // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
                CustomDeserialization.DeserializeAccountStatesRating(response.Data.AccountStates, response.Content);
            }

            return(response.Data);
        }
Пример #8
0
        /// <summary>
        /// Retrieves a movie by it's imdb Id
        /// </summary>
        /// <param name="imdbId">The Imdb id of the movie OR the TMDb id as string</param>
        /// <param name="language">Language to localize the results in.</param>
        /// <param name="extraMethods">A list of additional methods to execute for this req as enum flags</param>
        /// <returns>The reqed movie or null if it could not be found</returns>
        /// <remarks>Requires a valid user session when specifying the extra method 'AccountStates' flag</remarks>
        /// <exception cref="UserSessionRequiredException">Thrown when the current client object doens't have a user session assigned, see remarks.</exception>
        public async Task <Movie> GetMovieAsync(string imdbId, string language, MovieMethods extraMethods = MovieMethods.Undefined)
        {
            if (extraMethods.HasFlag(MovieMethods.AccountStates))
            {
                RequireSessionId(SessionType.UserSession);
            }

            RestRequest req = _client.Create("movie/{movieId}");

            req.AddUrlSegment("movieId", imdbId);
            if (extraMethods.HasFlag(MovieMethods.AccountStates))
            {
                AddSessionId(req, SessionType.UserSession);
            }

            if (language != null)
            {
                req.AddParameter("language", language);
            }

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(MovieMethods))
                                         .OfType <MovieMethods>()
                                         .Except(new[] { MovieMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

            if (appends != string.Empty)
            {
                req.AddParameter("append_to_response", appends);
            }

            RestResponse <Movie> response = await req.ExecuteGet <Movie>().ConfigureAwait(false);

            // No data to patch up so return
            if (response == null)
            {
                return(null);
            }

            Movie item = await response.GetDataObject().ConfigureAwait(false);

            // Patch up data, so that the end user won't notice that we share objects between req-types.
            if (item.Videos != null)
            {
                item.Videos.Id = item.Id;
            }

            if (item.AlternativeTitles != null)
            {
                item.AlternativeTitles.Id = item.Id;
            }

            if (item.Credits != null)
            {
                item.Credits.Id = item.Id;
            }

            if (item.Releases != null)
            {
                item.Releases.Id = item.Id;
            }

            if (item.Keywords != null)
            {
                item.Keywords.Id = item.Id;
            }

            if (item.Translations != null)
            {
                item.Translations.Id = item.Id;
            }

            // Overview is the only field that is HTML encoded from the source.
            item.Overview = WebUtility.HtmlDecode(item.Overview);

            if (item.AccountStates != null)
            {
                item.AccountStates.Id = item.Id;
                // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
                CustomDeserialization.DeserializeAccountStatesRating(item.AccountStates, await response.GetContent().ConfigureAwait(false));
            }

            return(item);
        }
Пример #9
0
        /// <summary>
        /// Retrieve a specific episode using TMDb id of the associated tv show.
        /// </summary>
        /// <param name="tvShowId">TMDb id of the tv show the desired episode belongs to.</param>
        /// <param name="seasonNumber">The season number of the season the episode belongs to. Note use 0 for specials.</param>
        /// <param name="episodeNumber">The episode number of the episode you want to retrieve.</param>
        /// <param name="extraMethods">Enum flags indicating any additional data that should be fetched in the same request.</param>
        /// <param name="language">If specified the api will attempt to return a localized result. ex: en,it,es </param>
        public TvEpisode GetTvEpisode(int tvShowId, int seasonNumber, int episodeNumber, TvEpisodeMethods extraMethods = TvEpisodeMethods.Undefined, string language = null)
        {
            if (extraMethods.HasFlag(TvEpisodeMethods.AccountStates))
            {
                RequireSessionId(SessionType.UserSession);
            }

            RestRequest request = new RestRequest("tv/{id}/season/{season_number}/episode/{episode_number}");

            request.AddUrlSegment("id", tvShowId.ToString(CultureInfo.InvariantCulture));
            request.AddUrlSegment("season_number", seasonNumber.ToString(CultureInfo.InvariantCulture));
            request.AddUrlSegment("episode_number", episodeNumber.ToString(CultureInfo.InvariantCulture));

            if (extraMethods.HasFlag(TvEpisodeMethods.AccountStates))
            {
                request.AddParameter("session_id", SessionId);
            }

            language = language ?? DefaultLanguage;
            if (!String.IsNullOrWhiteSpace(language))
            {
                request.AddParameter("language", language);
            }

            string appends = string.Join(",",
                                         Enum.GetValues(typeof(TvEpisodeMethods))
                                         .OfType <TvEpisodeMethods>()
                                         .Except(new[] { TvEpisodeMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

            if (appends != string.Empty)
            {
                request.AddParameter("append_to_response", appends);
            }

            IRestResponse <TvEpisode> response = _client.Get <TvEpisode>(request);

            // No data to patch up so return
            if (response.Data == null)
            {
                return(null);
            }

            // Patch up data, so that the end user won't notice that we share objects between request-types.
            if (response.Data.Videos != null)
            {
                response.Data.Videos.Id = response.Data.Id ?? 0;
            }

            if (response.Data.Credits != null)
            {
                response.Data.Credits.Id = response.Data.Id ?? 0;
            }

            if (response.Data.Images != null)
            {
                response.Data.Images.Id = response.Data.Id ?? 0;
            }

            if (response.Data.ExternalIds != null)
            {
                response.Data.ExternalIds.Id = response.Data.Id ?? 0;
            }

            if (response.Data.AccountStates != null)
            {
                response.Data.AccountStates.Id = response.Data.Id ?? 0;
                // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
                CustomDeserialization.DeserializeAccountStatesRating(response.Data.AccountStates, response.Content);
            }

            return(response.Data);
        }