/// <summary>
        /// Get the #tab=summary page
        /// </summary>
        /// <returns>
        /// int the ID of movie in database;
        /// </returns>
        private string GetGeneralDesc()
        {
            string                result     = ""; // default ID
            bool                  downloaded = false;
            int                   count      = 0;
            HtmlDocument          doc        = new HtmlDocument();
            TheNumbersDataContext dc         = new TheNumbersDataContext();
            Movy                  movieDB    = new Movy();
            List <ReleaseDate>    reldateDB  = new List <ReleaseDate>();

            while (!downloaded)
            {
                try
                {
                    doc.LoadHtml(Helper.GetHTML(url + @"#tab=summary"));
                    downloaded = true;
                }
                catch (Exception e)
                {
                    downloaded = false;
                    count++;
                    if (count >= 3)
                    {
                        Helper.WriteToLog(ProgramStatus.Error, "error loading the movie");
                        Helper.WriteToError(url, e.StackTrace, year);
                    }
                    else
                    {
                        Task.Delay(5000);
                    }
                }
            }
            if (downloaded)
            {
                try
                {
                    movieDB.ID = dc.GetMovieID();
                    // get summary div
                    var summ = doc.DocumentNode.Descendants("div")
                               .Single(o => o.HasAttributes && o.Attributes.Any(p => p.Name.Equals("id")) &&
                                       o.Attributes["id"].Value.Equals("summary"));

                    // title
                    movieDB.Title = doc.DocumentNode.Descendants("h1").Single(tit => tit.HasAttributes && tit.Attributes.Any(attr => attr.Name.ToLowerInvariant().Equals("itemprop")) && tit.Attributes["itemprop"].Value.ToLowerInvariant().Equals("name"))
                                    .InnerText.Trim();

                    // rating
                    var rating = summ.Descendants("table").FirstOrDefault();
                    if (rating.Descendants("tr").Count() > 1)
                    {
                        // rating exist
                        foreach (var a in rating.Descendants("tr").LastOrDefault().Descendants("a"))
                        {
                            if (a.InnerText.ToLowerInvariant().Contains("critics"))
                            { // critics
                                string temprating = Regex.Match(a.InnerText, @"\d+").Value;
                                movieDB.RTCRating = Int32.Parse(temprating);
                            }
                            else
                            { // audience
                                string temprating = Regex.Match(a.InnerText, @"\d+").Value;
                                movieDB.RTARating = Int32.Parse(temprating);
                            }
                        }
                    }

                    movieDB.year = this.year;

                    // general desc
                    var gen = summ.Descendants("table").LastOrDefault();
                    foreach (var tr in gen.Descendants("tr"))
                    {
                        if (tr.InnerText.ToLowerInvariant().Contains("budget"))
                        {
                            var tempbudget = tr.InnerText.Split(':').LastOrDefault()
                                             .Trim().Replace("$", string.Empty).Replace(",", string.Empty).Replace("&nbsp;", string.Empty);
                            movieDB.Budget = Int32.Parse(tempbudget);
                        }
                        else if (tr.InnerText.ToLowerInvariant().Contains("domestic"))
                        {
                            foreach (var rels in tr.Descendants("td").LastOrDefault()
                                     .InnerHtml.Split(new string[] { "<br>" },
                                                      StringSplitOptions.RemoveEmptyEntries))
                            {
                                var rel = rels.Split(new string[] { "by" },
                                                     StringSplitOptions.RemoveEmptyEntries);
                                var      kind        = Regex.Match(rel[0], @"\((.*?)\)").Value.Equals("") ? "" : Regex.Match(rel[0], @"\((.*?)\)").Value;
                                string   reldate     = "";
                                DateTime realreldate = new DateTime();
                                if (kind.Length > 0)
                                {
                                    reldate = rel[0].Remove(rel[0].IndexOf(',') - 2, 2).Replace(kind, String.Empty).Trim();
                                }
                                else
                                {
                                    reldate = rel[0].Remove(rel[0].IndexOf(',') - 2, 2).Trim();
                                }
                                realreldate = DateTime.ParseExact(reldate, "MMMM d, yyyy", CultureInfo.InvariantCulture);
                                HtmlNode    publisher     = rel.Count() > 1 ? HtmlNode.CreateNode(rel[1].Trim()) : null;
                                ReleaseDate reldateDBtemp = new ReleaseDate();
                                reldateDBtemp.ReleaseDate1 = realreldate;
                                reldateDBtemp.Remarks      = "Domestic";
                                reldateDBtemp.Company      = publisher == null ? "Unknown" : publisher.InnerText;
                                reldateDBtemp.Desc         = kind;
                                reldateDB.Add(reldateDBtemp);
                            }
                        }
                        else if (tr.InnerText.ToLowerInvariant().IndexOf("video") == 0)
                        {
                            foreach (var rels in tr.Descendants("td").LastOrDefault()
                                     .InnerHtml.Split(new string[] { "<br>" },
                                                      StringSplitOptions.RemoveEmptyEntries))
                            {
                                var rel = rels.Split(new string[] { "by" },
                                                     StringSplitOptions.RemoveEmptyEntries);
                                var      kind        = Regex.Match(rel[0], @"\((.*?)\)").Value.Equals("") ? "" : Regex.Match(rel[0], @"\((.*?)\)").Value;
                                string   reldate     = "";
                                DateTime realreldate = new DateTime();
                                if (kind.Length > 0)
                                {
                                    reldate = rel[0].Remove(rel[0].IndexOf(',') - 2, 2).Replace(kind, String.Empty).Trim();
                                }
                                else
                                {
                                    reldate = rel[0].Remove(rel[0].IndexOf(',') - 2, 2).Trim();
                                }
                                realreldate = DateTime.ParseExact(reldate, "MMMM d, yyyy", CultureInfo.InvariantCulture);
                                var         publisher     = rel.Count() > 1 ? HtmlNode.CreateNode(rel[1].Trim()) : null;
                                ReleaseDate reldateDBtemp = new ReleaseDate();
                                reldateDBtemp.ReleaseDate1 = realreldate;
                                reldateDBtemp.Remarks      = "Video";
                                reldateDBtemp.Company      = publisher == null ? "Unknown" : publisher.InnerText;
                                reldateDBtemp.Desc         = string.IsNullOrEmpty(kind) ? "Unknown" : kind;
                                reldateDB.Add(reldateDBtemp);
                            }
                        }
                        else if (tr.InnerText.ToLowerInvariant().IndexOf("mpaa") == 0)
                        {
                            var mpaarating = tr.Descendants("td").LastOrDefault().Descendants("a").Single()
                                             .InnerText;
                            //Console.WriteLine(mpaarating);
                            movieDB.MPAARating = mpaarating;
                        }
                        else if (tr.InnerText.ToLowerInvariant().IndexOf("running") == 0)
                        {
                            var runningtime = Int32.Parse(Regex.Match(tr.Descendants("td").LastOrDefault()
                                                                      .InnerText, @"\d+").Value);
                            movieDB.RunningTime = runningtime;
                        }
                        else if (tr.InnerText.ToLowerInvariant().IndexOf("franchise") == 0)
                        {
                            var franchise = tr.Descendants("td").LastOrDefault()
                                            .Descendants("a").Single().InnerText;
                            movieDB.Franchise = franchise;
                        }
                        else if (tr.InnerText.ToLowerInvariant().IndexOf("genre") == 0)
                        {
                            var genre = tr.Descendants("td").LastOrDefault()
                                        .Descendants("a").Single().InnerText;
                            //Console.WriteLine(genre);
                            movieDB.Genre = genre;
                        }
                        else if (tr.InnerText.ToLowerInvariant().IndexOf("compan") == 0)
                        {
                            var company = "";
                            foreach (var a in tr.Descendants("td").LastOrDefault()
                                     .Descendants("a"))
                            {
                                company += a.InnerText.Trim();
                            }
                            movieDB.Company = company;
                        }
                    }
                    try
                    {
                        var check = dc.CheckIfExistsTheSame(movieDB.Title, year);
                        if (check.Equals("false"))
                        {
                            dc.ReleaseDates.InsertAllOnSubmit(reldateDB.Select(rd => { rd.MovieID = movieDB.ID; return(rd); }).ToList());
                            dc.Movies.InsertOnSubmit(movieDB);
                            dc.SubmitChanges();
                            result = movieDB.ID;
                        }
                        else
                        {
                            result = check;
                        }
                    }
                    catch (Exception e)
                    {
                        Helper.WriteToLog(ProgramStatus.Error, "error loading the movie");
                        Helper.WriteToError(url, e.StackTrace, year);
                    }
                }
                catch
                {
                    Console.WriteLine("");
                }
            }
            return(result);
        }
Esempio n. 2
0
 partial void UpdateReleaseDate(ReleaseDate instance);
Esempio n. 3
0
 partial void DeleteReleaseDate(ReleaseDate instance);
Esempio n. 4
0
 partial void InsertReleaseDate(ReleaseDate instance);