示例#1
0
        private async Task <T> GetTvShowMethod <T>(int id, TvShowMethods tvShowMethod, string dateFormat = null, string language = null, string includeImageLanguage = null, int page = 0, CancellationToken cancellationToken = default(CancellationToken)) where T : new()
        {
            RestRequest req = _client.Create("tv/{id}/{method}");

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

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

            if (page > 0)
            {
                req.AddParameter("page", page.ToString());
            }

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

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

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

            return(resp);
        }
示例#2
0
        public async Task <TvShowContainer> GetTvShowAsync(int tvShowId, CancellationToken cancellationToken)
        {
            TvShowContainer container = TvShows.FindById(tvShowId);

            if (container != null)
            {
                return(container);
            }

            TvShowMethods methods    = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Videos | TvShowMethods.Translations | TvShowMethods.Keywords | TvShowMethods.ExternalIds;
            TvShow        tmdbResult = await TMDbClient.GetTvShowAsync(tvShowId, methods, cancellationToken);

            container = new TvShowContainer(tmdbResult);

            ImdbHelper.GetImdbInfo(tmdbResult.ExternalIds.ImdbId).ContinueWith(x =>
            {
                if (x.IsCompleted && !x.IsFaulted && x.Result != null)
                {
                    container.Votes      = x.Result.Resource.RatingCount;
                    container.ImdbRating = x.Result.Resource.Rating;

                    if (x.Result.Resource.OtherRanks?.Length > 0)
                    {
                        container.TopRating = x.Result.Resource.OtherRanks[0].Rank;
                    }
                }
            }, TaskScheduler.FromCurrentSynchronizationContext()).LogIfFaulted();

            return(container);
        }
示例#3
0
        private T GetTvShowMethod <T>(int id, TvShowMethods tvShowMethod, string dateFormat = null, string language = null, int page = 0) where T : new()
        {
            RestRequest req = new RestRequest("tv/{id}/{method}");

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

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

            if (page > 0)
            {
                req.AddParameter("page", page);
            }

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

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

            return(resp.Data);
        }
        /// <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 TvShow GetTvShow(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, string language = null)
        {
            RestRequest req = new RestRequest("tv/{id}");

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

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

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

            return(response.Data);
        }
        /// <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);
        }
示例#6
0
        public void TestTvShowExtrasAll()
        {
            TvShowMethods combinedEnum = _methods.Keys.Aggregate((methods, tvShowMethods) => methods | tvShowMethods);
            TvShow        tvShow       = _config.Client.GetTvShow(BreakingBad, combinedEnum);

            TestBreakingBadBaseProperties(tvShow);

            TestMethodsHelper.TestAllNotNull(_methods, tvShow);
        }
示例#7
0
        public void TestTvShowExtrasAll()
        {
            _config.Client.SetSessionInformation(_config.UserSessionId, SessionType.UserSession);

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

            TvShowMethods combinedEnum = _methods.Keys.Aggregate((methods, tvShowMethods) => methods | tvShowMethods);
            TvShow        tvShow       = _config.Client.GetTvShow(BreakingBad, combinedEnum).Result;

            TestBreakingBadBaseProperties(tvShow);

            TestMethodsHelper.TestAllNotNull(_methods, tvShow);
        }
示例#8
0
        public void TestTvShowExtrasAll()
        {
            IgnoreMissingJson(" / id");
            IgnoreMissingJson(" / genre_ids", " / known_for", " / similar", " / translations", " / videos", "alternative_titles / id", "content_ratings / id", "credits / id", "external_ids / id", "keywords / id", " / recommendations");

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

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

            TvShowMethods combinedEnum = _methods.Keys.Aggregate((methods, tvShowMethods) => methods | tvShowMethods);
            TvShow        tvShow       = Config.Client.GetTvShowAsync(IdHelper.BreakingBad, combinedEnum).Result;

            TestBreakingBadBaseProperties(tvShow);

            TestMethodsHelper.TestAllNotNull(_methods, tvShow);
        }
示例#9
0
        public async Task UpdateTvShowAsync(TvShowContainer container, CancellationToken cancellationToken)
        {
            TvShowMethods methods    = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Videos | TvShowMethods.Translations | TvShowMethods.Keywords | TvShowMethods.ExternalIds;
            TvShow        tmdbResult = await TMDbClient.GetTvShowAsync(container.Id, methods, cancellationToken);

            container.Item = tmdbResult;

            ImdbInfo imdbInfo = await ImdbHelper.GetImdbInfo(tmdbResult.ExternalIds.ImdbId);

            container.Votes      = imdbInfo.Resource.RatingCount;
            container.ImdbRating = imdbInfo.Resource.Rating;

            if (imdbInfo.Resource.OtherRanks?.Length > 0)
            {
                container.TopRating = imdbInfo.Resource.OtherRanks[0].Rank;
            }

            TvShows.Update(container);
        }
示例#10
0
        private T GetTvShowMethod <T>(int id, TvShowMethods tvShowMethod, string dateFormat = null, string language = null) where T : new()
        {
            var req = new RestRequest("tv/{id}/{method}");

            req.AddUrlSegment("id", id.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);
        }
示例#11
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 TvShow GetTvShow(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, string language = null)
        {
            RestRequest req = new RestRequest("tv/{id}");

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

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

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

            // 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.Translations != null)
            {
                response.Data.Translations.Id = id;
            }

            return(response.Data);
        }
示例#12
0
        private async Task <T> GetTvShowMethod <T>(int id, TvShowMethods tvShowMethod, string dateFormat         = null, string language = null, int page = 0,
                                                   IEnumerable <KeyValuePair <string, string> > customParameters = null) where T : new()
        {
            RestRequest req = new RestRequest("tv/{id}/{method}");

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

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

            if (page > 0)
            {
                req.AddParameter("page", page);
            }

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

            // add custom args
            if (customParameters != null)
            {
                foreach (var p in customParameters)
                {
                    req.AddParameter(p.Key, p.Value);
                }
            }

            IRestResponse <T> resp = await _client.ExecuteGetTaskAsync <T>(req).ConfigureAwait(false);

            return(resp.Data);
        }
示例#13
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>
        /// <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 Tv Show</returns>
        public async Task <TvShow> GetTvShowAsync(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, string language = null, string includeImageLanguage = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            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);
            }

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

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

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

            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 (string.IsNullOrWhiteSpace(item.Overview))
            {
                item.Overview = "N/A";
            }

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

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

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

            return(item);
        }
示例#14
0
 public async Task <TvShow> GetTVShowAsync(int showId, TvShowMethods extraMethods = TvShowMethods.Undefined, CancellationToken cancellationToken = default)
 {
     return(await TMDbServiceClient.Instance.GetTvShowAsync(showId, extraMethods, null, null, cancellationToken));
 }
示例#15
0
 public async Task <TvShow> GetTvShowAsync(int id, TvShowMethods extraMethods = TvShowMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await GetTvShowAsync(id, extraMethods, DefaultLanguage, cancellationToken));
 }
示例#16
0
 public static TvShow GetTvShow(this TMDbClient client, int movieID, TvShowMethods method,
                                string language = null)
 {
     return(Task.Run(async() => await client.GetTvShowAsync(movieID, method, language)).Result);
 }