Example #1
0
        public const short NUM_MOVIES = 250; // The amount of movies you want to consider. 250 is the max.

        public static void Main(string[] args)
        {
            IMDBHtmlExtractor.OpenNewDocument(INPUT_URL);

            List <string> links  = IMDBHtmlExtractor.ExtractMovieLinksFromList();
            List <Movie>  movies = new List <Movie>();

            foreach (string link in links)
            {
                MovieBuilder.TryBuildMovie(link, out Movie movie);
                if (movie == null)
                {
                    Logger.Warning("Failed to read movie from link: " + link);
                }
                else
                {
                    movies.Add(movie);
                }
                Logger.Info($"Movie read: {movie.Title}");
            }

            IOrderedEnumerable <Movie> sortedMovies = movies.OrderBy(m => m.ReleaseDate);

            foreach (Movie movie in sortedMovies)
            {
                MovieOutputter.OutputMovie(movie);
            }

            Console.ReadKey();
        }
Example #2
0
        /// <summary>
        /// Attempt to build a Movie object from its IMDb page.
        /// </summary>
        /// <param name="link">The link to the movie's IMDb page.</param>
        /// <param name="movie">The resulting Movie object (null if failed).</param>
        /// <returns>true if successful, false if not.</returns>
        public static bool TryBuildMovie(string link, out Movie movie)
        {
            try
            {
                movie = new Movie()
                {
                    PageLink = link,

                    Title       = IMDBHtmlExtractor.ExtractMovieTitle(link),
                    ReleaseDate = ParseReleaseDate(IMDBHtmlExtractor.ExtractReleaseDateString(link))
                };

                return(true);
            }
            catch (Exception e)
            {
                Logger.Warning($"[{nameof(MovieBuilder)}.{nameof(TryBuildMovie)}] Failed to build the movie from link: {link}\n{e.Message}");
                movie = null;
                return(false);
            }
        }