/// <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>
        /// <param name="cancellationToken">A cancellation token</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, CancellationToken cancellationToken = default(CancellationToken))
        {
            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>(cancellationToken).ConfigureAwait(false);

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

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

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

            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;
            }

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

            return(item);
        }
Beispiel #2
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 TvSeason GetTvSeason(int tvShowId, int seasonNumber, TvSeasonMethods extraMethods = TvSeasonMethods.Undefined, string language = null)
        {
            if (extraMethods.HasFlag(TvSeasonMethods.AccountStates))
            {
                RequireSessionId(SessionType.UserSession);
            }

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

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

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

            language = language ?? DefaultLanguage;
            if (!String.IsNullOrWhiteSpace(language))
            {
                request.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)
            {
                request.AddParameter("append_to_response", appends);
            }

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

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

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

            if (response.Data.Credits != null)
            {
                response.Data.Credits.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);
        }