Exemple #1
0
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            //修改或者新增
            MovieRule r = new MovieRule();

            if (ddl_RuleList.SelectedValue.IsNullOrEmpty() == false)
            {
                string FileName = Server.MapPath(string.Format("~/Config/MovieRule/{0}", ddl_RuleList.SelectedValue));

                r = (MovieRule)Voodoo.IO.XML.DeSerialize(typeof(MovieRule), Voodoo.IO.File.Read(FileName));
            }

            r.BaiduAreaRule = txt_BaiduAreaRule.Text;
            r.BaiduDramaRule = txt_BaiduDramaRule.Text;
            r.DefaultClass = txt_DefaultClass.Text;
            r.DramaPageBaiduRule = txt_DramaPageBaiduRule.Text;
            r.DramaPageKuaibRule = txt_DramaPageKuaibRule.Text;
            r.Encoding = ddl_Encoding.SelectedValue;
            r.InfoRule = txt_InfoRule.Text;
            r.IsMovie = chk_IsMovie.Checked;
            r.IsSearchRule = chk_IsSearchRule.Checked;
            r.KuaibAreaRule = txt_KuaibAreaRule.Text;
            r.KuaibDramaRule = txt_KuaibDramaRule.Text;
            r.ListInfoRule = txt_ListInfoRule.Text;
            r.ListPageUrl = txt_ListPageUrl.Text;
            r.Name = txt_Name.Text;
            r.NextListRule = txt_NextListRule.Text;
            r.SiteName = txt_SiteName.Text;
            r.SourceBaiduRule = txt_SourceBaiduRule.Text;
            r.SourceKuaibRule = txt_SourceKuaibRule.Text;
            r.UseLocationAsClass = chk_UseLocationAsClass.Checked;
            r.UseTagAsClass = chk_UseTagAsClass.Checked;

            Voodoo.IO.XML.SaveSerialize(r, Server.MapPath(string.Format("~/Config/MovieRule/{0}.xml", r.Name)));
        }
        /// <summary>
        /// 根据采集规则采集
        /// </summary>
        /// <param name="r">规则</param>
        protected void CollectByRule(MovieRule r)
        {
            Response.Buffer = false;
            Js.ScrollEnd();

            #region 打开列表页面
            Response.Write(string.Format("打开列表页面获得书籍信息<br />"));
            Js.ScrollEndStart();

            var Movies = GetAllMovies(r.Encoding,
                r.ListPageUrl,
                r.NextListRule,
                r.ListInfoRule,
                false);
            #endregion

            #region 补充电影的详细内容 剧集

            Response.Write(string.Format("获取影视详细内容<br />"));
            Js.ScrollEndStart();

            var NewMovies = new List<MovieInfo>();
            foreach (var m in Movies)
            {
                var nm = GetMovieInfo(r.Encoding,
                    m,
                    r.InfoRule,
                    r.KuaibAreaRule,
                    r.BaiduAreaRule,
                    r.KuaibDramaRule,
                    r.BaiduDramaRule);
                NewMovies.Add(nm);
            }

            Movies = NewMovies;

            #endregion

            #region 补充带单集播放页面的资源URL
            NewMovies = new List<MovieInfo>();
            foreach (var m in Movies)
            {
                if (r.IsSearchRule)
                {
                    break;//搜索系统不需要采集剧集信息
                }
                var nm = GetMovieDrama(r.Encoding, m, r.DramaPageBaiduRule, r.DramaPageKuaibRule);
                NewMovies.Add(nm);
            }

            Movies = NewMovies;

            #endregion

            #region 补充资源URL单独存放的单集信息
            NewMovies = new List<MovieInfo>();
            foreach (var m in Movies)
            {
                if (r.IsSearchRule)
                {
                    break;//搜索系统不需要采集剧集信息
                }
                var nm = GetMovieSource(r.Encoding, m, r.SourceBaiduRule, r.SourceKuaibRule);
                NewMovies.Add(nm);
            }

            Movies = NewMovies;
            #endregion

            #region 处理默认的分类信息
            NewMovies = new List<MovieInfo>();
            foreach (var m in Movies)
            {
                if (m.ClassName.IsNullOrEmpty())
                {
                    if (r.UseTagAsClass)
                    {
                        m.ClassName = m.Tags;
                    }
                    if (r.UseLocationAsClass)
                    {
                        m.ClassName = m.Location;
                    }
                    if (m.ClassName.IsNullOrEmpty())
                    {
                        m.ClassName = r.DefaultClass;
                    }
                }
                m.IsMove = r.IsMovie;

                NewMovies.Add(m);
            }

            Movies = NewMovies;

            #endregion

            #region 保存
            foreach (var m in Movies)
            {
                SaveMovie(m, r.IsSearchRule,r.SiteName);
            }
            #endregion
        }