public void CollectBaiduMovie(MovieInfo m, MovieRule r, string url, string Title) { string html = Url.GetHtml(url, r.Encoding); Match match = html.GetMatchGroup(r.BaiduDramaRule); if (match.Success && !r.BaiduDramaRule.IsNullOrEmpty() && !match.Groups["url"].Value.IsNullOrEmpty()) { MovieUrlBaidu drama = new MovieUrlBaidu(); drama.Enable = true; drama.MovieID = m.id; drama.MovieTitle = m.Title; drama.Title = Title.IsNull(match.Groups["title"].Value); drama.UpdateTime = DateTime.Now; drama.Url = match.Groups["url"].Value; using (kuaiboyingshiEntities ent = new kuaiboyingshiEntities()) { var dramas = (from l in ent.MovieUrlBaidu where l.MovieID == m.id && l.MovieTitle == drama.Title select l).ToList(); if (dramas.Count == 0) { ent.AddToMovieUrlBaidu(drama); ent.SaveChanges(); } } } else { Match m_source = html.GetMatchGroup(r.DramaPageBaiduRule); if (m_source.Success) { CollectSources(r, m_source.Groups["source"].Value.AppendToDomain(url), m); } } }
public void CollectSources(MovieRule r, string url, MovieInfo m) { white(); w("打开资源文件"); string html = Url.GetHtml(url, r.Encoding); w("分析资源内容"); var dramas = CollectDramas(html, m.id); dramas = dramas.OrderBy(p => p.Title).ToList(); w(string.Format("得到{0}个资源", dramas.Count)); using (kuaiboyingshiEntities ent = new kuaiboyingshiEntities()) { foreach (var drama in dramas) { if (drama.Type == "baidu") { ent.AddToMovieUrlBaidu(new MovieUrlBaidu() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = drama.Title, UpdateTime = DateTime.Now, Url = drama.Url }); } else { ent.AddToMovieUrlKuaib(new MovieUrlKuaib() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = drama.Title, UpdateTime = DateTime.Now, Url = drama.Url }); } m.UpdateTime = DateTime.Now; m.LastDramaTitle = drama.Title; w("保存"); ent.SaveChanges(); } w("保存"); ent.SaveChanges(); } }
public void CollectSources(MovieRule r, string url, MovieInfo m) { string html = Url.GetHtml(url, r.Encoding); var dramas = CollectDramas(html, m.id); using (kuaiboyingshiEntities ent = new kuaiboyingshiEntities()) { foreach (var drama in dramas) { if (drama.Type == "baidu") { ent.AddToMovieUrlBaidu(new MovieUrlBaidu() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = drama.Title, UpdateTime = DateTime.Now, Url = drama.Url }); } else { ent.AddToMovieUrlKuaib(new MovieUrlKuaib() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = drama.Title, UpdateTime = DateTime.Now, Url = drama.Url }); } m.UpdateTime = DateTime.Now; m.LastDramaTitle = drama.Title; } ent.SaveChanges(); } }
public void GetMovieInfo(MovieRule r, MovieInfo m, string InfoUrl) { string html = Url.GetHtml(InfoUrl, r.Encoding); using (kuaiboyingshiEntities ent = new kuaiboyingshiEntities()) { var movies = (from l in ent.MovieInfo where l.Title == m.Title select l).ToList(); if (movies.Count == 0) { Match match = html.GetMatchGroup(r.InfoRule); if (!match.Success) { return; } m.ClassName = m.ClassName.IsNull(match.Groups["class"].Value).IsNull("其他"); m.Title = match.Groups["title"].Value; m.Location = m.Title.IsNull(match.Groups["location"].Value); m.PublicYear = m.PublicYear.IsNull(match.Groups["publicyear"].Value).IsNull("2012");; m.Actors = m.Actors.IsNull(match.Groups["actors"].Value); m.Director = m.Director.IsNull(match.Groups["director"].Value); m.Info = m.Info.IsNull(match.Groups["intro"].Value); m.Intro = m.Intro.IsNull(match.Groups["intro"].Value); m.Status = 0; m.ClassID = GetClassByName(m.ClassName).ID; m.ClickCount = 0; m.DayClick = 0; m.InsertTime = DateTime.Now; m.IsMove = false; m.LastClickTime = DateTime.Now; m.LastDramaID = 0; m.LastDramaTitle = ""; m.MonthClick = 0; m.ReplyCount = 0; m.ScoreAvg = 0; m.ScoreTime = 0; m.StandardTitle = StandTitle(m.Title); m.Enable = true; ent.AddToMovieInfo(m); ent.SaveChanges(); SaveFace(match.Groups["image"].Value.AppendToDomain(InfoUrl), m.id); m.FaceImage = string.Format("/u/MovieFace/{0}.jpg", m.id); ent.SaveChanges(); } else { m = movies.FirstOrDefault(); } //获取百度和快播区域并且开始采集 #region 百度区域 Match m_baiduarea = html.GetMatchGroup(r.BaiduAreaRule); if (m_baiduarea.Success && !r.BaiduAreaRule.IsNullOrEmpty()) { Match m_drama = m_baiduarea.Groups["key"].Value.GetMatchGroup(r.BaiduDramaRule); while (m_drama.Success) { string title = m_drama.Groups["title"].Value; string playurl = m_drama.Groups["playurl"].Value; string url = m_drama.Groups["url"].Value; #region 打开播放页面处理 if (url.IsNullOrEmpty()) { CollectBaiduMovie(m, r, playurl.AppendToDomain(InfoUrl), title); if (!r.SourceBaiduRule.IsNullOrEmpty()) { break; } } #endregion else { var dramas = (from l in ent.MovieUrlBaidu where l.MovieID == m.id && l.Title == title select l); if (dramas.Count() == 0) { ent.AddToMovieUrlBaidu(new MovieUrlBaidu() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = title, UpdateTime = DateTime.Now, Url = url }); m.UpdateTime = DateTime.Now; ent.SaveChanges(); } } m_drama = m_drama.NextMatch(); } } #endregion #region 快播区域 Match m_kuaiboarea = html.GetMatchGroup(r.KuaibAreaRule); if (m_kuaiboarea.Success && !r.KuaibAreaRule.IsNullOrEmpty()) { Match m_drama = m_kuaiboarea.Groups["key"].Value.GetMatchGroup(r.KuaibAreaRule); while (m_drama.Success) { string title = m_drama.Groups["title"].Value; string playurl = m_drama.Groups["playurl"].Value; string url = m_drama.Groups["url"].Value; #region 打开播放页面处理 if (url.IsNullOrEmpty()) { CollectKuaiboMovie(m, r, playurl.AppendToDomain(InfoUrl), title); if (!r.SourceKuaibRule.IsNullOrEmpty()) { break; } } #endregion else { var dramas = (from l in ent.MovieUrlKuaib where l.MovieID == m.id && l.Title == title select l); if (dramas.Count() == 0) { ent.AddToMovieUrlKuaib(new MovieUrlKuaib() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = title, UpdateTime = DateTime.Now, Url = url }); m.UpdateTime = DateTime.Now; ent.SaveChanges(); } } m_drama = m_drama.NextMatch(); } } #endregion } }
public void GetMovieInfo(MovieRule r, MovieInfo m, string InfoUrl) { red(); w(string.Format("打开电影《{0}》的信息页:{1}", m.Title, InfoUrl)); string html = Url.GetHtml(InfoUrl, r.Encoding); using (kuaiboyingshiEntities ent = new kuaiboyingshiEntities()) { string short_title = m.Title.TrimEnd('.'); var movies = (from l in ent.MovieInfo where l.Title.Contains(short_title) select l).ToList(); Match match = html.GetMatchGroup(r.InfoRule); if (movies.Count == 0) { if (!match.Success) { w("这个电影无法和规则匹配\n "); return; } m.ClassName = m.ClassName.IsNull(match.Groups["class"].Value).IsNull("其他"); m.Title = match.Groups["title"].Value; m.Location = m.Title.IsNull(match.Groups["location"].Value); m.PublicYear = m.PublicYear.IsNull(match.Groups["publicyear"].Value).IsNull("2012");; m.Actors = m.Actors.IsNull(match.Groups["actors"].Value).TrimHTML(); m.Director = m.Director.IsNull(match.Groups["director"].Value); m.Info = m.Info.IsNull(match.Groups["intro"].Value).Replace(r.SiteName, ""); m.Intro = m.Intro.IsNull(match.Groups["intro"].Value).Replace(r.SiteName, ""); m.FaceImage = m.FaceImage.IsNull(match.Groups["image"].Value.AppendToDomain(InfoUrl)); m.Status = 0; m.ClassID = GetClassByName(m.ClassName).ID; m.ClickCount = 0; m.DayClick = 0; m.UpdateTime = DateTime.Now; m.InsertTime = DateTime.Now; m.IsMove = false; m.LastClickTime = DateTime.Now; m.LastDramaID = 0; m.LastDramaTitle = ""; m.MonthClick = 0; m.ReplyCount = 0; m.ScoreAvg = 0; m.ScoreTime = 0; m.StandardTitle = StandTitle(m.Title); m.Enable = true; if ((from l in ent.MovieInfo where l.Title == m.Title select l).Count() > 0) { w(string.Format("电影:{0} 类型:{1} 地区:{2} 年代:{3} 演员:{4} 导演:{5}", m.Title, m.ClassName, m.Location, m.PublicYear, m.Actors, m.Director)); ent.AddToMovieInfo(m); w("保存电影信息..."); ent.SaveChanges(); if (!m.FaceImage.IsNullOrEmpty()) { w("设置封面"); SaveFace(m.FaceImage, m.id); m.FaceImage = string.Format("/u/MovieFace/{0}.jpg", m.id); w("保存封面..."); ent.SaveChanges(); } } } else { string imageUrl = m.FaceImage.IsNull(match.Groups["image"].Value.AppendToDomain(InfoUrl)); m = movies.FirstOrDefault(); if (m.FaceImage.IsNullOrEmpty()) { SaveFace(imageUrl, m.id); } } //获取百度和快播区域并且开始采集 #region 百度区域 yellow(); Match m_baiduarea = html.GetMatchGroup(r.BaiduAreaRule); if (m_baiduarea.Success && !r.BaiduAreaRule.IsNullOrEmpty()) { w("分析百度区域"); Match m_drama = m_baiduarea.Groups["key"].Value.GetMatchGroup(r.BaiduDramaRule); while (m_drama.Success) { string title = m_drama.Groups["title"].Value; string playurl = m_drama.Groups["playurl"].Value; string url = m_drama.Groups["url"].Value; #region 打开播放页面处理 if (url.IsNullOrEmpty()) { CollectBaiduMovie(m, r, playurl.AppendToDomain(InfoUrl), title); if (!r.SourceBaiduRule.IsNullOrEmpty()) { break; } } #endregion else { var dramas = (from l in ent.MovieUrlBaidu where l.MovieID == m.id && l.Title == title select l); if (dramas.Count() == 0) { w(string.Format("在信息页面得到地址:{0}", url)); ent.AddToMovieUrlBaidu(new MovieUrlBaidu() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = title, UpdateTime = DateTime.Now, Url = url }); m.UpdateTime = DateTime.Now; m.LastDramaTitle = title; w("保存"); ent.SaveChanges(); } } m_drama = m_drama.NextMatch(); } } #endregion #region 快播区域 Match m_kuaiboarea = html.GetMatchGroup(r.KuaibAreaRule); if (m_kuaiboarea.Success && !r.KuaibAreaRule.IsNullOrEmpty()) { w("分析快播区域"); Match m_drama = m_kuaiboarea.Groups["key"].Value.GetMatchGroup(r.KuaibDramaRule); while (m_drama.Success) { string title = m_drama.Groups["title"].Value.IsNull("全集"); string playurl = m_drama.Groups["playurl"].Value; string url = m_drama.Groups["url"].Value; #region 打开播放页面处理 if (url.IsNullOrEmpty()) { CollectKuaiboMovie(m, r, playurl.AppendToDomain(InfoUrl), title); if (!r.SourceKuaibRule.IsNullOrEmpty()) { break; } } #endregion else { var dramas = (from l in ent.MovieUrlKuaib where l.MovieID == m.id && l.Title == title select l); if (dramas.Count() == 0) { w(string.Format("在信息页面得到地址:{0}", url)); ent.AddToMovieUrlKuaib(new MovieUrlKuaib() { Enable = true, MovieID = m.id, MovieTitle = m.Title, Title = title, UpdateTime = DateTime.Now, Url = url }); m.UpdateTime = DateTime.Now; m.LastDramaTitle = title; w("保存"); ent.SaveChanges(); } } m_drama = m_drama.NextMatch(); } } #endregion } }