Esempio n. 1
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)
        {
            RestRequest req = new RestRequest("tv/{id}/season/{season_number}/episode/{episode_number}");

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

            if (language != null)
            {
                req.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)
            {
                req.AddParameter("append_to_response", appends);
            }

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

            return(response.Data);
        }
Esempio n. 2
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)
        {
            RestRequest req = new RestRequest("tv/{id}/season/{season_number}/episode/{episode_number}");

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

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

            IRestResponse <TvEpisode> response = _client.Get <TvEpisode>(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.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;
            }

            return(response.Data);
        }
Esempio n. 3
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>
        /// <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>
        public async Task <TvEpisode> GetTvEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, TvEpisodeMethods extraMethods = TvEpisodeMethods.Undefined, string language = null, string includeImageLanguage = null, CancellationToken cancellationToken = default)
        {
            if (extraMethods.HasFlag(TvEpisodeMethods.AccountStates))
            {
                RequireSessionId(SessionType.UserSession);
            }

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

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

            if (extraMethods.HasFlag(TvEpisodeMethods.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(TvEpisodeMethods))
                                         .OfType <TvEpisodeMethods>()
                                         .Except(new[] { TvEpisodeMethods.Undefined })
                                         .Where(s => extraMethods.HasFlag(s))
                                         .Select(s => s.GetDescription()));

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

            RestResponse <TvEpisode> response = await req.Get <TvEpisode>(cancellationToken).ConfigureAwait(false);

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

            TvEpisode 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.Videos != null)
            {
                item.Videos.Id = item.Id ?? 0;
            }

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

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

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

            return(item);
        }
        /// <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);
        }