[搜片神器]迅雷云播视频地址获取代码分享[自己动手丰衣足食]
DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO
数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr
.
--------------------------------------------------------------------------------------------------------------------
在DHT网络获取的网络数据后,需要进行播放功能,目前只有迅雷云播放功能比较强大,其它各类小网站都是从迅雷网站进行数据的抓取分析功能,
接下来我们就主要介绍如果从迅雷网站简单的抓取视频播放地址来进行播放功能.
1.先看软件功能实现界面:
在获取网址后我们可以用播放器来进行播放,百度影音和VLC播放器可以查看,也可以进行拖放,比起网上很多网站都不支持拖放功能好了很多,
测试了迅雷看看不行,QQ影音也不行,其它的播放器没有测试.
可以进行拖动播放.
VLC media player播放界面:
2.介绍如何进行迅雷网站登录抓取视频流程:
1)主要先通过抓包来分析登录流程,第一包主要分析是否有验证码的问题http://login.xunlei.com/check?u=
通过分析返回的Header数据,如果里面有check_result=1说明需要进行验证码的处理工作.
/// <summary> /// 输入用户名后就需要检测是否输入验证码 /// </summary> private void txtName_Leave(object sender, EventArgs e) { string url = "http://login.xunlei.com/check?u=" + txtName.Text + "&t=" + Convert.ToString(DateTime.Now.ToUniversalTime()); string hash1 = Http.GetHtmlHeader(url, cookie); int temp1 = hash1.IndexOf("check_result="); string logintype = hash1.Substring(temp1 + 13, 1); if (logintype == "1") { labelVery.Visible = true; vefycodTxt.Visible = true; vefycodpicbox.Visible = true; vefycodTxt.Text = ""; string codeimageurl = string.Format("http://verify2.xunlei.com/image?cachetime={0}", Convert.ToString(UNIX_TIMESTAMP(DateTime.Now))); Stream getStream = Http.GetStream(codeimageurl, cookie); vefycodpicbox.Image = Image.FromStream(getStream); } else { vefycodTxt.Text = GetBetween(hash1, "check_result=0:", ";"); labelVery.Visible = false; vefycodTxt.Visible = false; vefycodpicbox.Visible = false; } }
2)如果有验证码,处理
string codeimageurl = string.Format("http://verify2.xunlei.com/image?cachetime={0}", Convert.ToString(UNIX_TIMESTAMP(DateTime.Now))); Stream getStream = Http.GetStream(codeimageurl, cookie); vefycodpicbox.Image = Image.FromStream(getStream);
3)进行密码加密
//生成密码字串 string password = getMd5Hash2(getMd5Hash2(getMd5Hash2(txtPass.Text)) + vefycodTxt.Text.ToUpper()); /// <summary> /// md5加密 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string getMd5Hash2(string input) { byte[] buffer = MD5.Create().ComputeHash(Encoding.Default.GetBytes(input)); StringBuilder builder = new StringBuilder(); for (int i = 0; i < buffer.Length; i++) { builder.Append(buffer[i].ToString("x2")); } return builder.ToString(); }
4)进行登录验证
string postData = "u=" + txtName.Text + "&p=" + password + "&verifycode=" + vefycodTxt.Text + "&login_enable=1&login_hour=720"; string res1 = Http.GetHtmlPostHeader("http://login.xunlei.com/sec2login/", postData, cookie); m_userid = GetBetween(res1, "userid=", ";"); m_sessionid = GetBetween(res1, "sessionid=", ";"); m_isvip = GetBetween(res1, "isvip=", ";"); string blog = GetBetween(res1, "blogresult=", ";"); if (m_userid.Length > 0) { this.Text = "H31DHT迅雷视频地址搜索软件UserID:" + m_userid + " VIP:" + m_isvip; button1.Text = "退出"; txtName.Enabled = false; txtPass.Enabled = false; labelVery.Visible = false; vefycodTxt.Visible = false; vefycodpicbox.Visible = false; SaveSetting(); }
#region 公用函数 /// <summary> /// md5加密 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string getMd5Hash2(string input) { byte[] buffer = MD5.Create().ComputeHash(Encoding.Default.GetBytes(input)); StringBuilder builder = new StringBuilder(); for (int i = 0; i < buffer.Length; i++) { builder.Append(buffer[i].ToString("x2")); } return builder.ToString(); } /// <summary> /// 获取字符串 /// </summary> public static string GetBetween(string s, string s1, string s2) { int n1, n2; n1 = s.IndexOf(s1, 0); if (n1 == -1) return ""; n1=n1+s1.Length; //开始位置 n2 = s.IndexOf(s2, n1); //结束位置 if (n2 == -1) return ""; return s.Substring(n1, n2 - n1); //取搜索的条数,用结束的位置-开始的位置,并返回 } /// <summary> /// 时间转成Unix时间戳 /// </summary> /// <param name="dateTime"></param> /// <returns></returns> public static long UNIX_TIMESTAMP(DateTime dateTime) { return (dateTime.Ticks - DateTime.Parse("1970-01-01 00:00:00").Ticks) / 10000000; } #endregion
如果登录成功会有一些userid,sessionid等信息返回需要使用.
5)去查询一个磁连接复制回来进行分析视频地址:
主要针对http://i.vod.xunlei.com/req_try_vod?url={0}&cache={1}&userid={2}&sessionid={3}&vip={4}&platform=0&from=vlist&jsonp=XL_CLOUD_FX_INSTANCEqueryBack
来构造数据分析;
/// <summary> /// 获取磁连接播放地址 /// </summary> private void buttonGetResult_Click(object sender, EventArgs e) { string sha = txtUrl.Text; string url4 = string.Format("http://i.vod.xunlei.com/req_try_vod?url={0}&cache={1}&userid={2}&sessionid={3}&vip={4}&platform=0&from=vlist&jsonp=XL_CLOUD_FX_INSTANCEqueryBack", sha, UNIX_TIMESTAMP(DateTime.Now), m_userid, m_sessionid, m_isvip); string res5 = Http.GetHtmlPostMsg(url4, cookie); res5 = res5.Replace("dt=16", "dt=17"); txtRusult.Text = res5; string pattern = string.Format("vod_url\": \"(.*?)\","); MatchCollection usermatch = Regex.Matches(res5, pattern, RegexOptions.IgnoreCase); if (usermatch.Count >= 2 && usermatch[0].Groups[0].Value.Length >= 1) { txtVideo1.Text = usermatch[0].Groups[1].Value; txtVideo2.Text = usermatch[1].Groups[1].Value; } }
6)整个流程代码主要通过HttpWebRequest来完成,相关类的代码如下:
public static Stream GetStream(string URL, CookieContainer cookieContainer) { HttpWebRequest httpWebRequest; HttpWebResponse webResponse; Stream getStream; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL); httpWebRequest.CookieContainer = cookieContainer; httpWebRequest.Accept = "*/*"; //httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.UserAgent = "User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"; httpWebRequest.Method = "GET"; webResponse = (HttpWebResponse)httpWebRequest.GetResponse(); string header = webResponse.Headers.ToString(); getStream = webResponse.GetResponseStream(); return getStream; } public static string GetHtmlHeader(string URL, CookieContainer cookieContainer) { HttpWebRequest httpWebRequest; HttpWebResponse webResponse; Stream getStream; StreamReader streamReader; string getString = ""; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL); httpWebRequest.CookieContainer = cookieContainer; httpWebRequest.Accept = "*/*"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.UserAgent = "User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"; httpWebRequest.Method = "GET"; webResponse = (HttpWebResponse)httpWebRequest.GetResponse(); string header = webResponse.Headers.ToString(); getStream = webResponse.GetResponseStream(); streamReader = new StreamReader(getStream, Encoding.UTF8); getString = streamReader.ReadToEnd(); streamReader.Close(); getStream.Close(); httpWebRequest.Abort(); webResponse.Close(); return header; } public static string GetHtmlPostHeader(string URL, string postData, CookieContainer cookieContainer) { HttpWebRequest httpWebRequest; HttpWebResponse webResponse; Stream getStream; StreamReader streamReader; string getString = ""; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL); httpWebRequest.CookieContainer = cookieContainer; httpWebRequest.Accept = "*/*"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.Referer = "http://i.xunlei.com/login.html"; httpWebRequest.UserAgent = "User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"; httpWebRequest.Method = "Post"; byte[] byteRequest = Encoding.Default.GetBytes(postData); httpWebRequest.ContentLength = byteRequest.Length; Stream stream; stream = httpWebRequest.GetRequestStream(); stream.Write(byteRequest, 0, byteRequest.Length); stream.Close(); webResponse = (HttpWebResponse)httpWebRequest.GetResponse(); string header = webResponse.Headers.ToString(); getStream = webResponse.GetResponseStream(); streamReader = new StreamReader(getStream, Encoding.UTF8); getString = streamReader.ReadToEnd(); streamReader.Close(); getStream.Close(); httpWebRequest.Abort(); webResponse.Close(); return header; } public static string GetHtmlPostMsg(string URL, CookieContainer cookieContainer) { HttpWebRequest httpWebRequest; HttpWebResponse webResponse; Stream getStream; StreamReader streamReader; string getString = ""; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL); httpWebRequest.CookieContainer = cookieContainer; httpWebRequest.Accept = "*/*"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; //httpWebRequest.Referer = "http://vod.xunlei.com/iplay.html?uvs=26792633_4_166BF1D2FD43C79F8605A78BFE0E65CD8FE775E494F79F64FB63CA6C692D71156FB80795D39CB79BC4DA348AFE399ECE96856BEAFAB89C9D7598D1AFBEAAFD5E&from=vlist&url=bt%3A%2F%2F0C8F6F3292F7049E4E76716C242A4BA0944D1466%2F2&list=all"; httpWebRequest.Referer = "http://vod.xunlei.com/iplay.html"; httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17"; httpWebRequest.Method = "Get"; webResponse = (HttpWebResponse)httpWebRequest.GetResponse(); string header = webResponse.Headers.ToString(); getStream = webResponse.GetResponseStream(); streamReader = new StreamReader(getStream, Encoding.UTF8); getString = streamReader.ReadToEnd(); streamReader.Close(); getStream.Close(); httpWebRequest.Abort(); webResponse.Close(); return getString; }
3.使用过程中的发现问题:
1)查询出来的播放地址,如果在播放几次后,那个地址会失效,还需要进一步分析如何避免的问题;
2)有的播放器测试进行播放不成功,然后这个地址也会失效;
3)有些参数不明白,有些不对的地方,希望大家指教下;
希望有兴趣朋友一起讨论分析迅雷云播放视频地址的获取问题,现提供第一版本程序下载,希望大家多多提意见!
下载程序:H31Thunder.rar
希望大家多多推荐哦...大家的推荐才是下一篇介绍的动力...