public async Task <MovieContainer> GetMovieAsync(int movieId, CancellationToken cancellationToken) { MovieContainer container = Movies.FindById(movieId); if (container != null) { return(container); } MovieMethods methods = MovieMethods.Credits | MovieMethods.Images | MovieMethods.Videos | MovieMethods.Translations | MovieMethods.Keywords; Movie tmdbResult = await TMDbClient.GetMovieAsync(movieId, methods, cancellationToken); container = new MovieContainer(tmdbResult); ImdbHelper.GetImdbInfo(tmdbResult.ImdbId).ContinueWith(x => { if (x.IsCompleted && !x.IsFaulted && x.Result != null) { container.Votes = x.Result.Resource.RatingCount; container.TopRating = x.Result.Resource.TopRank; container.ImdbRating = x.Result.Resource.Rating; } }, TaskScheduler.FromCurrentSynchronizationContext()).LogIfFaulted(); return(container); }
public void TestMoviesExtrasAll() { MovieMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Movie item = _config.Client.GetMovie(AGoodDayToDieHard, combinedEnum); TestMethodsHelper.TestAllNotNull(_methods, item); }
public void TestMoviesExtrasAll() { _config.Client.SetSessionInformation(_config.UserSessionId, SessionType.UserSession); MovieMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Movie item = _config.Client.GetMovie(AGoodDayToDieHard, combinedEnum); TestMethodsHelper.TestAllNotNull(_methods, item); }
public void TestMoviesImdbExtrasAll() { Dictionary <MovieMethods, Func <Movie, object> > tmpMethods = new Dictionary <MovieMethods, Func <Movie, object> >(_methods); tmpMethods.Remove(MovieMethods.Changes); tmpMethods.Remove(MovieMethods.SimilarMovies); // See https://github.com/LordMike/TMDbLib/issues/19 MovieMethods combinedEnum = tmpMethods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Movie item = _config.Client.GetMovie(AGoodDayToDieHardImdb, combinedEnum); TestMethodsHelper.TestAllNotNull(tmpMethods, item); }
public void TestMoviesExtrasAll() { // We ignore the 'notes' field, as TMDb sometimes leaves it out IgnoreMissingJson("release_dates.results[array].release_dates[array] / note"); IgnoreMissingJson(" / id", "alternative_titles / id", "credits / id", "keywords / id", "release_dates / id", "releases / id", "translations / id", "videos / id"); Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); MovieMethods combinedEnum = _methods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Movie item = Config.Client.GetMovieAsync(IdHelper.AGoodDayToDieHard, combinedEnum).Result; TestMethodsHelper.TestAllNotNull(_methods, item); }
public void TestMoviesImdbExtrasAll() { Dictionary <MovieMethods, Func <Movie, object> > tmpMethods = new Dictionary <MovieMethods, Func <Movie, object> >(_methods); tmpMethods.Remove(MovieMethods.Videos); _config.Client.SetSessionInformation(_config.UserSessionId, SessionType.UserSession); MovieMethods combinedEnum = tmpMethods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Movie item = _config.Client.GetMovie(TheDarkKnightRisesImdb, combinedEnum); TestMethodsHelper.TestAllNotNull(tmpMethods, item); }
private async Task <T> GetMovieMethod <T>(int movieId, MovieMethods movieMethod, string dateFormat = null, string country = null, string language = null, int page = 0, DateTime?startDate = null, DateTime?endDate = null, IEnumerable <KeyValuePair <string, string> > customParameters = null) where T : new() { RestRequest request = new RestRequest("movie/{movieId}/{method}"); request.AddUrlSegment("movieId", movieId.ToString(CultureInfo.InvariantCulture)); request.AddUrlSegment("method", movieMethod.GetDescription()); if (dateFormat != null) { request.DateFormat = dateFormat; } if (country != null) { request.AddParameter("country", country); } language = language ?? DefaultLanguage; if (!String.IsNullOrWhiteSpace(language)) { request.AddParameter("language", language); } if (page >= 1) { request.AddParameter("page", page); } if (startDate.HasValue) { request.AddParameter("start_date", startDate.Value.ToString("yyyy-MM-dd")); } if (endDate != null) { request.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd")); } // add custom args if (customParameters != null) { foreach (var p in customParameters) { request.AddParameter(p.Key, p.Value); } } IRestResponse <T> response = await _client.ExecuteGetTaskAsync <T>(request).ConfigureAwait(false); return(response.Data); }
public async Task UpdateMovieAsync(MovieContainer container, CancellationToken cancellationToken) { MovieMethods methods = MovieMethods.Credits | MovieMethods.Images | MovieMethods.Videos | MovieMethods.Translations | MovieMethods.Keywords; Movie tmdbResult = await TMDbClient.GetMovieAsync(container.Id, methods, cancellationToken); container.Item = tmdbResult; ImdbInfo imdbInfo = await ImdbHelper.GetImdbInfo(tmdbResult.ImdbId); container.Votes = imdbInfo.Resource.RatingCount; container.TopRating = imdbInfo.Resource.TopRank; container.ImdbRating = imdbInfo.Resource.Rating; Movies.Update(container); }
public async Task <IActionResult> AddToWLAsync([FromHeader] string Authorization, [FromBody] UserCred userCred) { string email = tokenObj.GetNameClaims(Authorization); int movie = userCred.MovieId; Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (email == "" || movie == 0) { dictionary.Add("Message:", "Not Found"); dictionary.Add("Description:", "Please enter all fields"); return(NotFound(JsonConvert.SerializeObject(dictionary, Formatting.Indented))); } if (await WatchListMethods.IsInList(email, movie) == true) { dictionary.Add("Message:", "Not Found"); dictionary.Add("Description:", "Please enter all fields"); return(NotFound(JsonConvert.SerializeObject(dictionary, Formatting.Indented))); } if (UserMethods.getUser(email) == null) { dictionary.Add("Message:", "Not Found"); dictionary.Add("Description:", "User not found"); return(NotFound(JsonConvert.SerializeObject(dictionary, Formatting.Indented))); } MovieFirebase retMov = await MovieMethods.GetMovie(movie); if (retMov.id == 0) { dictionary.Add("Message:", " Not Found"); dictionary.Add("Description:", "Movie Not Found"); return(NotFound(JsonConvert.SerializeObject(dictionary, Formatting.Indented))); } if (!(await WatchListMethods.insertInWLAsync(email, movie))) { dictionary.Add("Message:", "NotFound"); dictionary.Add("Description:", "Something went wrong"); return(NotFound(JsonConvert.SerializeObject(dictionary, Formatting.Indented))); } return(Ok(JsonConvert.SerializeObject(retMov, Formatting.Indented))); }
public void TestMoviesImdbExtrasAll() { Dictionary <MovieMethods, Func <Movie, object> > tmpMethods = new Dictionary <MovieMethods, Func <Movie, object> >(_methods); tmpMethods.Remove(MovieMethods.Videos); _config.Client.SetSessionInformation(_config.UserSessionId, SessionType.UserSession); // Account states will only show up if we've done something _config.Client.MovieSetRating(TheDarkKnightRises, 5); MovieMethods combinedEnum = tmpMethods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Movie item = _config.Client.GetMovie(TheDarkKnightRises, combinedEnum).Result; TestMethodsHelper.TestAllNotNull(tmpMethods, item); }
public async Task <IActionResult> getMovieAsync(int id) { MovieFirebase movie = await MovieMethods.GetMovie(id); Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (movie.id == 0) { dictionary.Add("Message:", "Not Found"); dictionary.Add("Description:", "Movie not found"); return(NotFound(JsonConvert.SerializeObject(dictionary, Formatting.Indented))); } string json = JsonConvert.SerializeObject(movie, Formatting.Indented); return(Ok(json)); }
public void TestMoviesImdbExtrasAll() { IgnoreMissingJson(" / id", " / videos", "alternative_titles / id", "credits / id", "keywords / id", "release_dates / id", "releases / id", "reviews.results[array] / media_type", "translations / id"); Dictionary <MovieMethods, Func <Movie, object> > tmpMethods = new Dictionary <MovieMethods, Func <Movie, object> >(_methods); tmpMethods.Remove(MovieMethods.Videos); Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession); // Account states will only show up if we've done something Config.Client.MovieSetRatingAsync(IdHelper.TheDarkKnightRises, 5).Sync(); MovieMethods combinedEnum = tmpMethods.Keys.Aggregate((methods, movieMethods) => methods | movieMethods); Movie item = Config.Client.GetMovieAsync(IdHelper.TheDarkKnightRises, combinedEnum).Result; TestMethodsHelper.TestAllNotNull(tmpMethods, item); }
public async Task <IActionResult> SearchMovieQueryAsync(string query) { List <MovieFirebase> movies = new List <MovieFirebase>(); movies = await MovieMethods.SearchMovie(query); Dictionary <string, string> dictionary = new Dictionary <string, string>(); if (movies.Count == 0) { dictionary.Add("Message:", "Not Found"); dictionary.Add("Description:", "Didnt find movies"); return(NotFound(JsonConvert.SerializeObject(dictionary, Formatting.Indented))); } string json = JsonConvert.SerializeObject(movies, Formatting.Indented); return(Ok(json)); }
private async Task <T> GetMovieMethodInternal <T>(int movieId, MovieMethods movieMethod, string dateFormat = null, string country = null, string language = null, string includeImageLanguage = null, int page = 0, DateTime?startDate = null, DateTime?endDate = null, CancellationToken cancellationToken = default) where T : new() { RestRequest req = _client.Create("movie/{movieId}/{method}"); req.AddUrlSegment("movieId", movieId.ToString(CultureInfo.InvariantCulture)); req.AddUrlSegment("method", movieMethod.GetDescription()); if (country != null) { req.AddParameter("country", country); } language ??= DefaultLanguage; if (!string.IsNullOrWhiteSpace(language)) { req.AddParameter("language", language); } if (!string.IsNullOrWhiteSpace(includeImageLanguage)) { req.AddParameter("include_image_language", includeImageLanguage); } if (page >= 1) { req.AddParameter("page", page.ToString()); } if (startDate.HasValue) { req.AddParameter("start_date", startDate.Value.ToString("yyyy-MM-dd")); } if (endDate != null) { req.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd")); } T response = await req.GetOfT <T>(cancellationToken).ConfigureAwait(false); return(response); }
private T GetMovieMethod <T>(int movieId, MovieMethods movieMethod, string dateFormat = null, string country = null, string language = null, int page = 0, DateTime?startDate = null, DateTime?endDate = null) where T : new() { RestRequest request = new RestRequest("movie/{movieId}/{method}"); request.AddUrlSegment("movieId", movieId.ToString(CultureInfo.InvariantCulture)); request.AddUrlSegment("method", movieMethod.GetDescription()); if (dateFormat != null) { request.DateFormat = dateFormat; } if (country != null) { request.AddParameter("country", country); } language = language ?? DefaultLanguage; if (!String.IsNullOrWhiteSpace(language)) { request.AddParameter("language", language); } if (page >= 1) { request.AddParameter("page", page); } if (startDate.HasValue) { request.AddParameter("start_date", startDate.Value.ToString("yyyy-MM-dd")); } if (endDate != null) { request.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd")); } IRestResponse <T> response = _client.Get <T>(request); return(response.Data); }
private T GetMovieMethod <T>(int movieId, MovieMethods movieMethod, string dateFormat = null, string country = null, string language = null, int page = 0, DateTime?startDate = null, DateTime?endDate = null) where T : new() { var req = new RestRequest("movie/{movieId}/{method}"); req.AddUrlSegment("movieId", movieId.ToString()); req.AddUrlSegment("method", movieMethod.GetDescription()); if (dateFormat != null) { req.DateFormat = dateFormat; } if (country != null) { req.AddParameter("country", country); } if (language != null) { req.AddParameter("language", language); } if (page >= 1) { req.AddParameter("page", page); } if (startDate.HasValue) { req.AddParameter("start_date", startDate.Value.ToString("yyyy-MM-dd")); } if (endDate != null) { req.AddParameter("end_date", endDate.Value.ToString("yyyy-MM-dd")); } IRestResponse <T> resp = _client.Get <T>(req); return(resp.Data); }
public async Task <Movie> GetMovieAsync(string imdbId, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { return(await GetMovieAsync(imdbId, DefaultLanguage, extraMethods, cancellationToken).ConfigureAwait(false)); }
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); }
/// <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); }
public Task <Movie> GetMovieAsync(int movieId, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default) { base.Track(); return(tmdbClient.GetMovieAsync(movieId, extraMethods, cancellationToken)); }
public async Task <Movie> GetMovieAsync(int movieId, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default) { return(await TMDbServiceClient.Instance.GetMovieAsync(movieId, extraMethods, cancellationToken)); }
public Movie GetMovie(int movieId, string language, MovieMethods extraMethods = MovieMethods.Undefined) { return(GetMovie(movieId.ToString(CultureInfo.InvariantCulture), language, extraMethods)); }
public async Task <Movie> GetMovieAsync(int movieId, string language, MovieMethods extraMethods = MovieMethods.Undefined) { return(await GetMovieAsync(movieId.ToString(CultureInfo.InvariantCulture), language, extraMethods).ConfigureAwait(false)); }
public async Task <Movie> GetMovieAsync(int movieId, string language, MovieMethods extraMethods = MovieMethods.Undefined, CancellationToken cancellationToken = default(CancellationToken)) { return(await GetMovieAsync(movieId.ToString(CultureInfo.InvariantCulture), language, extraMethods, cancellationToken).ConfigureAwait(false)); }
public static Movie GetMovie(this TMDbClient client, int movieID, MovieMethods methods = MovieMethods.Undefined) { return(Task.Run(async() => await client.GetMovieAsync(movieID, methods)).Result); }
public async Task <Movie> GetMovie(string imdbId, MovieMethods extraMethods = MovieMethods.Undefined) { return(await GetMovie(imdbId, DefaultLanguage, extraMethods)); }
public Movie GetMovie(int movieId, MovieMethods extraMethods = MovieMethods.Undefined) { return this.client.GetMovie(movieId, extraMethods); }
public async Task <Movie> GetMovieAsync(string imdbId, MovieMethods extraMethods = MovieMethods.Undefined) { return(await GetMovieAsync(imdbId, DefaultLanguage, extraMethods).ConfigureAwait(false)); }
public Movie GetMovie(int movieId, MovieMethods extraMethods = MovieMethods.Undefined) { return(GetMovie(movieId, DefaultLanguage, extraMethods)); }
/// <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); }
public Movie GetMovie(string imdbId, MovieMethods extraMethods = MovieMethods.Undefined) { return(GetMovie(imdbId, DefaultLanguage, extraMethods)); }