Esempio n. 1
0
        private static List <IMDBResult> GetMostPopularMovies()
        {
            List <IMDBResult> imdbSimpleModel = new List <IMDBResult>();

            try
            {
                HtmlWeb      web = new HtmlWeb();
                HtmlDocument doc = web.Load($"https://www.imdb.com/chart/moviemeter?ref_=nv_mv_mpm");

                var allMovieNodes = doc.DocumentNode.SelectSingleNode("//tbody[contains(@class, 'lister-list')]").SelectNodes(".//tr");

                foreach (var node in allMovieNodes)
                {
                    var model      = new IMDBResult();
                    var smallImage = node.SelectSingleNode(".//td[contains(@class, 'posterColumn')]").SelectSingleNode(".//a").SelectSingleNode(".//img").Attributes["src"].Value;
                    SetImages(model, smallImage);
                    model.Title = node.SelectSingleNode(".//td[contains(@class, 'titleColumn')]").SelectSingleNode(".//a").InnerText;
                    model.Id    = $"tt{Regex.Match(node.SelectSingleNode(".//td[contains(@class, 'posterColumn')]").SelectSingleNode(".//a").Attributes["href"].Value.Split('?').FirstOrDefault(), @"\d+").Value}";
                    model.Year  = int.Parse(Regex.Match(node.SelectSingleNode(".//span[contains(@class, 'secondaryInfo')]").InnerText, @"\b\d{4}\b").Value);
                    imdbSimpleModel.Add(model);
                }

                return(imdbSimpleModel);
            }
            catch (Exception ex)
            {
                //Crashes.TrackError(ex);
                return(imdbSimpleModel);
            }
        }
Esempio n. 2
0
        private static List <IMDBResult> GetNewestMovies(HomePageType movieType = HomePageType.MoviesInTheaters)
        {
            List <IMDBResult> imdbSimpleModel = new List <IMDBResult>();

            try
            {
                HtmlWeb      web = new HtmlWeb();
                HtmlDocument doc = web.Load($"https://www.imdb.com/movies-in-theaters/");

                var allMovieNodes = doc.DocumentNode.SelectNodes("//*[contains(@class,'list_item')]");

                foreach (var node in allMovieNodes)
                {
                    var model      = new IMDBResult();
                    var smallImage = node.SelectNodes(".//img").FirstOrDefault().Attributes["src"].Value;
                    SetImages(model, smallImage);
                    var title = node.SelectNodes(".//*[contains(@class,'overview-top')]").FirstOrDefault().SelectSingleNode(".//a").Attributes["title"].Value;
                    model.Title = title;
                    model.Title = Regex.Replace(model.Title, @"\((\d{4})\)$", "").TrimEnd();
                    model.Id    = $"tt{Regex.Match(node.SelectSingleNode(".//div[contains(@class, 'image')]").SelectSingleNode(".//a").Attributes["href"].Value, @"\d+").Value}";
                    model.Year  = int.Parse(Regex.Match(title, @"\b\d{4}\b").Value);
                    imdbSimpleModel.Add(model);
                }

                return(imdbSimpleModel);
            }
            catch (Exception ex)
            {
                //Crashes.TrackError(ex);
                return(imdbSimpleModel);
            }
        }
Esempio n. 3
0
        private static List <IMDBResult> GetNewDVDReleases()
        {
            List <IMDBResult> imdbSimpleModel = new List <IMDBResult>();

            try
            {
                HtmlWeb      web = new HtmlWeb();
                HtmlDocument doc = web.Load($"https://www.imdb.com/list/ls016522954/?ref_=nv_tvv_dvd");

                var allMovieNodes = doc.DocumentNode.SelectNodes("//*[contains(@class,'lister-item mode-detail')]");

                foreach (var node in allMovieNodes)
                {
                    var model      = new IMDBResult();
                    var smallImage = node.SelectNodes(".//img").Where(x => x.Attributes.Contains("loadlate")).FirstOrDefault().Attributes["loadlate"].Value;
                    SetImages(model, smallImage);
                    var titleNode = node.SelectNodes(".//*[contains(@class,'lister-item-header')]").FirstOrDefault();
                    model.Title = titleNode.SelectSingleNode(".//a").InnerText;
                    model.Id    = $"tt{Regex.Match(node.SelectSingleNode(".//div[contains(@class, 'image')]").SelectSingleNode(".//a").Attributes["href"].Value, @"\d+").Value}";
                    model.Year  = int.Parse(Regex.Match(titleNode.SelectNodes(".//span[contains(@class, 'lister-item-year')]").LastOrDefault().InnerText, @"\b\d{4}\b").Value);
                    imdbSimpleModel.Add(model);
                }

                return(imdbSimpleModel);
            }
            catch (Exception ex)
            {
                //Crashes.TrackError(ex);
                return(imdbSimpleModel);
            }
        }
Esempio n. 4
0
        private static void SetImages(IMDBResult model, string smallImage)
        {
            var imagelinkParts = smallImage.Split(',');
            var correctLink    = $"{imagelinkParts[0]}.{imagelinkParts[1]}.{imagelinkParts[2]}";

            model.SmallImage  = $"{correctLink}._V1_UX140_CR0,0,140,209_AL_.jpg";
            model.MediumImage = $"{correctLink}._SY1000_CR0,0,640,1000_AL_.jpg";
            model.LargeImage  = $"{correctLink}.jpg";
        }
Esempio n. 5
0
        public List <IMDBResult> GetMostPopularMoviesByGenre(IMDBCategories Category)
        {
            List <IMDBResult> imdbSimpleModel = new List <IMDBResult>();
            string            genre           = GetCategoryName(Category);

            try
            {
                HtmlWeb      web           = new HtmlWeb();
                HtmlDocument doc           = web.Load($"https://www.imdb.com/search/title?genres={genre}&explore=title_type,genres");
                var          allMovieNodes = doc.DocumentNode.SelectNodes("//div[contains(@class, 'lister-item mode-advanced')]");

                foreach (var node in allMovieNodes)
                {
                    var model          = new IMDBResult();
                    var smallImage     = node.SelectSingleNode(".//div[contains(@class, 'lister-item-image float-left')]").SelectSingleNode(".//img").Attributes["loadlate"].Value;
                    var imagelinkParts = smallImage.Split('.');
                    var correctLink    = $"{imagelinkParts[0]}.{imagelinkParts[1]}.{imagelinkParts[2]}";
                    model.SmallImage  = $"{correctLink}._V1_UX140_CR0,0,140,209_AL_.jpg";
                    model.MediumImage = $"{correctLink}._SY1000_CR0,0,640,1000_AL_.jpg";
                    model.LargeImage  = $"{correctLink}.jpg";
                    model.Title       = node.SelectSingleNode(".//h3[contains(@class, 'lister-item-header')]").SelectSingleNode(".//a").InnerText;
                    model.Id          = $"tt{Regex.Match(node.SelectSingleNode(".//h3[contains(@class, 'lister-item-header')]").SelectSingleNode(".//a").Attributes["href"].Value.Split('?').FirstOrDefault(), @"\d+").Value}";
                    model.Year        = int.Parse(Regex.Match(node.SelectSingleNode(".//span[contains(@class, 'lister-item-year')]").InnerText, @"\b\d{4}\b").Value);
                    //actors
                    //type
                    imdbSimpleModel.Add(model);
                }

                return(imdbSimpleModel);
            }
            catch (Exception ex)
            {
                //TODO: Enable logging
                return(imdbSimpleModel);
            }
        }