Ejemplo n.º 1
0
 public AsyncProcessor(int maximumSimultaneous, ImdbParser parser)
 {
     commands = new List <AsyncCommand>();
     running  = 0;
     this.maximumSimultaneous = maximumSimultaneous;
     this.parser = parser;
 }
Ejemplo n.º 2
0
        public static MovieInfo GetMovieInfo(string movieName, string outputDirectory)
        {
            MovieInfo info = new MovieInfo()
            {
                Name = movieName
            };
            ChromeOptions options = new ChromeOptions();

            //options.AddArgument("headless");
            using (ChromeDriver chrome = new ChromeDriver(Environment.CurrentDirectory, options))
            {
                //Search Movie
                Searcher searcher = new Searcher(driver: chrome,
                                                 urlBuilder: SearchUrlBuilders.Bing,
                                                 parsers: (driver) => RankWikiLinks(driver, movieName));

                var result = searcher.Search($"{movieName} film").Select(link => link.GetAttribute("href")).ToList();

                foreach (var link in result)
                {
                    try
                    {
                        info.WikiLink = link;
                        chrome.Navigate().GoToUrl(info.WikiLink);
                        chrome.WaitForPageLoad();

                        //Extract Info
                        info.WikiScreenShotPath = Path.Combine(outputDirectory, $"{movieName}_wiki.png");
                        chrome.GetScreenshot().SaveAsFile(info.WikiScreenShotPath);
                        WikiParser wp = new WikiParser(chrome);
                        info.Directors_Wiki = wp.GetDirectors();

                        //Extract Info
                        var imdbLink = LinkFinders.FindImdb(chrome)?.Reverse()?.First();
                        info.ImdbLink = imdbLink.GetAttribute("href");
                        chrome.Navigate().GoToUrl($"{info.ImdbLink}fullcredits");
                        info.ImdbScreenShotPath = Path.Combine(outputDirectory, $"{movieName}_imdb.png");
                        chrome.GetScreenshot().SaveAsFile(info.ImdbScreenShotPath);
                        ImdbParser ip = new ImdbParser(chrome);
                        info.Directors_Imdb = ip.GetDirectors();

                        break;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"{movieName}" + e.Message);
                    }
                }
            }
            return(info);
        }
        public void Redirect(string srcurl, string src)
        {
            var title = ImdbParser.MediaFrom(src);

            if (!string.IsNullOrEmpty(title))
            {
                var url = "http://www.imdb.com/title/" + title;
                InvokeOnDebugTextFired(string.Format("Redirect to '{0}'...\r\n", url));
                Browser.Navigate(url);

                RecentSearch = false;
            }

            if (srcurl.StartsWith(ImdbSearch))
            {
                RecentSearch = false;
            }
        }
        public Movie ParseMovieInfo(string html)
        {
            try
            {
                var movie = new Movie();

                //var src = Browser.DocumentText;
                var rating = ImdbParser.ParseRating(html);
                var title  = ImdbParser.ParseTitle(html);
                var year   = ImdbParser.ParseYear(html);
                var imdbId = ImdbParser.ParseId(html);

                InvokeOnDebugTextFired("Title: " + title + "\r\n");
                InvokeOnDebugTextFired("Year: " + year + "\r\n");
                InvokeOnDebugTextFired("Rating: " + rating + "\r\n");

                movie.Rating     = Convert.ToDouble(rating);
                movie.Title      = HttpHelper.HtmlDecode(HttpHelper.UrlDecode(ImdbParser.ParseTitle(html)));
                movie.Year       = Convert.ToInt32(year);
                movie.ImdbId     = imdbId;
                movie.FilePath   = "";
                movie.Runtime    = ImdbParser.ParseRuntime(html);
                movie.MPAA       = ImdbParser.ParseMpaa(html);
                movie.MPAAReason = ImdbParser.ParseMpaaReason(html);
                movie.Highlight  = ImdbParser.ParseHighlight(html);
                movie.Genres     = ImdbParser.ParseGenres(html);
                movie.Countries  = ImdbParser.ParseCountries(html);
                movie.Languages  = ImdbParser.ParseLanguages(html);

                movie.PersonStars     = ImdbParser.ParseStars(html);
                movie.PersonWriters   = ImdbParser.ParseWriters(html);
                movie.PersonDirectors = ImdbParser.ParseDirectors(html);

                movie.IsValidMovie = true;

                return(movie);
            }
            catch (Exception exception)
            {
                Logger.Exception(exception, 418);
                return(null);
            }
        }
 public static Movie GuessMovie(string srcHtml)
 {
     return(ImdbParser.GuessMovie(srcHtml));
 }
        public Movie CollectAndAddMovieToDb(Movie movie2, string moviePage = null, bool collectKeyword = true)
        {
            if (string.IsNullOrEmpty(moviePage))
            {
                InvokeOnNotificationFired("Started collecting movie: " + movie2.Title);
                moviePage = HttpHelper.FetchWebPage(ImdbTitle + movie2.ImdbId);
            }

            var parseMovieInfo = ParseMovieInfo(moviePage);

            if (parseMovieInfo == null)
            {
                return(null);
            }



            var movie = _entities.Movies.Where(o => o.ImdbId == parseMovieInfo.ImdbId).FirstOrDefault();

            if (movie == null)
            {
                movie           = parseMovieInfo;
                movie.IsUpdated = false;
                _entities.AddToMovies(movie);
                _entities.SaveChanges();
            }
            else
            {
                movie.CopyFromMovie(parseMovieInfo);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.Genres)
            {
                var genre      = GetGenre(g);
                var movieGenre = _entities.MovieGenres.Where(o => o.Movie.Id == movie.Id && o.Genre.Id == genre.Id).FirstOrDefault();

                if (movieGenre != null)
                {
                    continue;
                }
                movieGenre = new MovieGenre {
                    Movie = movie, Genre = genre
                };
                _entities.AddToMovieGenres(movieGenre);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.Languages)
            {
                var language      = GetLanguage(g);
                var movieLanguage = _entities.MovieLanguages.Where(o => o.Movie.Id == movie.Id && o.Language.Id == language.Id).FirstOrDefault();

                if (movieLanguage != null)
                {
                    continue;
                }
                movieLanguage = new MovieLanguage {
                    Movie = movie, Language = language
                };
                _entities.AddToMovieLanguages(movieLanguage);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.Countries)
            {
                var country      = GetCountry(g);
                var movieCountry = _entities.MovieCountries.Where(o => o.Movie.Id == movie.Id && o.Country.Id == country.Id).FirstOrDefault();

                if (movieCountry != null)
                {
                    continue;
                }
                movieCountry = new MovieCountry {
                    Movie = movie, Country = country
                };
                _entities.AddToMovieCountries(movieCountry);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.PersonDirectors)
            {
                var person   = GetPerson(g);
                var director = _entities.Directors.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault();

                if (director != null)
                {
                    continue;
                }
                director = new Director {
                    Movie = movie, Person = person
                };
                _entities.AddToDirectors(director);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.PersonStars)
            {
                var person = GetPerson(g);
                var star   = _entities.Stars.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault();

                if (star != null)
                {
                    continue;
                }
                star = new Star {
                    Movie = movie, Person = person
                };
                _entities.AddToStars(star);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.PersonWriters)
            {
                var person = GetPerson(g);
                var writer = _entities.Writers.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault();

                if (writer != null)
                {
                    continue;
                }
                writer = new Writer {
                    Movie = movie, Person = person
                };
                _entities.AddToWriters(writer);
                _entities.SaveChanges();
            }


            if (collectKeyword)
            {
                var keywordPage = HttpHelper.FetchWebPage(string.Format(ImdbKeywordUrl, parseMovieInfo.ImdbId));
                parseMovieInfo.Keywords = ImdbParser.ParseKeywords(keywordPage);

                foreach (var g in parseMovieInfo.Keywords)
                {
                    var keyword      = GetKeyword(g);
                    var movieKeyword =
                        _entities.MovieKeywords.Where(o => o.Movie.Id == movie.Id && o.Keyword.Id == keyword.Id).
                        FirstOrDefault();

                    if (movieKeyword != null)
                    {
                        continue;
                    }
                    movieKeyword = new MovieKeyword {
                        Movie = movie, Keyword = keyword
                    };
                    _entities.AddToMovieKeywords(movieKeyword);
                    _entities.SaveChanges();
                }
            }
            InvokeOnNotificationFired("Fiished collecting movie: " + movie.Title);

            movie.IsUpdated = true;
            _entities.SaveChanges();

            return(movie);
        }