Пример #1
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)
        {
            var req = new RestRequest("tv/{id}/season/{season_number}");

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

            if (language != null)
            {
                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);
            }

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

            return(response.Data);
        }
Пример #2
0
        public async Task <TvSeason> GetTvSeasonAsync(int tvShowId, int seasonNumber, string language, CancellationToken cancellationToken)
        {
            TvSeasonMethods methods    = TvSeasonMethods.Credits | TvSeasonMethods.Images | TvSeasonMethods.Videos;
            TvSeason        tmdbResult = await TMDbClient.GetTvSeasonAsync(tvShowId, seasonNumber, methods, language, cancellationToken);

            return(tmdbResult);
        }
Пример #3
0
        public void TestTvSeasonExtrasAll()
        {
            TvSeasonMethods combinedEnum = _methods.Keys.Aggregate((methods, tvSeasonMethods) => methods | tvSeasonMethods);
            TvSeason        tvSeason     = _config.Client.GetTvSeason(BreakingBad, 1, combinedEnum);

            TestBreakingBadBaseProperties(tvSeason);

            TestMethodsHelper.TestAllNotNull(_methods, tvSeason);
        }
Пример #4
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)
        {
            RestRequest req = new RestRequest("tv/{id}/season/{season_number}");

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

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

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

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

            return(response.Data);
        }
        public void TestTvSeasonExtrasAll()
        {
            _config.Client.SetSessionInformation(_config.UserSessionId, SessionType.UserSession);

            // Account states will only show up if we've done something
            _config.Client.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 5).Wait();

            TvSeasonMethods combinedEnum = _methods.Keys.Aggregate((methods, tvSeasonMethods) => methods | tvSeasonMethods);
            TvSeason        tvSeason     = _config.Client.GetTvSeasonAsync(IdHelper.BreakingBad, 1, combinedEnum).Result;

            TestBreakingBadBaseProperties(tvSeason);

            TestMethodsHelper.TestAllNotNull(_methods, tvSeason);
        }
Пример #6
0
        public void TestTvSeasonExtrasAll()
        {
            // TMDb is sending an extra property
            IgnoreMissingCSharp("_id / _id");

            IgnoreMissingJson("images / id", "account_states / id", "credits / id", "external_ids / id", "videos / id");

            Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession);

            // Account states will only show up if we've done something
            Config.Client.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 5).Sync();

            TvSeasonMethods combinedEnum = _methods.Keys.Aggregate((methods, tvSeasonMethods) => methods | tvSeasonMethods);
            TvSeason        tvSeason     = Config.Client.GetTvSeasonAsync(IdHelper.BreakingBad, 1, combinedEnum).Result;

            TestBreakingBadBaseProperties(tvSeason);

            TestMethodsHelper.TestAllNotNull(_methods, tvSeason);
        }
Пример #7
0
        private async Task <T> GetTvSeasonMethod <T>(int tvShowId, int seasonNumber, TvSeasonMethods tvShowMethod, string dateFormat = null, string language = null) where T : new()
        {
            RestRequest req = new RestRequest("tv/{id}/season/{season_number}/{method}");

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

            if (dateFormat != null)
            {
                req.DateFormat = dateFormat;
            }

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

            return((await _client.ExecuteGetTaskAsync <T>(req).ConfigureAwait(false)).Data);
        }
Пример #8
0
        private async Task <T> GetTvSeasonMethod <T>(int tvShowId, int seasonNumber, TvSeasonMethods tvShowMethod, string dateFormat = null, string language = null) where T : new()
        {
            RestRequest req = _client.Create("tv/{id}/season/{season_number}/{method}");

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

            // TODO: Dateformat?
            //if (dateFormat != null)
            //    req.DateFormat = dateFormat;

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

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

            return(response);
        }
Пример #9
0
        private T GetTvSeasonMethod <T>(int tvShowId, int seasonNumber, TvSeasonMethods tvShowMethod, string dateFormat = null, string language = null) where T : new()
        {
            var req = new RestRequest("tv/{id}/season/{season_number}/{method}");

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

            if (dateFormat != null)
            {
                req.DateFormat = dateFormat;
            }

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

            IRestResponse <T> resp = _client.Get <T>(req);

            return(resp.Data);
        }
Пример #10
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);
        }
Пример #11
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>
        /// <param name="includeImageLanguage">If specified the api will attempt to return localized image results eg. 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, string includeImageLanguage = null, CancellationToken cancellationToken = default)
        {
            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 ??= DefaultLanguage;
            if (!string.IsNullOrWhiteSpace(language))
            {
                req.AddParameter("language", language);
            }

            includeImageLanguage ??= DefaultImageLanguage;
            if (!string.IsNullOrWhiteSpace(includeImageLanguage))
            {
                req.AddParameter("include_image_language", includeImageLanguage);
            }

            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.Get <TvSeason>(cancellationToken).ConfigureAwait(false);

            if (!response.IsValid)
            {
                return(null);
            }

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