分享
 
 
 

C# 歌词自动下载显示代码

王朝学院·作者佚名  2009-06-22
窄屏简体版  字體: |||超大  

歌词下载:

view plaincopy to clipboardprint?

//Foxer_Player_App_Author: CT.ThEN

//Foxer_Player_App_BuildTime: Otc,12,2008

//Foxer_Player_App_Version: 1.01

//Foxer_Player_App_Author_email: ctthen@126.com

//Foxer_Player_App_Author_schoolID: 2740610812

//Foxer_Player_lrc_down:download_lrc_form_web

using System;

using System.Collections.Generic;

using System.Text;

using System.Text.RegularExpressions;

using System.Web;

using System.Net;

using System.IO;

using System.Windows.Forms;

namespace Foxer_Player_1._1

{

class lrc_down

{

public static WebClient client = new WebClient();

public static void gecixia(string name)

{

string geci_search_adress;

geci_search_adress = HttpUtility.UrlEncode(name, Encoding.Default);

string ci = geci_search_adress;

string geci = "http://mp3.sogou.com/gecisearch.so?query=" + ci + "&as=false&st=&ac=1&pf=&class=5&gecisearch.so=";

string ne = GetWebContent(geci);

Regex r2 = new Regex("((downlrc.jsp?).*(LRC歌词下载))", RegexOptions.IgnoreCase);

if (r2.IsMatch(ne))

{

string wangzhi = r2.Match(ne).Value;

string down_address = "http://mp3.sogou.com/" + wangzhi.Remove(wangzhi.IndexOf('"'));

DownloadFile(down_address, System.AppDomain.CurrentDomain.BaseDirectory + "Lrc\\" + name + ".lrc");

}

else

{

Regex r3 = new Regex("http://.*(?=.*lrc")");

if (r3.IsMatch(ne))

{

string wangzhi1 = r3.Match(ne).Value;

string down_address1 = "http://mp3.sogou.com/" + wangzhi1.Remove(wangzhi1.IndexOf('"'));

client.Dispose();

DownloadFile( down_address1, System.AppDomain.CurrentDomain.BaseDirectory + "Lrc\\" + name + ".lrc");

}

else

{

Regex r4 = new Regex(@"lrc.aspxp.net/lrc.asp.* ");

if (r4.IsMatch(ne))

{

string wangzhi2 = r2.Match(ne).Value;

string down_address2 = wangzhi2.Remove(wangzhi2.IndexOf('"'));

DownloadFile("http://" + down_address2, System.AppDomain.CurrentDomain.BaseDirectory + "Lrc\\" + name + ".lrc");

}

}

}

}

public static string GetWebContent(string Url)

{

string strResult = "";

try

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

//声明一个HttpWebRequest请求

request.Timeout = 30000;

//设置连接超时时间

request.Headers.Set("Pragma", "no-cache");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream streamReceive = response.GetResponseStream();

Encoding encoding = Encoding.GetEncoding("GB2312");

StreamReader streamReader = new StreamReader(streamReceive, encoding);

strResult = streamReader.ReadToEnd();

}

catch

{

// MessageBox.Show("出错");

}

return strResult;

}

public static void DownloadFile(string URLAddress, string fileName)

{

try

{

client.DownloadFile(URLAddress, fileName);

Stream str = client.OpenRead(URLAddress);

StreamReader reader = new StreamReader(str);

byte[] mbyte = new byte[1000000];

int allmybyte = (int)mbyte.Length;

int startmbyte = 0;

while (allmybyte > 0)

{

int m = str.Read(mbyte, startmbyte, allmybyte);

if (m == 0)

break;

startmbyte += m;

allmybyte -= m;

}

FileStream fstr = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);

fstr.Write(mbyte, 0, startmbyte);

str.Close();

fstr.Close();

client.Dispose();

}

catch

{

// MessageBox.Show(exp.Message, "Error");

}

}

}

}

//Foxer_Player_App_Author: CT.ThEN

//Foxer_Player_App_BuildTime: Otc,12,2008

//Foxer_Player_App_Version: 1.01

//Foxer_Player_App_Author_email: ctthen@126.com

//Foxer_Player_App_Author_schoolID: 2740610812

//Foxer_Player_lrc_down:download_lrc_form_web

using System;

using System.Collections.Generic;

using System.Text;

using System.Text.RegularExpressions;

using System.Web;

using System.Net;

using System.IO;

using System.Windows.Forms;

namespace Foxer_Player_1._1

{

class lrc_down

{

public static WebClient client = new WebClient();

public static void gecixia(string name)

{

string geci_search_adress;

geci_search_adress = HttpUtility.UrlEncode(name, Encoding.Default);

string ci = geci_search_adress;

string geci = "http://mp3.sogou.com/gecisearch.so?query=" + ci + "&as=false&st=&ac=1&pf=&class=5&gecisearch.so=";

string ne = GetWebContent(geci);

Regex r2 = new Regex("((downlrc.jsp?).*(LRC歌词下载))", RegexOptions.IgnoreCase);

if (r2.IsMatch(ne))

{

string wangzhi = r2.Match(ne).Value;

string down_address = "http://mp3.sogou.com/" + wangzhi.Remove(wangzhi.IndexOf('"'));

DownloadFile(down_address, System.AppDomain.CurrentDomain.BaseDirectory + "Lrc\\" + name + ".lrc");

}

else

{

Regex r3 = new Regex("http://.*(?=.*lrc")");

if (r3.IsMatch(ne))

{

string wangzhi1 = r3.Match(ne).Value;

string down_address1 = "http://mp3.sogou.com/" + wangzhi1.Remove(wangzhi1.IndexOf('"'));

client.Dispose();

DownloadFile( down_address1, System.AppDomain.CurrentDomain.BaseDirectory + "Lrc\\" + name + ".lrc");

}

else

{

Regex r4 = new Regex(@"lrc.aspxp.net/lrc.asp.* ");

if (r4.IsMatch(ne))

{

string wangzhi2 = r2.Match(ne).Value;

string down_address2 = wangzhi2.Remove(wangzhi2.IndexOf('"'));

DownloadFile("http://" + down_address2, System.AppDomain.CurrentDomain.BaseDirectory + "Lrc\\" + name + ".lrc");

}

}

}

}

public static string GetWebContent(string Url)

{

string strResult = "";

try

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

//声明一个HttpWebRequest请求

request.Timeout = 30000;

//设置连接超时时间

request.Headers.Set("Pragma", "no-cache");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream streamReceive = response.GetResponseStream();

Encoding encoding = Encoding.GetEncoding("GB2312");

StreamReader streamReader = new StreamReader(streamReceive, encoding);

strResult = streamReader.ReadToEnd();

}

catch

{

// MessageBox.Show("出错");

}

return strResult;

}

public static void DownloadFile(string URLAddress, string fileName)

{

try

{

client.DownloadFile(URLAddress, fileName);

Stream str = client.OpenRead(URLAddress);

StreamReader reader = new StreamReader(str);

byte[] mbyte = new byte[1000000];

int allmybyte = (int)mbyte.Length;

int startmbyte = 0;

while (allmybyte > 0)

{

int m = str.Read(mbyte, startmbyte, allmybyte);

if (m == 0)

break;

startmbyte += m;

allmybyte -= m;

}

FileStream fstr = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);

fstr.Write(mbyte, 0, startmbyte);

str.Close();

fstr.Close();

client.Dispose();

}

catch

{

// MessageBox.Show(exp.Message, "Error");

}

}

}

}

歌词显示:

view plaincopy to clipboardprint?

//Foxer_Player_App_Author: CT.ThEN

//Foxer_Player_App_BuildTime: Otc,12,2008

//Foxer_Player_App_Version: 1.01

//Foxer_Player_App_Author_email: ctthen@126.com

//Foxer_Player_App_Author_schoolID: 2740610812

//Foxer_Player_lrc_show:showLryic

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using System.Threading;

using System.Windows.Forms;

namespace Foxer_Player_1._1

{

class lrc_show

{

private static string musicPath;

private static string lrcPath;

private static string[] lrcString;

private static string listItem;

private static string listItemUnAdd ="XX#ooX#X";

private static bool isHasLrc=false;

public static bool unClict=true;

private static string[] clear;

//main

public static string get_lrc(string musicPath1,string geciIs1)

{

musicPath = musicPath1;

getGeci_str();

string listAdd=getList_add_geci(geciIs1);

return listAdd;

}

public static void getGeci_str()

{

try

{

FileInfo fi = new FileInfo(musicPath);

foreach (string gecifile in Directory.GetFiles(Application.StartupPath + "\Lrc\"))

{

FileInfo fi2 = new FileInfo(gecifile);

lrcPath = fi.Name.Remove(fi.Name.LastIndexOf('.'));

try

{

if (fi2.Name.Substring(0, fi2.Name.Length - 4) == fi.Name.Substring(0, fi.Name.Length - 4))

{

lrcString = File.ReadAllLines(gecifile, Encoding.Default);

isHasLrc = true;

return;

}

lrcString = clear;

if (unClict)

{

Thread t2 = new Thread(new ThreadStart(fangfa));

t2.IsBackground = true;

t2.Start();

unClict = false;

isHasLrc = true;

}

}

catch

{

}

}

}

catch

{

}

}

private static void fangfa()

{

lrc_down.gecixia(lrcPath);

}

private static string getList_add_geci(string currentPos)

{

try

{

for (int i = 0; i < lrcString.Length; i++)

{

int l = lrcString[i].LastIndexOf("]");

if(l == 9)

{

if (getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 8, 5))

{

listItem = lrcString[i].Substring(l + 1, lrcString[i].Length - l - 1);

return listItem;

}

}

else

if (l == 19)

{

if (getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 8, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 18, 5))

{

listItem = lrcString[i].Substring(l + 1, lrcString[i].Length - l - 1);

return listItem;

}

}

else

if (l == 29)

{

if (getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 8, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 18, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 28, 5))

{

listItem = lrcString[i].Substring(l + 1, lrcString[i].Length - l - 1);

return listItem;

}

}

else

if (l == 39)

{

if (getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 8, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 18, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 28, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 38, 5))

{

listItem = lrcString[i].Substring(l + 1, lrcString[i].Length - l - 1);

return listItem;

}

}

else

if (l == 49)

{

if (getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 8, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 18, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 28, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 38, 5) || getLengthWithFormat2(currentPos) == lrcString[i].Substring(l - 48, 5))

{

listItem = lrcString[i].Substring(l + 1, lrcString[i].Length - l - 1);

return listItem;

}

}

}

return listItemUnAdd;

}

catch

{

return listItemUnAdd;

}

}

private static string getLengthWithFormat2(string mm)

{

string ccds = mm.Replace("00:", "");

if (ccds.Length < 5)

{

ccds = "00:" + ccds;

}

return ccds;

}

}

}

出处:http://blog.csdn.net/ctthen/archive/2009/06/19/4284177.aspx

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有