Beispiel #1
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);
        }
Beispiel #2
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;
            }

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

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

            return(item);
        }
Beispiel #3
0
        public Movie GetMovie(string imdbId, string language, MovieMethods extraMethods = MovieMethods.Undefined)
        {
            var req = new RestRequest("movie/{movieId}");

            req.AddUrlSegment("movieId", imdbId);

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

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

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

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

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

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

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

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

            return(resp.Data);
        }