示例#1
0
 public Form1()
 {
     InitializeComponent();
     context = new AWSPrimeStreamingContext();
     cbDownloadScope.SelectedIndex = 0;
 }
示例#2
0
        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");
            }
        }