protected void btn_Save_Click(object sender, EventArgs e) { int id = WS.RequestInt("id"); MovieInfo mi = MovieInfoView.GetModelByID(id.ToS()); mi.ClassID = ddl_Class.SelectedItem.Value.ToInt32(); mi.ClassName = ddl_Class.SelectedItem.Text; mi.Title = txt_Title.Text; mi.Director = txt_Director.Text; mi.Actors = txt_Actors.Text; mi.Tags = txt_Tags.Text; mi.Location = txt_Location.Text; mi.PublicYear = txt_PublicYear.Text; mi.Intro = txt_Intro.Text; mi.IsMove = chk_IsMovie.Checked; mi.Status = rbl_Status.SelectedValue.ToInt32(); mi.Enable = chk_Enable.Checked; mi.Info = FCKeditor1.Value; mi.InsertTime = DateTime.UtcNow.AddHours(8); mi.UpdateTime = DateTime.UtcNow.AddHours(8); mi.LastClickTime = DateTime.UtcNow.AddHours(8); if (mi.Id > 0) { //update MovieInfoView.Update(mi); } else { MovieInfoView.Insert(mi); } //Deal Book face image if (file_Moviefacefile.FileName.IsNullOrEmpty() == false) { file_Moviefacefile.SaveAs(Server.MapPath("/u/MoviekFace/" + mi.Id + ".jpg")); mi.FaceImage = "/u/MoviekFace/" + mi.Id + ".jpg"; MovieInfoView.Update(mi); } //Class c=MovieInfoView.GetClass(mi); ////Create statis pages //CreatePage.CreateContentPage(mi, c); //var kuaibos = MovieUrlKuaibView.GetModelList(string.Format("MovieID={0}", mi.Id)); //var baidus = MovieUrlBaiduView.GetModelList(string.Format("MovieID={0}", mi.Id)); //var dramas = MovieDramaView.GetModelList(string.Format("MovieID={0}", mi.Id)); ////foreach (var kuaib in kuaibos) //{ // CreatePage.CreateDramapage(kuaib, c); //} //foreach (var baidu in baidus) //{ // CreatePage.CreateDramapage(baidu, c); //} //foreach (var drama in dramas) //{ // CreatePage.CreateDramapage(drama, c); //} Response.Redirect(url); }
/// <summary> /// 旧的电影采集 /// </summary> protected void OldCollect() { Response.Buffer = false; //打开列表页面 Response.Write("打开列表页面<br/>"); string listUrl = "http://kuaib.tv.sohu.com/html/more_list21.htm"; openurl: string html_List = Url.GetHtml(listUrl, "utf-8"); //打开信息页面 Match m_list = html_List.GetMatchGroup("<img src=\"(?<image>.*?)\" width=\"120\" height=\"165\" alt=\"\" />[\\s\\S]*?<h4><a href=\"(?<url>.*?)\" target=\"_blank\">(?<title>.*?)</a></h4>"); while (m_list.Success) { //判断是否存在 if (MovieInfoView.Exist(string.Format("Title=N'{0}'", m_list.Groups["title"].Value))) { m_list = m_list.NextMatch(); continue; } Response.Write("下载封面<br/>"); //如果不存在,则先下载封面,内容页面是没有封面的 try { Url.DownFile(m_list.Groups["image"].Value, Server.MapPath("~/config/movieface.jpg")); } catch (Exception ex) { Response.Write(ex.Message + "<br/>"); } //打开内容页面 Response.Write("打开内容页面<br/>"); string html_content = Url.GetHtml(m_list.Groups["url"].Value, "utf-8"); Match m_movie = html_content.GetMatchGroup("<em id='specialID'>《(?<title>.*?)》</em>[\\s\\S]*?<param name='URL' value='(?<url>.*?)'>[\\s\\S]*?<div id=\"introID\">[\\s]*?<p>(?<intro>[\\s\\S]*?)</p>[\\s\\S]*?var VRS_DIRECTOR=\"(?<director>.*?)\";[\\s\\S]*?var VRS_CATEGORY=\"(?<tags>.*?)\";[\\s\\S]*?var VRS_ACTOR=\"(?<actor>.*?)\";[\\s\\S]*?var VRS_AREA=\"(?<location>.*?)\";[\\s\\S]*?var VRS_PLAY_YEAR=\"(?<year>.*?)\";"); if (!m_movie.Success) { Response.Write("!!!!!内容匹配失败<br/>"); } string title = m_movie.Groups["title"].Value; string intro = m_movie.Groups["intro"].Value; string director = m_movie.Groups["director"].Value; string actor = m_movie.Groups["actor"].Value; string location = m_movie.Groups["location"].Value; string url = m_movie.Groups["url"].Value; string year = m_movie.Groups["year"].Value; string tags = m_movie.Groups["tags"].Value; Response.Write("处理类别:" + location + "<br/>"); Class cls = ClassView.Find(string.Format("classname=N'{0}'", location)); if (cls.ID <= 0) { cls.Alter = location; cls.ClassKeywords = location + "在线观看"; cls.ClassName = location; cls.IsLeafClass = true; cls.ShowInNav = true; cls.ClassForder = location; cls.ModelID = 6; ClassView.Insert(cls); } MovieInfo mv = new MovieInfo(); mv.Actors = actor; mv.ClassID = cls.ID; mv.ClassName = cls.ClassName; mv.ClickCount = 0; mv.Director = director; mv.Enable = true; mv.InsertTime = DateTime.Now; mv.Intro = intro; mv.IsMove = true; mv.Location = location; mv.PublicYear = year; mv.ReplyCount = 0; mv.ScoreAvg = 10; mv.ScoreTime = 0; mv.Status = 1; mv.Tags = tags; mv.Title = title; mv.TjCount = 0; mv.UpdateTime = DateTime.Now; Response.Write("保存:" + title + "<br/>"); MovieInfoView.Insert(mv); //设置封面 Response.Write("设置封面<br/>"); mv.FaceImage = string.Format("/u/MoviekFace/{0}.jpg", mv.Id); try { Voodoo.IO.File.Move(Server.MapPath("~/config/movieface.jpg"), Server.MapPath(mv.FaceImage)); } catch { Voodoo.IO.File.Copy(Server.MapPath("~/config/0.jpg"), Server.MapPath(mv.FaceImage)); } MovieInfoView.Update(mv); //添加地址 Response.Write("添加地址:" + url + "<br/>"); MovieUrlKuaib mk = new MovieUrlKuaib(); mk.Enable = true; mk.MovieID = mv.Id; mk.MovieTitle = mv.Title; mk.Title = "全集"; mk.UpdateTime = DateTime.Now; mk.Url = url; MovieUrlKuaibView.Insert(mk); //生成 Response.Write("生成<br/>"); //CreatePage.CreateDramapage(mk,cls); //CreatePage.CreateContentPage(mv,cls); //CreatePage.CreateListPage(cls,0); //CreatePage.GreateIndexPage(); Response.Write(title + "-完成<br/><br/><br/>"); m_list = m_list.NextMatch(); } //处理列表下一页 Match m_next = html_List.GetMatchGroup("<a href='(?<key>[^'/]*?)'>下一页</a>"); if (m_next.Success) { listUrl = m_next.Groups["key"].Value.AppendToDomain(listUrl); goto openurl; } }
/// <summary> /// 保存影视信息 /// </summary> /// <param name="mv"></param> protected void SaveMovie(MovieInfo mv, bool IsSearchRule, string SiteName) { #region 处理分类 Class cls = ClassView.Find(string.Format("ClassName=N'{0}'", mv.ClassName)); if (cls.ID <= 0) { cls.IsLeafClass = true; cls.Alter = mv.ClassName; cls.ClassForder = mv.ClassName; cls.ShowInNav = true; cls.ParentID = 0; cls.ClassName = mv.ClassName; cls.ModelID = 6; ClassView.Insert(cls); } mv.ClassID = cls.ID; #endregion #region 保存影视 MovieInfo sysMv = MovieInfoView.Find(string.Format("Title=N'{0}' and ClassName=N'{1}'", mv.Title, mv.ClassName)); if (sysMv.Id <= 0) { sysMv = mv; sysMv.ClickCount = 0; sysMv.Enable = true; sysMv.InsertTime = DateTime.UtcNow.AddHours(8); sysMv.ReplyCount = 0; sysMv.ScoreAvg = 10; sysMv.ScoreTime = 0;//评分次数 sysMv.Status = 0; sysMv.TjCount = 0; sysMv.UpdateTime = DateTime.UtcNow.AddHours(8); MovieInfoView.Insert(sysMv); } else { sysMv.BaiduDramas = mv.BaiduDramas; sysMv.KuaiboDramas = mv.KuaiboDramas; } #endregion #region 载封面 try { Url.DownFile(sysMv.FaceImage, Server.MapPath(string.Format("~/u/MoviekFace/{0}.jpg", sysMv.Id))); sysMv.FaceImage = string.Format("/u/MoviekFace/{0}.jpg", sysMv.Id); } catch { sysMv.FaceImage = "/u/MoviekFace/0.jpg"; } MovieInfoView.Update(sysMv); #endregion #region 保存单集资源 if (IsSearchRule == false) { #region 是电影搜索 foreach (var drama in sysMv.BaiduDramas) { var sysDrama = MovieUrlBaiduView.Find(string.Format("MovieID={0} and Title=M'{0}' ", sysMv.Id, drama.Title)); if (sysDrama.Id <= 0) { sysDrama.Title = drama.Title; sysDrama.Url = drama.Url; sysDrama.Enable = true; sysDrama.MovieID = sysMv.Id; sysDrama.MovieTitle = sysMv.Title; sysDrama.UpdateTime = DateTime.UtcNow.AddHours(8); MovieUrlBaiduView.Insert(sysDrama); sysMv.LastDramaTitle = sysDrama.Title; sysMv.LastDramaID = sysDrama.Id; MovieInfoView.Update(sysMv); CreatePage.CreateDramapage(sysDrama, cls);//生成 Response.Write(string.Format("百度影音《{0}》《{1}》保存成功!:-D<br />", sysDrama.MovieTitle, sysDrama.Title)); } else { Response.Write(string.Format("已经存在%>_<%<br />")); } } foreach (var drama in sysMv.KuaiboDramas) { var sysDrama = MovieUrlKuaibView.Find(string.Format("MovieID={0} and Title=N'{0}' ", sysMv.Id, drama.Title)); if (sysDrama.Id <= 0) { sysDrama.Title = drama.Title; sysDrama.Url = drama.Url; sysDrama.Enable = true; sysDrama.MovieID = sysMv.Id; sysDrama.MovieTitle = sysMv.Title; sysDrama.UpdateTime = DateTime.UtcNow.AddHours(8); MovieUrlKuaibView.Insert(sysDrama); sysMv.LastDramaTitle = sysDrama.Title; sysMv.LastDramaID = sysDrama.Id; MovieInfoView.Update(sysMv); CreatePage.CreateDramapage(sysDrama, cls); Response.Write(string.Format("快播《{0}》《{1}》保存成功!:-D<br />", sysDrama.MovieTitle, sysDrama.Title)); } else { Response.Write(string.Format("已经存在%>_<%<br />")); } } #endregion } else { //电影搜索不需要保存资源地址 只需要保存 新建剧集和播放页面地址 #region 快播地址 foreach (var drama in mv.KuaiboDramas) { var sysDrama = MovieDramaView.Find(string.Format("MovieTitle=N'{0}' and Title=N'{1}'", drama.MovieTitle, drama.Title)); if (sysDrama.Id <= 0) { sysDrama.Enable = true; sysDrama.MovieID = mv.Id; sysDrama.MovieTitle = mv.Title; sysDrama.Title = drama.Title; sysDrama.UpdateTime = DateTime.UtcNow.AddHours(8); MovieDramaView.Insert(sysDrama); } var sysUrl = MovieDramaUrlView.Find(string.Format("MovieID={0} and MovieDramaID={1} and SourceSite=N'{2}'", drama.MovieID, drama.Id, SiteName)); if (sysUrl.Id <= 0) { sysUrl.Enable = true; sysUrl.MovieDramaID = drama.Id; sysUrl.MovieDramaTitle = drama.Title; sysUrl.MovieID = mv.Id; sysUrl.MovieTitle = mv.Title; sysUrl.SourceSite = SiteName; sysUrl.Title = drama.Title; sysUrl.UpdateTime = DateTime.UtcNow.AddHours(8); sysUrl.Url = drama.PlayUrl.IsNull(mv.Url); } } #endregion #region 百度影音 foreach (var drama in mv.BaiduDramas) { var sysDrama = MovieDramaView.Find(string.Format("MovieTitle=N'{0}' and Title=N'{1}'", drama.MovieTitle, drama.Title)); if (sysDrama.Id <= 0) { sysDrama.Enable = true; sysDrama.MovieID = mv.Id; sysDrama.MovieTitle = mv.Title; sysDrama.Title = drama.Title; sysDrama.UpdateTime = DateTime.UtcNow.AddHours(8); MovieDramaView.Insert(sysDrama); } var sysUrl = MovieDramaUrlView.Find(string.Format("MovieID={0} and MovieDramaID={1} and SourceSite=N'{2}'", drama.MovieID, drama.Id, SiteName)); if (sysUrl.Id <= 0) { sysUrl.Enable = true; sysUrl.MovieDramaID = drama.Id; sysUrl.MovieDramaTitle = drama.Title; sysUrl.MovieID = mv.Id; sysUrl.MovieTitle = mv.Title; sysUrl.SourceSite = SiteName; sysUrl.Title = drama.Title; sysUrl.UpdateTime = DateTime.UtcNow.AddHours(8); sysUrl.Url = drama.PlayUrl.IsNull(mv.Url); } } #endregion } #endregion #region 生成 Response.Write(string.Format("生成《{0}》信息页<br />", sysMv.Title)); CreatePage.CreateContentPage(sysMv, cls); Response.Write(string.Format("生成“{0}”分类<br />", cls.ClassName)); CreatePage.CreateListPage(cls, 1); #endregion }
/// <summary> /// 获取保存电影详细信息 /// </summary> /// <param name="rulename">规则名称</param> /// <param name="url">地址</param> /// <param name="cls">分类名称</param> /// <param name="title">标题</param> /// <param name="director">导演</param> /// <param name="actors">演员</param> /// <param name="tags">tag</param> /// <param name="location">位置</param> /// <param name="publicyear">上映年代</param> /// <param name="intro">简介</param> /// <param name="image">图片</param> protected void GetMovieInfo(string rulename, string url, string cls, string title, string director, string actors, string tags, string location, string publicyear, string intro, string image) { url = url.UrlDecode(); MovieRule _r = Rules.Where(p => p.Name == rulename).First(); MovieRule r = _r.Clone(); Class c = new Class(); string html = Url.GetHtml(url, r.Encoding); Match m_info = html.GetMatchGroup(r.InfoRule); MovieInfo mv = MovieInfoView.Find(string.Format("title=N'{0}'", m_info.Groups["title"].Value)); if (mv.Id <= 0) { if (m_info.Success) { //开始获取信息 mv.Actors = m_info.Groups["actors"].Value.IsNull(actors).TrimHTML(); mv.ClassName = m_info.Groups["class"].Value.IsNull(cls).IsNull(r.DefaultClass); mv.Director = m_info.Groups["director"].Value.IsNull(director); mv.Enable = true; mv.FaceImage = m_info.Groups["image"].Value.IsNull(image).AppendToDomain(url); mv.Intro = m_info.Groups["intro"].Value.IsNull(intro).TrimHTML(); mv.Location = m_info.Groups["location"].Value.IsNull(location); mv.PublicYear = m_info.Groups["publicyear"].Value.IsNull(publicyear); mv.Tags = m_info.Groups["tags"].Value.IsNull(tags); mv.Title = m_info.Groups["title"].Value.IsNull(title); mv.Info = Regex.Replace(mv.Intro, "<a.*?>", "", RegexOptions.IgnoreCase); mv.Info = Regex.Replace(mv.Intro, "</a>", "", RegexOptions.IgnoreCase); mv.Intro = mv.Info.TrimHTML().CutString(200); mv.ClickCount = 0; mv.InsertTime = DateTime.UtcNow.AddHours(8); mv.IsMove = r.IsMovie; mv.ReplyCount = 0; mv.ScoreAvg = 10; mv.ScoreTime = 0; mv.Status = 0; mv.TjCount = 0; mv.DayClick = 0; mv.WeekClick = 0; mv.MonthClick = 0; mv.LastClickTime = DateTime.UtcNow.AddHours(8); mv.UpdateTime = DateTime.UtcNow.AddHours(8); #region 处理分类 c = ClassView.Find(string.Format("ClassName=N'{0}'", mv.ClassName)); if (c.ID <= 0) { c.IsLeafClass = true; c.Alter = mv.ClassName; c.ClassForder = mv.ClassName; c.ShowInNav = true; c.ParentID = 0; c.ClassName = mv.ClassName; c.ModelID = 6; ClassView.Insert(c); } mv.ClassID = c.ID; #endregion //不存在这个电影就要保存到数据库 MovieInfoView.Insert(mv); #region 载封面 try { Url.DownFile(mv.FaceImage, Server.MapPath(string.Format("~/u/MoviekFace/{0}.jpg", mv.Id))); mv.FaceImage = string.Format("/u/MoviekFace/{0}.jpg", mv.Id); } catch { mv.FaceImage = "/u/MoviekFace/0.jpg"; } MovieInfoView.Update(mv); #endregion } else { throw new Exception("电影信息匹配失败!"); } } else { c = ClassView.GetModelByID(mv.ClassID.ToString()); } mv.BaiduDramas = new List <MovieUrlBaidu>(); mv.KuaiboDramas = new List <MovieUrlKuaib>(); #region 获取快播剧集 Match m_kuaiboArea = html.GetMatchGroup(r.KuaibAreaRule); if (m_kuaiboArea.Success && r.KuaibAreaRule.IsNullOrEmpty() == false) { string html_kuaiboArea = m_kuaiboArea.Groups[1].Value; Match m_kuaibo = html_kuaiboArea.GetMatchGroup(r.KuaibDramaRule); while (m_kuaibo.Success) { //判断是够存在 if (MovieUrlKuaibView.Exist(string.Format("MovieId={0} and Title=N'{1}'", mv.Id, m_kuaibo.Groups["title"].Value))) { m_kuaibo = m_kuaibo.NextMatch(); continue; } mv.KuaiboDramas.Add(new MovieUrlKuaib() { MovieID = mv.Id, Enable = true, PlayUrl = m_kuaibo.Groups["playurl"].Value.AppendToDomain(url), MovieTitle = mv.Title, Title = m_kuaibo.Groups["title"].Value.IsNull("全集"), UpdateTime = DateTime.UtcNow.AddHours(8), Url = m_kuaibo.Groups["url"].Value }); m_kuaibo = m_kuaibo.NextMatch(); } } #endregion #region 获取百度剧集 Match m_baiduArea = html.GetMatchGroup(r.BaiduAreaRule); if (m_baiduArea.Success && r.BaiduAreaRule.IsNullOrEmpty() == false) { string html_baiduArea = m_baiduArea.Groups[1].Value; Match m_baidu = html_baiduArea.GetMatchGroup(r.BaiduDramaRule); while (m_baidu.Success) { //判断是够存在 if (MovieUrlBaiduView.Exist(string.Format("MovieId={0} and Title=N'{1}'", mv.Id, m_baidu.Groups["title"].Value))) { m_baidu = m_baidu = m_baidu.NextMatch(); continue; } mv.BaiduDramas.Add(new MovieUrlBaidu() { MovieID = mv.Id, Enable = true, PlayUrl = m_baidu.Groups["playurl"].Value.AppendToDomain(url), MovieTitle = mv.Title, Title = m_baidu.Groups["title"].Value.IsNull("全集"), UpdateTime = DateTime.UtcNow.AddHours(8), Url = m_baidu.Groups["url"].Value }); m_baidu = m_baidu = m_baidu.NextMatch(); } } #endregion #region 如果是搜索系统,则只保存播放地址即可 if (r.IsSearchRule) { foreach (var drama in mv.KuaiboDramas) { #region 处理剧集 var sysDrama = MovieDramaView.Find(string.Format("MovieTitle=N'{0}' and Title=N'{1}'", drama.MovieTitle, drama.Title)); if (sysDrama.Id <= 0) { sysDrama.Enable = true; sysDrama.MovieID = mv.Id; sysDrama.MovieTitle = mv.Title; sysDrama.Title = drama.Title; sysDrama.UpdateTime = drama.UpdateTime; MovieDramaView.Insert(sysDrama); } #endregion #region 处理播放地址 var playUrl = MovieDramaUrlView.Find(string.Format("MovieDramaID={0} and Url=N'{1}'", sysDrama.Id, drama.PlayUrl.IsNull(url))); if (playUrl.Id <= 0) { playUrl.Enable = true; playUrl.MovieDramaID = sysDrama.Id; playUrl.MovieDramaTitle = sysDrama.Title; playUrl.MovieID = mv.Id; playUrl.MovieTitle = mv.Title; playUrl.SourceSite = r.SiteName; playUrl.Title = r.SiteName; playUrl.UpdateTime = DateTime.Now.AddHours(8); playUrl.Url = drama.PlayUrl.IsNull(url); MovieDramaUrlView.Insert(playUrl); } #endregion } foreach (var drama in mv.BaiduDramas) { #region 处理剧集 var sysDrama = MovieDramaView.Find(string.Format("MovieTitle=N'{0}' and Title=N'{1}'", drama.MovieTitle, drama.Title)); if (sysDrama.Id <= 0) { sysDrama.Enable = true; sysDrama.MovieID = mv.Id; sysDrama.MovieTitle = mv.Title; sysDrama.Title = drama.Title; sysDrama.UpdateTime = drama.UpdateTime; MovieDramaView.Insert(sysDrama); } #endregion #region 处理播放地址 var playUrl = MovieDramaUrlView.Find(string.Format("MovieDramaID={0} and Url=N'{1}'", sysDrama.Id, drama.PlayUrl.IsNull(url))); if (playUrl.Id <= 0) { playUrl.Enable = true; playUrl.MovieDramaID = sysDrama.Id; playUrl.MovieDramaTitle = sysDrama.Title; playUrl.MovieID = mv.Id; playUrl.MovieTitle = mv.Title; playUrl.SourceSite = r.SiteName; playUrl.Title = r.SiteName; playUrl.UpdateTime = DateTime.Now.AddHours(8); playUrl.Url = drama.PlayUrl.IsNull(url); MovieDramaUrlView.Insert(playUrl); } #endregion } if (mv.BaiduDramas.Count > 0) { mv.LastDramaTitle = mv.BaiduDramas.Last().Title; mv.UpdateTime = DateTime.UtcNow.AddHours(8); MovieInfoView.Update(mv); } } #endregion #region 处理快播和百度影音 else { bool needCreate = false; foreach (var drama in mv.KuaiboDramas) { if (drama.Url.IsNullOrEmpty() == false) { var sysDrama = MovieUrlKuaibView.Find(string.Format("MovieID={0} and Title=N'{1}'", mv.Id, drama.Title)); if (sysDrama.Id <= 0) { MovieUrlKuaibView.Insert(drama); //保存完成 生成 //CreatePage.CreateDramapage(drama, c); //needCreate = true; } } } foreach (var drama in mv.BaiduDramas) { if (drama.Url.IsNullOrEmpty() == false) { var sysDrama = MovieUrlBaiduView.Find(string.Format("MovieID={0} and Title=N'{1}'", mv.Id, drama.Title)); if (sysDrama.Id <= 0) { MovieUrlBaiduView.Insert(drama); //保存完成 生成 //CreatePage.CreateDramapage(drama, c); //needCreate = true; } } } if (needCreate) { //CreatePage.CreateContentPage(mv, c); } if (mv.BaiduDramas.Count > 0) { mv.LastDramaTitle = mv.BaiduDramas.Last().Title; mv.UpdateTime = DateTime.UtcNow.AddHours(8); MovieInfoView.Update(mv); } } #endregion // 完成咯 Response.Clear(); Response.Write(JsonConvert.SerializeObject(mv)); }