/// <summary> /// 生成内容页--影视 /// </summary> /// <param name="album"></param> /// <param name="cls"></param> public string CreateContentPage(MovieInfo movie, Class cls) { DataEntities ent = new DataEntities(); string Content = ""; TemplateContent temp = GetContentTemplate(cls); Content = temp.Content; //公共变量 Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); //系统参数 Content = ReplaceSystemSetting(Content); #region 替换内容 Content = Content.Replace("[!--class.id--]", cls.ID.ToString()); Content = Content.Replace("[!--class.name--]", cls.ClassName); Content = Content.Replace("[!--class.url--]", BasePage.GetClassUrl(cls)); Content = ReplaceContent(Content, movie, cls); StringBuilder sb = new StringBuilder(); List<MovieUrlKuaib> qb = (from l in ent.MovieUrlKuaib where l.MovieID == movie.id select l).ToList(); string list_tmp = GetTempateString(1, TempType.下载地址); foreach (MovieUrlKuaib q in qb) { string row = list_tmp.Replace("[!--url.id--]", q.id.ToS()); row = row.Replace("[!--url.url--]", q.Url); row = row.Replace("[!--url.title--]", q.Title); row = row.Replace("[!--url.movieid--]", q.MovieID.ToS()); row = row.Replace("[!--url.movietitle--]", q.MovieTitle); row = row.Replace("[!--url--]", BasePage.GetMovieDramaUrl(q, q.GetClass())); sb.Append(row); } Content = Content.Replace("[!--movie.kuib--]", sb.ToS()); sb = new StringBuilder(); List<MovieUrlBaidu> baidu = (from l in ent.MovieUrlBaidu where l.MovieID == movie.id select l).ToList(); foreach (MovieUrlBaidu q in baidu) { string row = list_tmp.Replace("[!--url.id--]", q.id.ToS()); row = row.Replace("[!--url.url--]", q.Url); row = row.Replace("[!--url.title--]", q.Title); row = row.Replace("[!--url.movieid--]", q.MovieID.ToS()); row = row.Replace("[!--url.movietitle--]", q.MovieTitle); row = row.Replace("[!--url--]", BasePage.GetMovieDramaUrl(q, q.GetClass())); sb.Append(row); } Content = Content.Replace("[!--movie.baidu--]", sb.ToS()); sb = new StringBuilder(); List<MovieUrlMag> mag = (from l in ent.MovieUrlMag where l.MovieID == movie.id select l).ToList(); foreach (MovieUrlMag q in mag) { string row = list_tmp.Replace("[!--url.id--]", q.id.ToS()); row = row.Replace("[!--url.url--]", q.Url); row = row.Replace("[!--url.title--]", q.Title); row = row.Replace("[!--url.movieid--]", q.MovieID.ToS()); row = row.Replace("[!--url.movietitle--]", q.MovieTitle); sb.Append(row); } Content = Content.Replace("[!--movie.mag--]", sb.ToS()); #endregion Content = ReplaceTagContent(Content); //替换导航条 Content = Content.Replace("[!--newsnav--]", BuildClassNavString(cls)); ent.Dispose(); return Content; }
/// <summary> /// 替换影视 /// </summary> /// <param name="temp"></param> /// <param name="TempString"></param> /// <param name="m"></param> /// <param name="c"></param> /// <returns></returns> public string ReplaceContent(TemplateList temp, string TempString, MovieInfo m, Class c) { string str_lst = temp.ListVar; str_lst = str_lst.Replace("[!--movie.url--]", BasePage.GetMovieUrl(m, m.GetClass())); str_lst = str_lst.Replace("[!--movie.actors--]", m.Actors); str_lst = str_lst.Replace("[!--movie.classid--]", m.ClassID.ToS()); str_lst = str_lst.Replace("[!--movie.classname--]", m.ClassName); str_lst = str_lst.Replace("[!--movie.director--]", m.Director); str_lst = str_lst.Replace("[!--movie.enable--]", m.Enable.ToInt32().ToS()); str_lst = str_lst.Replace("[!--movie.faceimage--]", m.FaceImage); str_lst = str_lst.Replace("[!--movie.id--]", m.id.ToS()); str_lst = str_lst.Replace("[!--movie.inserttime--]", m.InsertTime.ToDateTime().ToString(temp.TimeFormat)); str_lst = str_lst.Replace("[!--movie.intro--]", m.Intro.TrimHTML()); str_lst = str_lst.Replace("[!--movie.ismove--]", m.IsMove.ToInt32().ToS()); str_lst = str_lst.Replace("[!--movie.lastdramatitle--]", m.LastDramaTitle); str_lst = str_lst.Replace("[!--movie.location--]", m.Location); str_lst = str_lst.Replace("[!--movie.publicyear--]", m.PublicYear); str_lst = str_lst.Replace("[!--movie.status--]", m.Status.ToS()); str_lst = str_lst.Replace("[!--movie.tags--]", m.Tags); str_lst = str_lst.Replace("[!--movie.title--]", m.Title); str_lst = str_lst.Replace("[!--movie.updatetimetime--]", m.UpdateTime.ToDateTime().ToString(temp.TimeFormat)); return str_lst; }
public string ReplaceContent(string TempString, MovieInfo n, Class c) { return ReplaceContent(new TemplateList() { TimeFormat = "yyyy-MM-dd HH:mm:ss", CutTitle = 0 }, TempString, n, c); }
/// <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> 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> /// 获取资源URL单独存放的资源 /// </summary> /// <param name="Encoding"></param> /// <param name="mv"></param> /// <param name="BaiduUrlRule"></param> /// <param name="KuaiboUrlRule"></param> /// <param name="UrlEncoding"></param> /// <returns></returns> protected MovieInfo GetMovieSource(string Encoding, MovieInfo mv, string BaiduUrlRule, string KuaiboUrlRule) { foreach (var drama in mv.KuaiboDramas) { Response.Write(string.Format("打开资源脚本:{0}<br />", drama.Title)); Js.ScrollEndStart(); string html = Url.GetHtml(drama.SourceDataUrl, Encoding); Match m_source = html.GetMatchGroup(KuaiboUrlRule); if (m_source.Success) { Response.Write(string.Format("成功!:-D<br />")); Js.ScrollEndStart(); drama.Url = m_source.Groups[1].Value.UrlDecode(System.Text.Encoding.Unicode); } } foreach (var drama in mv.BaiduDramas) { Response.Write(string.Format("打开资源脚本:{0}<br />", drama.Title)); Js.ScrollEndStart(); string html = Url.GetHtml(drama.SourceDataUrl, Encoding); Match m_source = html.GetMatchGroup(BaiduUrlRule); if (m_source.Success) { Response.Write(string.Format("成功!:-D<br />")); Js.ScrollEndStart(); drama.Url = m_source.Groups[1].Value.UrlDecode(System.Text.Encoding.Unicode); } } return mv; }
/// <summary> /// 获取单个剧集的详细信息 /// </summary> /// <param name="Encoding">编码</param> /// <param name="mv">剧集的大概信息</param> /// <param name="InfoRule">剧集信息规则</param> /// <param name="KuaibAreaRule">快播区域规则</param> /// <param name="BaiduAreaRule">百度影音区域规则</param> /// <param name="KuaibDramaRule">快播单集规则</param> /// <param name="BaiduDramaRule">百度影音单集规则</param> /// <returns></returns> protected MovieInfo GetMovieInfo(string Encoding, MovieInfo mv, string InfoRule, string KuaibAreaRule, string BaiduAreaRule, string KuaibDramaRule, string BaiduDramaRule) { Response.Write(string.Format("打开信息页面:{0}<br />", mv.Title)); Js.ScrollEndStart(); string html = Url.GetHtml(mv.Url, Encoding); mv.Html = html; Match m_info = html.GetMatchGroup(InfoRule); if (m_info.Success) { //开始获取信息 mv.Actors = mv.Actors.IsNull(m_info.Groups["actors"].Value); mv.ClassName = mv.ClassName.IsNull(m_info.Groups["class"].Value); mv.Director = mv.Director.IsNull(m_info.Groups["director"].Value); mv.Enable = true; mv.FaceImage = mv.FaceImage.IsNull(m_info.Groups["image"].Value); mv.Intro = mv.Intro.IsNull(m_info.Groups["intro"].Value); mv.Location = mv.Location.IsNull(m_info.Groups["location"].Value); mv.PublicYear = mv.PublicYear.IsNull(m_info.Groups["publicyear"].Value); mv.Tags = mv.Tags.IsNull(m_info.Groups["tags"].Value); mv.Title = mv.Title.IsNull(m_info.Groups["title"].Value); } else { throw new Exception("电影信息匹配失败!"); } mv.KuaiboDramas = new List<MovieDrama>(); mv.BaiduDramas = new List<MovieDrama>(); #region 获取快播剧集地址 Match m_kuaiboArea = html.GetMatchGroup(KuaibAreaRule); if (m_kuaiboArea.Success && KuaibAreaRule.IsNullOrEmpty() == false) { Match m_drama = m_kuaiboArea.Groups[1].Value.GetMatchGroup(KuaibDramaRule); while (m_drama.Success) { mv.KuaiboDramas.Add(new MovieDrama() { Title = m_drama.Groups["title"].Value, PlayUrl = m_drama.Groups["playurl"].Value, Url = m_drama.Groups["url"].Value }); m_drama = m_drama.NextMatch(); } } #endregion #region 获取百度影音剧集地址 Match m_baiduArea = html.GetMatchGroup(BaiduAreaRule); if (m_baiduArea.Success && BaiduAreaRule.IsNullOrEmpty() == false) { Match m_drama = m_kuaiboArea.Groups[1].Value.GetMatchGroup(BaiduDramaRule); while (m_drama.Success) { mv.BaiduDramas.Add(new MovieDrama() { Title = m_drama.Groups["title"].Value, PlayUrl = m_drama.Groups["playurl"].Value, Url = m_drama.Groups["url"].Value }); m_drama = m_drama.NextMatch(); } } #endregion return mv; }
protected MovieInfo GetMovieDrama(string Encoding, MovieInfo mv, string BaiduUrlRule, string KuaibUrlRule) { #region 获取百度Url foreach (var drama in mv.BaiduDramas) { Response.Write(string.Format("获取百度URL:{0}<br />", drama.Title)); Js.ScrollEndStart(); if (drama.Url.IsNullOrEmpty() == false) { continue; } else { string html = Url.GetHtml(drama.PlayUrl, Encoding); Match m_url = html.GetMatchGroup(BaiduUrlRule); if (m_url.Success) { drama.Url = m_url.Groups["url"].Value; drama.SourceDataUrl = m_url.Groups["source"].Value.AppendToDomain(drama.Url); } } } #endregion #region 获取快播Url foreach (var drama in mv.KuaiboDramas) { Response.Write(string.Format("获取快播URL:{0}<br />", drama.Title)); Js.ScrollEndStart(); if (drama.Url.IsNullOrEmpty() == false) { continue; } else { string html = Url.GetHtml(drama.PlayUrl, Encoding); Match m_url = html.GetMatchGroup(KuaibUrlRule); if (m_url.Success) { drama.Url = m_url.Groups["url"].Value; drama.SourceDataUrl = m_url.Groups["source"].Value.AppendToDomain(drama.Url); } } } #endregion return mv; }