//Insert data into MovieDetails table private void ProcessMovieDetails(OmdbApi omdbApi, int movieid) { List <string> langList = omdbApi.Language.Split(',').Select(l => l.Trim()).ToList(); MovieDetails movieDetails = db.MovieDetails.Where(m => m.MovieId.Equals(movieid)).FirstOrDefault(); bool exits = true; if (movieDetails == null) { exits = false; movieDetails = new MovieDetails(); } movieDetails.MovieId = movieid; movieDetails.Year = omdbApi.Year; movieDetails.Runtime = omdbApi.Runtime; movieDetails.Plot = omdbApi.Plot; movieDetails.Poster = omdbApi.Poster; movieDetails.Language = langList.First(); movieDetails.IMDBRating = omdbApi.IMDBRating; movieDetails.IMDBId = omdbApi.IMDBId; if (exits) { db.Entry(movieDetails).State = EntityState.Modified; } else { db.MovieDetails.Add(movieDetails); } db.SaveChanges(); }
/// <summary> /// Seeds the RavenDB database with movie data. /// </summary> /// <returns>The database async.</returns> /// <param name="overwrite">If set to <c>true</c> overwrite.</param> public static async Task SeedDatabaseAsync(bool overwrite = false) { var path = Path.Combine(Directory.GetCurrentDirectory(), "Data") + Path.DirectorySeparatorChar + "Databases" + Path.DirectorySeparatorChar + "TitanSoftStore"; var exists = File.Exists(path + Path.DirectorySeparatorChar + "Raven.voron"); if (overwrite && exists) { Directory.Delete(path, true); } else if (exists) { return; } var api = new OmdbApi(null, null); var results = await GetMovieResults(api); Log.Information($"found {results.Count} results"); Parallel.ForEach(results, async(model) => { using (var db = RavenDocumentStore.Store.OpenAsyncSession()) { foreach (var result in model.Search) { Log.Information($"saving {result.Title}"); var movie = await api.GetMovieAsync(result.ImdbId); await db.StoreAsync(movie); } await db.SaveChangesAsync(); } }); }
static async Task AsyncMain() { var omdbApi = new OmdbApi(new SharedHttpClient()); while (true) { System.Console.WriteLine("SEARCH for a movies or get by ID:"); var input = System.Console.ReadLine(); if (string.IsNullOrEmpty(input)) return; switch (input.ToLower().Split(' ')[0]) { case "exit": case "": case null: return; case "search": await Search(omdbApi, input.Split(' ')[1]); break; case "id": await ById(omdbApi, input.Split(' ')[1]); break; } } }
public void Load_Movie_Test() { var api = new OmdbApi(config, logger) as IOmdbApi; var id = "tt3896198"; var result = api.GetMovie(id); Assert.IsTrue(result != null); }
public void Search_Movies_Test() { var term = "american"; var api = new OmdbApi(config, logger) as IOmdbApi; var results = api.Search(term, 1); Assert.IsTrue(results.Search.Count > 0); }
private static async Task Search(OmdbApi omdbApi, string s) { var results = await omdbApi.Search(s); if (!string.IsNullOrEmpty(results.Error)) { System.Console.WriteLine(results.Error); return; } foreach (var movie in results.Search) System.Console.WriteLine($"{movie.ImdbId}: {movie.Title} ({movie.Year})"); }
// GET: MoviesList/Sync public async Task <ActionResult> Sync(int id, MovieDetails MovieDetails) { MoviesList movieList = db.MoviesList.Find(id); OmdbApi omdbApi = await service.GetMovieDetailsFromApi(movieList.MovieName); if (omdbApi.IMDBId != null) { ProcessMovieData(omdbApi, id); } return(RedirectToAction("Index")); }
private static async Task ById(OmdbApi omdbApi, string s) { var movie = await omdbApi.GetById(s); if (!string.IsNullOrEmpty(movie.Error)) { System.Console.WriteLine(movie.Error); return; } foreach (var prop in movie.GetType().GetProperties()) { System.Console.WriteLine(prop.Name + ": " + prop.GetMethod.Invoke(movie, new object[]{})); // I'm lazy } }
public async Task <ActionResult> SyncAll() { List <MoviesList> movieList = db.MoviesList.Where(movList => !db.MovieDetails.Any(movDetails => movDetails.MovieId == movList.MovieId)).ToList(); foreach (MoviesList eachMovie in movieList) { OmdbApi omdbApi = await service.GetMovieDetailsFromApi(eachMovie.MovieName); if (omdbApi.IMDBId != null) { ProcessMovieData(omdbApi, eachMovie.MovieId); } } return(RedirectToAction("Index")); }
private static async Task SendFilmInformations(Message message, string lowerCaseMessage) { var titolo = ""; if (lowerCaseMessage.Contains("films")) { var posTitolo = lowerCaseMessage.IndexOf("films"); titolo = lowerCaseMessage.Substring(posTitolo + 6); } else { var posTitolo = lowerCaseMessage.IndexOf("film"); titolo = lowerCaseMessage.Substring(posTitolo + 5); } List <string> ids = OmdbApi.SearchImdbIds(titolo); string filmDataString = ""; foreach (string id in ids.Distinct()) { JObject filmData = OmdbApi.GetFilmData(id); filmDataString += string.Format(@$ " ---- Titolo: {filmData[" Title "]} Anno: {filmData[" Year "]} Durata: {filmData[" Runtime "]} "); if (filmData.ContainsKey("Ratings") && filmData["Ratings"].HasValues) { foreach (var rating in filmData["Ratings"]) { filmDataString += rating["Source"] + "\t" + rating["Value"] + "\n"; filmDataString = filmDataString.Replace("Internet Movie Database", "IMDB"); filmDataString = filmDataString.Replace("Rotten Tomatoes", "ROTT"); filmDataString = filmDataString.Replace("Metacritic", "METC"); } } } await Bot.SendTextMessageAsync( chatId : message.Chat.Id, text : filmDataString, replyMarkup : new ReplyKeyboardRemove()); }
private void ProcessMovieData(OmdbApi omdbApi, int movieid) { List <string> genreList = omdbApi.Genre.Split(',').Select(g => g.Trim()).ToList(); List <int> genreIdList = ProcessGenre(genreList); List <string> actorList = omdbApi.Actors.Split(',').Select(a => a.Trim()).ToList(); List <int> actorIdList = ProcessActors(actorList); var dbContextTransaction = db.Database.BeginTransaction(); ProcessMovieGenre(genreIdList, movieid); ProcessMovieCast(actorIdList, movieid); ProcessMovieDetails(omdbApi, movieid); dbContextTransaction.Commit(); }
//Gets movie details from Omdb Api by MovieName public async Task <OmdbApi> GetMovieDetailsFromApi(string moviename) { OmdbApi omdbApi = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUri); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync("?apikey=f2625f26&t=" + moviename); if (response.IsSuccessStatusCode) { omdbApi = await response.Content.ReadAsAsync <OmdbApi>(); } } return(omdbApi); }
public string Evaluate(Context context) { try { Task.Factory.StartNew(() => { var omdbApi = new OmdbApi(); var result = omdbApi.Search(context.Element.Value); if (result.Success) { var getAttribute = context.Element.Attribute(Tag.GetAttribute); var toReturn = string.Empty; if (getAttribute != null) { var getValue = getAttribute.Value.ToLower(); if (getValue == "rating") { toReturn = result.ImdbRating.ToString(CultureInfo.InvariantCulture); } if (getValue == "language") { toReturn = result.Language; } if (getValue == "genre") { toReturn = result.Genre; } if (getValue == "votes") { toReturn = result.ImdbVotes.ToString(CultureInfo.InvariantCulture); } if (getValue == "writer") { toReturn = result.Writer; } if (getValue == "country") { toReturn = result.Country; } if (getValue == "plot") { toReturn = result.Plot; } if (getValue == "year") { toReturn = result.Year.ToString(CultureInfo.InvariantCulture); } if (getValue == "awards") { toReturn = result.Awards; } if (getValue == "actors") { toReturn = result.Actors; } if (getValue == "director") { toReturn = result.Director; } var dispatcher = VirtualAssistant.Instance.Components.Get <Dispatcher>(); if (dispatcher != null && !string.IsNullOrEmpty(toReturn)) { dispatcher.Invoke(() => { context.User.Vars["mediainfo-movie"].Value = context.Element.Value; context.User.Vars["mediainfo-type"].Value = getValue; context.User.Vars["mediainfo-value"].Value = toReturn; context.Bot.Trigger("mediainfo-query"); }); } else { context.Bot.Trigger("mediainfo-query-error"); } } } }); } catch (Exception exception) { VirtualAssistant.Instance.Logger.Error(exception); } return(string.Empty); }