SougouMp3小偷
发布时间:2019-09-21 11:14:23编辑:auto阅读(1729)
主要源码
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Web;
///////////////////////////////////////////////////////////////////////////// ////////////////////////////作者:kkkkyue//////////////////////////////////// ////////////////////////创建时间:2008年9月8日/////////////////////////////// ///////////////////////////////////////////////////////////////////////////// namespace SougouMp3Search
{
/// <summary> /// MP3结构体 /// </summary> public class Mp3Struck
{
/// <summary> /// 歌名 /// </summary> public string Name = "";
/// <summary> /// 歌手名 /// </summary> public string Author = "";
/// <summary> /// 类型 /// </summary> public string Type = "";
/// <summary> /// 大小 /// </summary> public string Size = "";
/// <summary> /// SOGOU下载页面URL /// </summary> public string PageURI = "";
/// <summary> /// 下载地址集合 /// </summary> public ArrayList DownloadURI=
new ArrayList();
}
/// <summary> /// MP3搜索 /// </summary> public class Mp3Search
{
readonly WebClient wc =
new WebClient();
private const string _URL =
"http://mp3.sogou.com/music.so?as=false&w=02009900&_asf=mp3.sogou.com&_ast=1220904551";
private const string Dwordstr = "&query=";
private const string Dpage = "&page=";
//private const int count = 30;
/// <summary>
/// 通过关键字和页数获得SOGOU下载页面URL集合
/// </summary>
/// <param name="dWord"></param>
/// <param name="page"></param>
/// <returns></returns>
public string[] GetPageURIsByDword(string dWord, int page)
{
string Html = wc.DownloadString(_URL + Dwordstr + UrlEncode(dWord) + Dpage + page);
int count1 = 0;
int count2 = 0;
int count = 0;
while (count1 != -1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1 == -1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2 == -1)
{
break;
}
count++;
}
count1 = 0;
count2 = 0;
string[] mp3Strucks = new string[count];
count = 0;
while (count1 != -1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1 == -1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2 == -1)
{
break;
}
string td = Html.Substring(count1, count2 - count1);
mp3Strucks[count] = td;
count++;
}
return mp3Strucks;
}
/// <summary>
/// 通过关键字和页数获得MP3结构体集合
/// </summary>
/// <param name="dWord"></param>
/// <param name="page"></param>
/// <returns></returns>
public Mp3Struck[] GetListByDword(string dWord, int page)
{
string Html = wc.DownloadString(_URL + Dwordstr + UrlEncode(dWord) + Dpage + page);
int count1 = 0;
int count2 = 0;
int count = 0;
while (count1!=-1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1==-1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2==-1)
{
break;
}
count++;
}
count1 = 0;
count2 = 0;
Mp3Struck[] mp3Strucks = new Mp3Struck[count];
count = 0;
while (count1 != -1)
{
count1 = Html.IndexOf("down.so?gid", count2);
if (count1 == -1)
{
break;
}
count2 = Html.IndexOf("',''", count1);
if (count2 == -1)
{
break;
}
string td = Html.Substring(count1, count2 - count1 );
mp3Strucks[count] = GetDownURI(td);
mp3Strucks[count].PageURI = td;
count++;
}
return mp3Strucks;
}
/// <summary>
/// 通过SOGOU下载页面获得MP3结构体
/// </summary>
/// <param name="downURI"></param>
/// <returns></returns>
public Mp3Struck GetDownURI(string downURI)
{
Mp3Struck mp3Struck=new Mp3Struck();
mp3Struck.PageURI = downURI;
string htm2 = "";
htm2 = wc.DownloadString("http://mp3.sogou.com/" + downURI);
int count1 = 0;
int count2 = 0;
count2 = htm2.IndexOf("歌名:<a", count2);
count1 = htm2.IndexOf(">", count2);
count2 = htm2.IndexOf("</a", count1);
mp3Struck.Name = htm2.Substring(count1 + 1, count2 - count1 - 1);
count2 = htm2.IndexOf("歌手:<a", count2);
count1 = htm2.IndexOf(">", count2);
count2 = htm2.IndexOf("</a", count1);
mp3Struck.Author = htm2.Substring(count1 + 1, count2 - count1 - 1);
count1 = htm2.IndexOf("格式:", count2);
count2 = htm2.IndexOf("</td>", count1);
mp3Struck.Type = htm2.Substring(count1 + 3, count2 - count1 - 3);
count1 = htm2.IndexOf("大小:", count2);
count2 = htm2.IndexOf("</td>", count1);
mp3Struck.Size = htm2.Substring(count1 + 3, count2 - count1 - 3);
while (count1 != -1)
{
count1 = htm2.IndexOf("http://", count2);
if (count1 == -1)
{
break;
}
count2 = htm2.IndexOf("\">", count1);
if (count2==-1)
{
break;
}
string td = htm2.Substring(count1, count2 - count1);
mp3Struck.DownloadURI.Add(td);
}
return mp3Struck;
}
private static string UrlEncode(string url)
{
return HttpUtility.UrlEncode(url, Encoding.GetEncoding("GB2312"));
}
}
}
关键字: