public void ParseTVDetails(string result) { try { List <string> genres = new List <string>(); Tvseries tv = tvForDetails[itemsProcessed]; context.Tvseries.Update(tv); int pos = result.IndexOf("Watch for 0.00 with Prime"); tv.IsPrime = pos != -1; pos = result.IndexOf("av-icon--amazon_rating"); int pos2; int pos3; if (pos != -1) { pos = result.IndexOf("(", pos); pos2 = result.IndexOf(")", pos); tv.Ratings = result.Substring(pos + 1, pos2 - pos - 1); } pos = result.IndexOf("\"imdb-rating-badge\""); if (pos != -1) { pos = result.IndexOf(">", pos); pos2 = result.IndexOf("<", pos); try { tv.Imdbrating = Convert.ToSingle(result.Substring(pos + 1, pos2 - pos - 1)); } catch (Exception) { } } pos = result.IndexOf("\"synopsis\""); if (pos != -1) { pos = result.IndexOf("<p", pos); if (pos > -1) { pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</p>", pos); try { tv.Plot = result.Substring(pos + 1, pos2 - pos - 1).Replace("Now included with Prime.", "").Trim(); } catch (Exception) { } } } int posProductDetails = result.IndexOf("Product details"); if (posProductDetails != -1) { int posOtherFormats = result.IndexOf("Customer Reviews", posProductDetails); int posTR = -1; pos = result.IndexOf("Genres", posProductDetails); if (pos > posOtherFormats) { pos = -1; } if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); tv.Genres = string.Empty; while (pos < pos3 && pos < posTR && pos != -1) { if (pos >= posOtherFormats) { break; } pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { string genre = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)); genres.Add(genre); genre += ", "; tv.Genres += genre; pos = result.IndexOf("<a", pos); } catch (Exception) { } } } pos = result.IndexOf("Director", posProductDetails); if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); if (pos < pos3 && pos < posTR && pos != -1) { pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { tv.Director = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)); } catch (Exception) { } } } pos = result.IndexOf("Starring", posProductDetails); if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); tv.Starring = string.Empty; while (pos < pos3 && pos < posTR && pos != -1) { if (pos >= posOtherFormats) { break; } pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { string data = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)) + ", "; tv.Starring += data; pos = result.IndexOf("<a", pos); } catch (Exception) { } } if (tv.Starring != null && tv.Starring.Length > 0) { tv.Starring = tv.Starring.Replace(" ", " "); tv.Starring = tv.Starring.Substring(0, tv.Starring.Length - 2); } } pos = result.IndexOf("Supporting actors", posProductDetails); if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); tv.SupportingActors = string.Empty; while (pos < pos3 && pos < posTR && pos != -1) { if (pos >= posOtherFormats) { break; } pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { string data = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)) + ", "; tv.SupportingActors += data; pos = result.IndexOf("<a", pos); } catch (Exception) { } } if (tv.SupportingActors != null && tv.SupportingActors.Length > 0) { tv.SupportingActors = tv.SupportingActors.Replace(" ", " "); tv.SupportingActors = tv.SupportingActors.Substring(0, tv.SupportingActors.Length - 2); } } } context.SaveChanges(); foreach (string _genre in genres) { Genre genre = context.Genre.Where(g => g.Name == _genre).SingleOrDefault(); if (genre == null) { genre = new Genre(); genre.Name = _genre; context.Add(genre); context.SaveChanges(); } TvseriesGenre tvseriesGenre = new TvseriesGenre(); tvseriesGenre.Genre = genre; tvseriesGenre.Tvseries = tv; context.Add(tvseriesGenre); context.SaveChanges(); } itemsProcessed++; lblDetailProgress.Text = $"{itemsProcessed} of {itemsToProcess} Bad URLs: {badURLs}"; if (itemsProcessed < tvForDetails.Count()) { nextURL = tvForDetails[itemsProcessed].Url; webBrowser1.Navigate(nextURL); while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } timer1.Start(); } else { MessageBox.Show("Update complete"); } } catch (Exception ex) { var error = ex; } }
public void ParseMovieDetails(string result) { try { Movie movie = moviesForDetails[itemsProcessed]; if (result.IndexOf("To discuss automated access to Amazon") != -1) { MessageBox.Show("Update complete"); return; } using (AWSPrimeStreamingContext context = new AWSPrimeStreamingContext()) { List <string> genres = new List <string>(); context.Update(movie); int pos = result.IndexOf("Watch for 0.00 with a Prime"); movie.IsPrime = pos != -1; pos = result.IndexOf("av-icon--amazon_rating"); int pos2; int pos3; if (pos != -1) { pos = result.IndexOf("(", pos); pos2 = result.IndexOf(")", pos); movie.Ratings = result.Substring(pos + 1, pos2 - pos - 1); } pos = result.IndexOf("\"imdb-rating-badge\""); if (pos != -1) { pos = result.IndexOf(">", pos); pos2 = result.IndexOf("<", pos); try { movie.Imdbrating = Convert.ToSingle(result.Substring(pos + 1, pos2 - pos - 1)); } catch (Exception) { } } pos = result.IndexOf("\"synopsis\""); if (pos != -1) { pos = result.IndexOf("<p", pos); if (pos > -1) { pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</p>", pos); try { movie.Plot = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1).Replace("Now included with Prime.", "").Replace("Now on Prime. ", "").Trim()); } catch (Exception) { } } } int posProductDetails = result.IndexOf("Product details"); if (posProductDetails != -1) { int posOtherFormats = result.IndexOf("Other formats", posProductDetails); int posTR = -1; pos = result.IndexOf("Genres", posProductDetails); if (pos > posOtherFormats) { pos = -1; } if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); movie.Genres = string.Empty; while (pos < pos3 && pos < posTR && pos != -1) { if (pos >= posOtherFormats) { break; } pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { string genre = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)); genres.Add(genre); genre += ", "; movie.Genres += genre; pos = result.IndexOf("<a", pos); } catch (Exception) { } } } pos = result.IndexOf("Director", posProductDetails); if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); if (pos < pos3 && pos < posTR && pos != -1) { pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { movie.Director = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)); } catch (Exception) { } } } pos = result.IndexOf("Starring", posProductDetails); if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); movie.Starring = string.Empty; while (pos < pos3 && pos < posTR && pos != -1) { if (pos >= posOtherFormats) { break; } pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { string data = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)) + ", "; movie.Starring += data; pos = result.IndexOf("<a", pos); } catch (Exception) { } } if (movie.Starring != null && movie.Starring.Length > 0) { movie.Starring = movie.Starring.Replace(" ", " "); movie.Starring = movie.Starring.Substring(0, movie.Starring.Length - 2); } } pos = result.IndexOf("Supporting actors", posProductDetails); if (pos != -1) { posTR = result.IndexOf("<tr", pos); pos3 = result.IndexOf("</td>", pos); pos = result.IndexOf("<a", pos); movie.SupportingActors = string.Empty; while (pos < pos3 && pos < posTR && pos != -1) { if (pos >= posOtherFormats) { break; } pos = result.IndexOf(">", pos); pos2 = result.IndexOf("</a>", pos); try { string data = HttpUtility.HtmlDecode(result.Substring(pos + 1, pos2 - pos - 1)) + ", "; movie.SupportingActors += data; pos = result.IndexOf("<a", pos); } catch (Exception) { } } if (movie.SupportingActors != null && movie.SupportingActors.Length > 0) { movie.SupportingActors = movie.SupportingActors.Replace(" ", " "); movie.SupportingActors = movie.SupportingActors.Substring(0, movie.SupportingActors.Length - 2); } } } context.SaveChanges(); foreach (string _genre in genres) { Genre genre = context.Genre.Where(g => g.Name == _genre).SingleOrDefault(); if (genre == null) { genre = new Genre(); genre.Name = _genre; context.Add(genre); context.SaveChanges(); } MovieGenre movieGenre = new MovieGenre(); movieGenre.Genre = genre; movieGenre.Movie = movie; context.Add(movieGenre); try { context.SaveChanges(); } catch (Exception) { } } } } catch (Exception) { } itemsProcessed++; lblDetailProgress.Text = $"{itemsProcessed} of {itemsToProcess} Bad URLs: {badURLs}"; if (itemsProcessed < moviesForDetails.Count()) { nextURL = moviesForDetails[itemsProcessed].Url; webBrowser1.Navigate(nextURL); while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } timer1.Start(); } else { MessageBox.Show("Update complete"); } }