Model层
DBModel.cs代码:
public class DBModel
{
public int r { get ; set ; }
public Res res { get ; set ; }
public Status status { get ; set ; }
}
public class Res
{
public string TYPE { get ; set ; }
public int comment_count { get ; set ; }
public int id { get ; set ; }
public int kind { get ; set ; }
public string kind_cn { get ; set ; }
public string kind_str { get ; set ; }
public int page_id { get ; set ; }
public Payload payload { get ; set ; }
public int status { get ; set ; }
public Subject subject { get ; set ; }
public Subject1[] subjects { get ; set ; }
public User user { get ; set ; }
}
public class Payload
{
public string background_color { get ; set ; }
public string background_img { get ; set ; }
public string description { get ; set ; }
public string has_barrage { get ; set ; }
public string left { get ; set ; }
public string mobile_background_img { get ; set ; }
public string subject_ids { get ; set ; }
public string title { get ; set ; }
public string user_id { get ; set ; }
}
public class Subject
{
public string cover { get ; set ; }
public string [] directors { get ; set ; }
public string id { get ; set ; }
public bool is_released { get ; set ; }
public string m_url { get ; set ; }
public string orig_title { get ; set ; }
public float rating { get ; set ; }
public int rating_count { get ; set ; }
public string title { get ; set ; }
public string type { get ; set ; }
public string url { get ; set ; }
}
public class User
{
public string avatar { get ; set ; }
public string id { get ; set ; }
public string name { get ; set ; }
public string url { get ; set ; }
}
public class Subject1
{
public string cover { get ; set ; }
public string id { get ; set ; }
public bool is_released { get ; set ; }
public string m_url { get ; set ; }
public string orig_title { get ; set ; }
public float rating { get ; set ; }
public int rating_count { get ; set ; }
public string title { get ; set ; }
public string type { get ; set ; }
public string url { get ; set ; }
}
public class Status
{
public int code { get ; set ; }
}
IDModel类:
public class IDModel
{
public string downURL { get ; set ; }
public string headImg { get ; set ; }
public string inforMessage { get ; set ; }
}
ShowModel.cs类文件:
public class Rootobject
{
public int count { get ; set ; }
public int start { get ; set ; }
public int total { get ; set ; }
public Subjects[] subjects { get ; set ; }
public string title { get ; set ; }
}
public class Subjects
{
public Rating rating { get ; set ; }
public string [] genres { get ; set ; }
public string title { get ; set ; }
public Cast[] casts { get ; set ; }
public int collect_count { get ; set ; }
public string original_title { get ; set ; }
public string subtype { get ; set ; }
public Director[] directors { get ; set ; }
public string year { get ; set ; }
public Images images { get ; set ; }
public string alt { get ; set ; }
public string id { get ; set ; }
}
public class Rating
{
public int max { get ; set ; }
public float average { get ; set ; }
public string stars { get ; set ; }
public int min { get ; set ; }
}
public class Images
{
public string small { get ; set ; }
public string large { get ; set ; }
public string medium { get ; set ; }
}
public class Cast
{
public string alt { get ; set ; }
public Avatars avatars { get ; set ; }
public string name { get ; set ; }
public string id { get ; set ; }
}
public class Avatars
{
public string small { get ; set ; }
public string large { get ; set ; }
public string medium { get ; set ; }
}
public class Director
{
public string alt { get ; set ; }
public Avatars1 avatars { get ; set ; }
public string name { get ; set ; }
public string id { get ; set ; }
}
public class Avatars1
{
public string small { get ; set ; }
public string large { get ; set ; }
public string medium { get ; set ; }
}
Utility文件夹:
DBInfo.cs代码:
public class DBInfo
{
private static readonly Cache cache = HttpRuntime.Cache;
public static DBModel GetMovieInforListByCache (string key, int i)
{
if (cache[key] != null )
{
return cache[key] as DBModel;
}
DBModel model = GetMovieInfor("https://movie.douban.com/ithil_j/activity/movie_annual2016/widget/" + i);
if (model == null )
return null ;
cache.Insert(key, model, null , DateTime.Now.AddDays(1 ), TimeSpan.Zero);
;
return model;
}
public static DBModel GetMovieInfor (string url)
{
DBModel model = null ;
string html = HtmlHelper.LoadPageContent(url);
if (!string .IsNullOrEmpty(html))
{
var Serializer = new JavaScriptSerializer();
model = Serializer.Deserialize<DBModel>(html);
}
return model;
}
}
HtmlHelper.cs代码:
public class HtmlHelper
{
public static string DBYear = ConfigurationManager.AppSettings["DBYear" ];
public static string DBOrder = ConfigurationManager.AppSettings["DBOrder" ];
public static string Showing = ConfigurationManager.AppSettings["Showing" ];
public static string Coming = ConfigurationManager.AppSettings["Coming" ];
public static string Top = ConfigurationManager.AppSettings["Top" ];
public static string idSeach = ConfigurationManager.AppSettings["idSeach" ];
public static string downloadUrl = ConfigurationManager.AppSettings["DownloadUrl" ];
public static string wsSearchUrl = ConfigurationManager.AppSettings["wsSearch" ];
public static string wsDownloadUrl = ConfigurationManager.AppSettings["wsDownloadUrl" ];
public static string DownloadHtml (string url)
{
return DownloadHtml(url, Encoding.UTF8);
}
public static string DyDownloadHtml (string url)
{
return DownloadHtml(url, Encoding.Default);
}
public static string DownloadHtml (string url, Encoding encoding)
{
string html = String.Empty;
try
{
var request = WebRequest.Create(url) as HttpWebRequest;
request.Timeout = 60 *1000 ;
request.ContentType = "text/html; charset=utf-8" ;
using (var response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode == HttpStatusCode.OK)
{
try
{
var sr = new StreamReader(response.GetResponseStream(), encoding);
html = sr.ReadToEnd();
sr.Close();
}
catch (Exception ex)
{
html = null ;
}
}
}
}
catch (Exception ex)
{
html = null ;
}
return html;
}
public static string LoadPageContent (string url)
{
var wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
byte [] pageData = wc.DownloadData(url);
return (Encoding.GetEncoding("utf-8" ).GetString(pageData));
}
}
ID97Crewl.cs:
public class ID97Crewl
{
public static IDModel GetMovieInforMode (string movieName)
{
IDModel model = null ;
string html = HtmlHelper.DownloadHtml(HtmlHelper.idSeach + movieName);
if (!string .IsNullOrEmpty(html))
{
model = new IDModel();
var doc = new HtmlDocument();
doc.LoadHtml(html);
string xPath = "/html/body/div/div[1]/div/div[1]/a" ;
HtmlNode node = doc.DocumentNode.SelectSingleNode(xPath);
if (node != null )
{
string movieUrl = node.Attributes["href" ].Value;
string movieId = movieUrl.Substring(movieUrl.LastIndexOf('/' ) + 1 ).Replace(".html" , "" );
string resquestUrl = HtmlHelper.downloadUrl + movieId;
string inforHtml = HtmlHelper.DownloadHtml(resquestUrl);
if (inforHtml != null )
{
var inforDoc = new HtmlDocument();
inforDoc.LoadHtml(inforHtml);
string downPath = "//*[@id='normalDown']/div/table" ;
HtmlNode downNode = inforDoc.DocumentNode.SelectSingleNode(downPath);
if (downNode != null )
{
var thirdDoc = new HtmlDocument();
thirdDoc.LoadHtml(downNode.InnerHtml);
string aPath = "//a" ;
HtmlNodeCollection aNode = thirdDoc.DocumentNode.SelectNodes(aPath);
string downInfor = String.Empty;
if (aNode != null )
{
foreach (HtmlNode nodes in aNode)
{
if (nodes.Attributes["href" ].Value.IndexOf("http://pan.baidu.com/" ) >= 0 ||
nodes.Attributes["href" ].Value.IndexOf("https://pan.baidu.com/s/" ) >= 0 )
{
downInfor += nodes.Attributes["title" ].Value + "\n百度云盘地址:" +
nodes.Attributes["href" ].Value + "\n" ;
}
else if (nodes.Attributes["href" ].Value.IndexOf("ed2k://|file" ) >= 0 )
{
downInfor += "电驴:" + nodes.Attributes["href" ].Value + "\n" ;
}
else if (nodes.Attributes["href" ].Value.IndexOf("magnet:?xt=urn:" ) >= 0 )
{
downInfor += "磁力:" + nodes.Attributes["href" ].Value + "\n" ;
}
}
}
model.downURL = downInfor;
}
}
}
string imgPath = "/html/body/div/div[1]/div/div[1]/a/img" ;
HtmlNode imgNode = doc.DocumentNode.SelectSingleNode(imgPath);
if (imgNode != null )
{
model.headImg = imgNode.Attributes["src" ].Value;
}
string infoPath = "/html/body/div/div[1]/div/div[2]/div/p[2]" ;
HtmlNode infoNode = doc.DocumentNode.SelectSingleNode(infoPath);
if (infoNode != null )
{
model.inforMessage = infoNode.InnerText;
}
else
{
infoPath = "/html/body/div[7]/div[1]/div/div[2]/div/p[2]" ;
infoNode = doc.DocumentNode.SelectSingleNode(infoPath);
if (infoNode != null )
{
model.inforMessage = infoNode.InnerText;
}
}
}
return model;
}
}
ShowimgCrewl.cs:
public class ShowimgCrewl
{
private static readonly Cache cache = HttpRuntime.Cache;
public static Rootobject GetShowingMovieInforListByCache ()
{
string key = "SHOWING_LIST" ;
if (cache[key] != null )
{
return cache[key] as Rootobject;
}
Rootobject model = GetMovieInfor(HtmlHelper.Showing);
if (model == null )
return null ;
cache.Insert(key, model, null , DateTime.Now.AddDays(1 ), TimeSpan.Zero);
;
return model;
}
public static Rootobject GetComingMovieInforListByCache ()
{
string key = "COMING_LIST" ;
if (cache[key] != null )
{
return cache[key] as Rootobject;
}
Rootobject model = GetMovieInfor(HtmlHelper.Coming);
if (model == null )
return null ;
cache.Insert(key, model, null , DateTime.Now.AddDays(1 ), TimeSpan.Zero);
;
return model;
}
public static Rootobject GetTopMovieInforListByCache ()
{
string key = "TOP_LIST" ;
if (cache[key] != null )
{
return cache[key] as Rootobject;
}
Rootobject model = GetMovieInfor(HtmlHelper.Top);
if (model == null )
return null ;
cache.Insert(key, model, null , DateTime.Now.AddDays(1 ), TimeSpan.Zero);
;
return model;
}
public static Rootobject GetMovieInfor (string url)
{
Rootobject model = null ;
string html = HtmlHelper.LoadPageContent(url);
if (!string .IsNullOrEmpty(html))
{
var Serializer = new JavaScriptSerializer();
model = Serializer.Deserialize<Rootobject>(html);
}
return model;
}
}
WXCrewl.cs代码:
public class WXCrewl
{
public static IDModel GetMovieInfor (string movieName)
{
IDModel model = null ;
string searchUrl = HtmlHelper.wsSearchUrl + movieName;
string html = HtmlHelper.DownloadHtml(searchUrl);
if (!string .IsNullOrEmpty(html))
{
var doc = new HtmlDocument();
doc.LoadHtml(html);
string wsMoviePath = "/html/body/div[3]/div[2]/ul/li[1]/a" ;
HtmlNode htmlnode = doc.DocumentNode.SelectSingleNode(wsMoviePath);
if (htmlnode != null )
{
string apathUrl = htmlnode.Attributes["href" ].Value;
string resourceUrl = HtmlHelper.wsDownloadUrl + apathUrl;
string resourceHtml = HtmlHelper.DownloadHtml(resourceUrl);
if (!string .IsNullOrEmpty(resourceHtml))
{
var resourceDoc = new HtmlDocument();
resourceDoc.LoadHtml(resourceHtml);
model = new IDModel();
string lookPath = "//*[@id='wuxingyun']/div/ul/li/a" ;
HtmlNode linkNode = resourceDoc.DocumentNode.SelectSingleNode(lookPath);
if (linkNode != null )
{
model.downURL = HtmlHelper.wsDownloadUrl + linkNode.Attributes["href" ].Value;
}
else
{
lookPath = "//*[@id='jisuayun']/div/ul/li[1]/a" ;
linkNode = resourceDoc.DocumentNode.SelectSingleNode(lookPath);
if (linkNode != null )
{
model.downURL = HtmlHelper.wsDownloadUrl + linkNode.Attributes["href" ].Value;
}
else
{
lookPath = "//*[@id='mgtv']/div/ul/li/a" ;
linkNode = resourceDoc.DocumentNode.SelectSingleNode(lookPath);
if (linkNode != null )
{
model.downURL = HtmlHelper.wsDownloadUrl + linkNode.Attributes["href" ].Value;
}
}
}
string imagePath = "/html/body/div[3]/div[3]/div[4]/div[1]/img" ;
HtmlNode imageNode = resourceDoc.DocumentNode.SelectSingleNode(imagePath);
if (imageNode != null )
{
if (imageNode.Attributes.Contains("data-original" ))
model.headImg = imageNode.Attributes["data-original" ].Value;
else if (imageNode.Attributes.Contains("original" ))
model.headImg = imageNode.Attributes["original" ].Value;
else if (imageNode.Attributes.Contains("src" ))
model.headImg = imageNode.Attributes["src" ].Value;
}
string inforPath = "/html/body/div[3]/div[3]/div[4]/div[2]/div[2]/dl[2]/dd/p" ;
HtmlNode inforNode = resourceDoc.DocumentNode.SelectSingleNode(inforPath);
if (inforNode != null )
{
model.inforMessage = "简介:" + inforNode.InnerHtml;
}
}
}
}
return model;
}
}
App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration >
<startup >
<supportedRuntime version ="v4.0" sku =".NETFramework,Version=v4.5" />
</startup >
<appSettings >
<add key ="DBOrder" value ="https://movie.douban.com/annual2016/?source=navigation#15" />
<add key ="DBYear" value ="https://movie.douban.com/ithil_j/activity/movie_annual2016" />
<add key ="idSeach" value ="http://www.181bt.com/search?q=" />
<add key ="DownloadUrl" value ="http://www.181bt.com/videos/resList/" />
<add key ="wsSearch" value ="http://wap.lol5s.com/index.php?m=vod-search-wd-" />
<add key ="wsDownloadUrl" value ="http://wap.lol5s.com" />
<add key ="Showing" value ="https://api.douban.com/v2/movie/in_theaters" />
<add key ="Coming" value ="https://api.douban.com/v2/movie/coming_soon" />
<add key ="Top" value ="https://api.douban.com/v2/movie/top250" />
</appSettings >
</configuration >
using System;
using System.Diagnostics;
using System.Windows.Forms;
using CCWin;
using CCWin.SkinControl;
namespace MovieDemo
{
public partial class Form1 : CCSkinMain
{
private static string gkUrl = string .Empty;
public Form1 ()
{
InitializeComponent();
cmb_type.SelectedIndex = 0 ;
com_orderby.SelectedIndex = 0 ;
pic_img.ImageLocation = "http://ojtdqq2ha.bkt.clouddn.com/16b0b3789293bd7ba4e280a228546ef3.jpg" ;
pic_img.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void cmb_type_SelectedIndexChanged (object sender, EventArgs e)
{
switch (cmb_type.SelectedIndex)
{
case 1 :
GetMovieList("DBHY_LIST" , 1 );
break ;
case 2 :
GetMovieList("DBWY_LIST" , 2 );
break ;
case 3 :
GetMovieList("DBZSGZY_LIST" , 4 );
break ;
case 4 :
GetMovieList("DBZSGZFY_LIST" , 5 );
break ;
case 5 :
GetMovieList("DBDLDL_LIST" , 7 );
break ;
case 6 :
GetMovieList("DBLMJP_LIST" , 8 );
break ;
case 7 :
GetMovieList("DBHG_LIST" , 10 );
break ;
case 8 :
GetMovieList("DBWRB_LIST" , 11 );
break ;
case 9 :
GetMovieList("DBOZ_LIST" , 12 );
break ;
case 10 :
GetMovieList("DBTXL_LIST" , 13 );
break ;
case 11 :
GetMovieList("DBXJ_LIST" , 15 );
break ;
case 12 :
GetMovieList("DBAQ_LIST" , 16 );
break ;
case 13 :
GetMovieList("DBKH_LIST" , 17 );
break ;
case 14 :
GetMovieList("DBKB_LIST" , 18 );
break ;
case 15 :
GetMovieList("DBDH_LIST" , 20 );
break ;
case 16 :
GetMovieList("DBJLP_LIST" , 21 );
break ;
case 17 :
GetMovieList("DBDP_LIST" , 22 );
break ;
case 18 :
GetMovieList("DBDLDSJ_LIST" , 24 );
break ;
case 19 :
GetMovieList("DBYMJ_LIST" , 25 );
break ;
case 20 :
GetMovieList("DBYMJF_LIST" , 26 );
break ;
case 21 :
GetMovieList("DBHJ_LIST" , 28 );
break ;
case 22 :
GetMovieList("DBRJ_LIST" , 29 );
break ;
case 23 :
GetMovieList("DBQITJ_LIST" , 30 );
break ;
case 24 :
GetMovieList("DBDHJJ_LIST" , 34 );
break ;
case 25 :
GetMovieList("DBJLJJ_LIST" , 35 );
break ;
case 26 :
GetMovieList("DB1YRM_LIST" , 41 );
break ;
case 27 :
GetMovieList("DB2yrm_LIST" , 42 );
break ;
case 28 :
GetMovieList("DB3YRM_LIST" , 43 );
break ;
case 29 :
GetMovieList("DB4YRM_LIST" , 45 );
break ;
case 30 :
GetMovieList("DB5YRM_LIST" , 46 );
break ;
case 31 :
GetMovieList("DB6YRM_LIST" , 47 );
break ;
case 32 :
GetMovieList("DB7YRM_LIST" , 49 );
break ;
case 33 :
GetMovieList("DB8YRM_LIST" , 50 );
break ;
case 34 :
GetMovieList("DB9YRM_LIST" , 51 );
break ;
case 35 :
GetMovieList("DB10YRM_LIST" , 53 );
break ;
case 36 :
GetMovieList("DB11YRM_LIST" , 54 );
break ;
case 37 :
GetMovieList("DB12YRM_LIST" , 55 );
break ;
case 38 :
GetMovieList("DB10ZN_LIST" , 57 );
break ;
case 39 :
GetMovieList("DB20ZN_LIST" , 58 );
break ;
case 40 :
GetMovieList("DB30ZN_LIST" , 59 );
break ;
case 41 :
GetMovieList("DBqdhy_LIST" , 68 );
break ;
case 42 :
GetMovieList("DBqdwy_LIST" , 69 );
break ;
case 43 :
GetMovieList("DBbj_LIST" , 70 );
break ;
default :
break ;
}
}
private void GetMovieList (string key, int i)
{
DBModel model = DBInfo.GetMovieInforListByCache(key, i);
if (model != null )
{
lisb_movie.Items.Clear();
foreach (Subject1 item in model.res.subjects)
{
SkinListBoxItem skinListBoxItem = new SkinListBoxItem();
skinListBoxItem.Text = item.title + "-" + item.rating + "分" ;
lisb_movie.Items.Add(skinListBoxItem);
}
}
}
private void lisb_movie_SelectedIndexChanged (object sender, EventArgs e)
{
string movieName = lisb_movie.SelectedItem.ToString().Split('-' )[0 ];
GetMovieInfo(movieName.TrimEnd('。' ));
}
public void GetMovieInfo (string movieName)
{
txt_name.Text = movieName;
rtb_xping.Text = "" ;
pic_img.ImageLocation = "http://ojtdqq2ha.bkt.clouddn.com/16b0b3789293bd7ba4e280a228546ef3.jpg" ;
gkUrl = "" ;
btn_search.Enabled = false ;
IDModel movieInfo = ID97Crewl.GetMovieInforMode(movieName);
IDModel wxMovie = WXCrewl.GetMovieInfor(movieName);
if (movieInfo != null && movieInfo.downURL != null )
{
rtb_messagebox.Text = movieInfo.downURL;
rtb_xping.Text = movieInfo.inforMessage;
pic_img.ImageLocation = movieInfo.headImg;
if (wxMovie != null && wxMovie.downURL != null )
{
gkUrl = wxMovie.downURL;
}
}
else
{
if (wxMovie != null && wxMovie.downURL != null )
{
rtb_messagebox.Text = "无下载资源,点击在线观看!" ;
rtb_xping.Text = wxMovie.inforMessage;
pic_img.ImageLocation = wxMovie.headImg;
gkUrl = wxMovie.downURL;
}
else
{
rtb_xping.Text = "" ;
pic_img.ImageLocation = "http://ojtdqq2ha.bkt.clouddn.com/16b0b3789293bd7ba4e280a228546ef3.jpg" ;
gkUrl = "" ;
rtb_messagebox.Text = "暂无资源!" ;
}
}
btn_search.Enabled = true ;
}
private void btn_search_Click (object sender, EventArgs e)
{
rtb_messagebox.Text = "" ;
if (txt_name.Text.Trim() == "" )
{
btn_search.Enabled = true ;
rtb_messagebox.Text = "请输入要查找的电影名称!" ;
return ;
}
GetMovieInfo(txt_name.Text.Trim());
}
private void btn_look_Click (object sender, EventArgs e)
{
if (!string .IsNullOrEmpty(gkUrl))
{
var process = new Process();
process.StartInfo.FileName = "firefox.exe" ;
process.StartInfo.Arguments = gkUrl;
process.Start();
}
else
{
MessageBox.Show("暂无播放资源,可以尝试复制下载资源到迅雷,边看边下!" );
}
}
private void com_orderby_SelectedIndexChanged (object sender, EventArgs e)
{
switch (com_orderby.SelectedIndex)
{
case 1 :
ShowShowing();
break ;
case 2 :
ShowComing();
break ;
case 3 :
ShowTop();
break ;
}
}
public void ShowShowing ()
{
Rootobject model = ShowimgCrewl.GetShowingMovieInforListByCache();
if (model != null )
{
lisb_orderby.Items.Clear();
foreach (Subjects item in model.subjects)
{
SkinListBoxItem skinListBoxItem = new SkinListBoxItem();
skinListBoxItem.Text = item.title + "-" + item.rating + "分" ;
lisb_orderby.Items.Add(skinListBoxItem);
}
}
}
public void ShowComing ()
{
Rootobject model = ShowimgCrewl.GetComingMovieInforListByCache();
if (model != null )
{
lisb_orderby.Items.Clear();
foreach (Subjects item in model.subjects)
{
SkinListBoxItem skinListBoxItem = new SkinListBoxItem();
skinListBoxItem.Text = item.title + "-" + item.rating.average + "分" ;
lisb_orderby.Items.Add(skinListBoxItem);
}
}
}
public void ShowTop ()
{
Rootobject model = ShowimgCrewl.GetTopMovieInforListByCache();
if (model != null )
{
lisb_orderby.Items.Clear();
foreach (Subjects item in model.subjects)
{
SkinListBoxItem skinListBoxItem = new SkinListBoxItem();
skinListBoxItem.Text = item.title + "-" + item.rating.average + "分" ;
lisb_orderby.Items.Add(skinListBoxItem);
}
}
}
private void lisb_orderby_SelectedIndexChanged (object sender, EventArgs e)
{
string movieName = lisb_orderby.SelectedItem.ToString().Split('-' )[0 ];
GetMovieInfo(movieName.TrimEnd('。' ));
}
}
}
运行结果如图: