/// <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)); }