コード例 #1
0
 public GaoQingCollection()
 {
     http             = new HttpHelper();
     movie_bll        = new Movie_BLL();
     download_bll     = new Download_BLL();
     subtitle_bll     = new Subtitle_BLL();
     douBanCollection = new DouBanCollection();
 }
コード例 #2
0
        public void AnalysisMovieSubtitleHtml(int movieID, string html)
        {
            try
            {
                HtmlDocument hd = new HtmlDocument();
                hd.LoadHtml(html);
                var node       = hd.DocumentNode.SelectSingleNode("//table[@id='subtable']");
                var info_nodes = node == null ? null : node.SelectNodes("./tr");
                //var info_nodes = node.SelectNodes("./tr");
                if (info_nodes != null)
                {
                    for (int i = 0; i < (info_nodes.Count > 10 ? info_nodes.Count - 2 : info_nodes.Count); i++)
                    {
                        var     item     = info_nodes[i];
                        string  clear    = item.GetAttributeValue("id", "") == null ? null : item.GetAttributeValue("id", "").Trim();
                        var     name     = item.SelectSingleNode("./td/span/b") == null ? "" : item.SelectSingleNode("./td/span/b").InnerText.Trim();
                        string  size_str = item.SelectSingleNode("./td/span[2]/span[1]") == null ? null : item.SelectSingleNode("./td/span[2]/span[1]").InnerText.Trim();
                        decimal?size     = null;
                        if (!string.IsNullOrWhiteSpace(size_str))
                        {
                            if (size_str.Contains("TB"))
                            {
                                size = Convert.ToDecimal(Utils.ToDouble_(size_str.Replace("TB", "").Trim(), 0) * (1024.0 * 1024.0 * 1024.0));
                            }
                            if (size_str.Contains("GB"))
                            {
                                size = Convert.ToDecimal(Utils.ToDouble_(size_str.Replace("GB", "").Trim(), 0) * (1024.0 * 1024.0));
                            }
                            if (size_str.Contains("MB"))
                            {
                                size = Convert.ToDecimal(Utils.ToDouble_(size_str.Replace("MB", "").Trim(), 0) * (1024.0));
                            }
                            if (size_str.Contains("KB"))
                            {
                                size = Convert.ToDecimal(Utils.ToDouble_(size_str.Replace("KB", "").Trim(), 0));
                            }
                            size = size == 0 ? null : size;
                        }
                        var source       = item.SelectSingleNode("./td/span[2]/span[2]") == null ? null : item.SelectSingleNode("./td/span[2]/span[2]").InnerText.Trim();
                        var format_nodes = item.SelectNodes("./td/span[2]/span[@class='label label-danger']");
                        var format_str   = "";
                        if (format_nodes != null)
                        {
                            foreach (var m in format_nodes)
                            {
                                var t_format = m.InnerText.Trim();
                                if (!string.IsNullOrWhiteSpace(t_format))
                                {
                                    format_str += t_format + ",";
                                }
                            }
                        }
                        format_str = format_str.TrimEnd(',');

                        var language_node = item.SelectSingleNode("./td/span[2]/span[last()]/span");
                        var language      = "";
                        var meat          = "";
                        if (language_node != null)
                        {
                            language = language_node.GetAttributeValue("title", "").Trim().Replace(" ", ",");
                            meat     = language_node.InnerText.Trim();
                        }

                        var download      = "";
                        var download_node = item.SelectSingleNode("./td/span[2]/span[last()]/a");
                        if (download_node != null)
                        {
                            download = download_node.GetAttributeValue("href", "");
                        }

                        if (!string.IsNullOrWhiteSpace(download))
                        {
                            int sid = new Subtitle_BLL().SaveSubtitle(new Domain.Entity.Subtitle_Repository()
                            {
                                Clear      = clear,
                                Size       = size == 0 ? null : size,
                                CreateTime = DateTime.Now,
                                Title      = name,
                                Format     = format_str,
                                Language   = string.IsNullOrWhiteSpace(language) ? null : language,
                                Meta       = string.IsNullOrWhiteSpace(meat) ? null : meat,
                                Download   = string.IsNullOrWhiteSpace(download) ? null : download,
                                Source     = string.IsNullOrWhiteSpace(source) ? null : source,
                                Guid       = Guid.NewGuid().ToString().ToUpper(),
                                MovieID    = movieID
                            });
                            if (sid > 0)
                            {
                                Console.WriteLine(name + "\t" + meat + "\t写入数据库成功!");
                            }
                            else
                            {
                                Console.WriteLine(name + "\t" + meat + "\t写入数据库失败!");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }