我wgscd在网上看到一个人说的方法可下载千千静听歌词。
我修改了下经调试确实能得到歌词:
EncodeHelper.cs:----这个类可编码符合要求的请求ID
view plaincopy to clipboardprint?
using System;
using System.Collections.Generic;
using System.Text;
namespace QianQianLrc {
public class EncodeHelper {
public static string ToQianQianHexString(string s, Encoding encoding) {
StringBuilder sb = new StringBuilder();
byte[] bytes = encoding.GetBytes(s);
foreach (byte b in bytes) {
sb.Append(b.ToString("X").PadLeft(2, '0'));
}
return sb.ToString();
}
public static string CreateQianQianCode(string singer, string title, int lrcId) {
string qqHexStr = ToQianQianHexString(singer + title, Encoding.UTF8);
int length = qqHexStr.Length / 2;
int[] song = new int[length];
for (int i = 0; i < length; i++) {
song[i] = int.Parse(qqHexStr.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
}
int t1 = 0, t2 = 0, t3 = 0;
t1 = (lrcId & 0x0000FF00) >> 8;
if ((lrcId & 0x00FF0000) == 0) {
t3 = 0x000000FF & ~t1;
} else {
t3 = 0x000000FF & ((lrcId & 0x00FF0000) >> 16);
}
t3 = t3 | ((0x000000FF & lrcId) << 8);
t3 = t3 << 8;
t3 = t3 | (0x000000FF & t1);
t3 = t3 << 8;
if ((lrcId & 0xFF000000) == 0) {
t3 = t3 | (0x000000FF & (~lrcId));
} else {
t3 = t3 | (0x000000FF & (lrcId >> 24));
}
int j = length - 1;
while (j >= 0) {
int c = song[j];
if (c >= 0x80) c = c - 0x100;
t1 = (int)((c + t2) & 0x00000000FFFFFFFF);
t2 = (int)((t2 << (j % 2 + 4)) & 0x00000000FFFFFFFF);
t2 = (int)((t1 + t2) & 0x00000000FFFFFFFF);
j -= 1;
}
j = 0;
t1 = 0;
while (j <= length - 1) {
int c = song[j];
if (c >= 128) c = c - 256;
int t4 = (int)((c + t1) & 0x00000000FFFFFFFF);
t1 = (int)((t1 << (j % 2 + 3)) & 0x00000000FFFFFFFF);
t1 = (int)((t1 + t4) & 0x00000000FFFFFFFF);
j += 1;
}
int t5 = (int)Conv(t2 ^ t3);
t5 = (int)Conv(t5 + (t1 | lrcId));
t5 = (int)Conv(t5 * (t1 | t3));
t5 = (int)Conv(t5 * (t2 ^ lrcId));
long t6 = (long)t5;
if (t6 > 2147483648)
t5 = (int)(t6 - 4294967296);
return t5.ToString();
}
public static long Conv(int i) {
long r = i % 4294967296;
if (i >= 0 && r > 2147483648)
r = r - 4294967296;
if (i < 0 && r < 2147483648)
r = r + 4294967296;
return r;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace QianQianLrc {
public class EncodeHelper {
public static string ToQianQianHexString(string s, Encoding encoding) {
StringBuilder sb = new StringBuilder();
byte[] bytes = encoding.GetBytes(s);
foreach (byte b in bytes) {
sb.Append(b.ToString("X").PadLeft(2, '0'));
}
return sb.ToString();
}
public static string CreateQianQianCode(string singer, string title, int lrcId) {
string qqHexStr = ToQianQianHexString(singer + title, Encoding.UTF8);
int length = qqHexStr.Length / 2;
int[] song = new int[length];
for (int i = 0; i < length; i++) {
song[i] = int.Parse(qqHexStr.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
}
int t1 = 0, t2 = 0, t3 = 0;
t1 = (lrcId & 0x0000FF00) >> 8;
if ((lrcId & 0x00FF0000) == 0) {
t3 = 0x000000FF & ~t1;
} else {
t3 = 0x000000FF & ((lrcId & 0x00FF0000) >> 16);
}
t3 = t3 | ((0x000000FF & lrcId) << 8);
t3 = t3 << 8;
t3 = t3 | (0x000000FF & t1);
t3 = t3 << 8;
if ((lrcId & 0xFF000000) == 0) {
t3 = t3 | (0x000000FF & (~lrcId));
} else {
t3 = t3 | (0x000000FF & (lrcId >> 24));
}
int j = length - 1;
while (j >= 0) {
int c = song[j];
if (c >= 0x80) c = c - 0x100;
t1 = (int)((c + t2) & 0x00000000FFFFFFFF);
t2 = (int)((t2 << (j % 2 + 4)) & 0x00000000FFFFFFFF);
t2 = (int)((t1 + t2) & 0x00000000FFFFFFFF);
j -= 1;
}
j = 0;
t1 = 0;
while (j <= length - 1) {
int c = song[j];
if (c >= 128) c = c - 256;
int t4 = (int)((c + t1) & 0x00000000FFFFFFFF);
t1 = (int)((t1 << (j % 2 + 3)) & 0x00000000FFFFFFFF);
t1 = (int)((t1 + t4) & 0x00000000FFFFFFFF);
j += 1;
}
int t5 = (int)Conv(t2 ^ t3);
t5 = (int)Conv(t5 + (t1 | lrcId));
t5 = (int)Conv(t5 * (t1 | t3));
t5 = (int)Conv(t5 * (t2 ^ lrcId));
long t6 = (long)t5;
if (t6 > 2147483648)
t5 = (int)(t6 - 4294967296);
return t5.ToString();
}
public static long Conv(int i) {
long r = i % 4294967296;
if (i >= 0 && r > 2147483648)
r = r - 4294967296;
if (i < 0 && r < 2147483648)
r = r + 4294967296;
return r;
}
}
}
QianQianLrcer.cs:---这个类负责请求歌词:
view plaincopy to clipboardprint?
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;
using System.Windows.Forms;
using System.Collections;
namespace QianQianLrc {
public class QianQianLrcer {
public static readonly string SearchPath = "http://ttlrcct2.qianqian.com/dll/lyricsvr.dll?sh?Artist={0}&Title={1}&Flags=0";
public static readonly string DownloadPath = "http://ttlrcct2.qianqian.com/dll/lyricsvr.dll?dl?Id={0}&Code={1}";
public static ArrayList listSongs = new ArrayList();
public static searchState sState = searchState.none;
public enum searchState { none=1,begin , loading , complete};
public void DownLoadLrc2(string singer, string title, int lrcId)
{
string sURL = string.Format(DownloadPath, lrcId, EncodeHelper.CreateQianQianCode(singer, title, lrcId));
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string sContent = "";
try
{
sContent = wc.DownloadString(sURL);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
sContent = sContent.Trim();
// MessageBox.Show(sContent);
}
void createFoldaer(string folderPath) {
if (Directory.Exists(folderPath)) return;
try {
Directory.CreateDirectory(folderPath);
}
catch(Exception ex){
MessageBox.Show(ex.Message);
}
}
private bool searchLocal(string singer, string title)
{
createFoldaer(ClassCommon.cfg_lrc_folder);
foreach (string file in Directory.GetFiles(ClassCommon.cfg_lrc_folder)){
if (file.Trim().IndexOf(singer +"-" + title)>=0)
{
if (checkFileContains(file, "[ar:singer]")) { return true; }
}
};
return false;
}
bool checkFileContains(string strFile ,string strInput) {
Stream oStream=null ;
StreamReader oReader=null ;
string sContent = "";
try
{
oStream = File.Open(strFile, FileMode.OpenOrCreate);
oReader = new StreamReader(oStream ,Encoding.Default );
sContent = oReader.ReadToEnd();
if (sContent.Contains(strInput)) {
return true;
}
oReader.Close();
oStream.Close();
}
catch (Exception ex){
if (oReader!=null )
{
oReader.Close();}
if(oStream!=null ){
oStream.Close();}
MessageBox.Show("Can not open file : " + ex.Message );
}
return false;
}
public void SearchLrc(string singer, string title) {
if (searchLocal(singer, title)) { return; }
singer = singer.ToLower().Replace(" ", "").Replace("'", "");
title = title.ToLower().Replace(" ", "").Replace("'", "");
string sURL = string.Format(SearchPath,
EncodeHelper.ToQianQianHexString(singer, Encoding.Unicode),
EncodeHelper.ToQianQianHexString(title, Encoding.Unicode)) ;
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string sContent="" ;
try
{
sContent = wc.DownloadString(sURL);
}
catch (Exception ex){
MessageBox.Show(ex.Message );
return;
}
sContent = sContent.Trim();
MessageBox.Show(sContent);
XmlDocument doc = new XmlDocument();
listSongs.Clear();
try
{
doc.LoadXml(sContent);
foreach (XmlNode node in doc.SelectNodes("/result/lrc"))
{
int xId= int.Parse(node.Attributes["id"].Value);
string xSinger = node.Attributes["artist"].Value;
string xTitle = node.Attributes["title"].Value;
SongBase sb = new SongBase(xId, xSinger, xTitle);
listSongs.Add(sb);
DownLoadLrc2(sb.Artist, sb.Title, sb.Id);
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
return;
}
}
}
public class SongBase {
public SongBase(int id,string artist,string title) {
this.id = id;
this.artist = artist;
this.title = title;
}
private int id;
private string artist;
private string title;
public string Title {
get { return title; }
set { title = value; }
}
public string Artist {
get { return artist; }
set { artist = value; }
}
public int Id {
get { return id; }
set { id = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;
using System.Windows.Forms;
using System.Collections;
namespace QianQianLrc {
public class QianQianLrcer {
public static readonly string SearchPath = "http://ttlrcct2.qianqian.com/dll/lyricsvr.dll?sh?Artist={0}&Title={1}&Flags=0";
public static readonly string DownloadPath = "http://ttlrcct2.qianqian.com/dll/lyricsvr.dll?dl?Id={0}&Code={1}";
public static ArrayList listSongs = new ArrayList();
public static searchState sState = searchState.none;
public enum searchState { none=1,begin , loading , complete};
public void DownLoadLrc2(string singer, string title, int lrcId)
{
string sURL = string.Format(DownloadPath, lrcId, EncodeHelper.CreateQianQianCode(singer, title, lrcId));
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string sContent = "";
try
{
sContent = wc.DownloadString(sURL);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
sContent = sContent.Trim();
// MessageBox.Show(sContent);
}
void createFoldaer(string folderPath) {
if (Directory.Exists(folderPath)) return;
try {
Directory.CreateDirectory(folderPath);
}
catch(Exception ex){
MessageBox.Show(ex.Message);
}
}
private bool searchLocal(string singer, string title)
{
createFoldaer(ClassCommon.cfg_lrc_folder);
foreach (string file in Directory.GetFiles(ClassCommon.cfg_lrc_folder)){
if (file.Trim().IndexOf(singer +"-" + title)>=0)
{
if (checkFileContains(file, "[ar:singer]")) { return true; }
}
};
return false;
}
bool checkFileContains(string strFile ,string strInput) {
Stream oStream=null ;
StreamReader oReader=null ;
string sContent = "";
try
{
oStream = File.Open(strFile, FileMode.OpenOrCreate);
oReader = new StreamReader(oStream ,Encoding.Default );
sContent = oReader.ReadToEnd();
if (sContent.Contains(strInput)) {
return true;
}
oReader.Close();
oStream.Close();
}
catch (Exception ex){
if (oReader!=null )
{
oReader.Close();}
if(oStream!=null ){
oStream.Close();}
MessageBox.Show("Can not open file : " + ex.Message );
}
return false;
}
public void SearchLrc(string singer, string title) {
if (searchLocal(singer, title)) { return; }
singer = singer.ToLower().Replace(" ", "").Replace("'", "");
title = title.ToLower().Replace(" ", "").Replace("'", "");
string sURL = string.Format(SearchPath,
EncodeHelper.ToQianQianHexString(singer, Encoding.Unicode),
EncodeHelper.ToQianQianHexString(title, Encoding.Unicode)) ;
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
string sContent="" ;
try
{
sContent = wc.DownloadString(sURL);
}
catch (Exception ex){
MessageBox.Show(ex.Message );
return;
}
sContent = sContent.Trim();
MessageBox.Show(sContent);
XmlDocument doc = new XmlDocument();
listSongs.Clear();
try
{
doc.LoadXml(sContent);
foreach (XmlNode node in doc.SelectNodes("/result/lrc"))
{
int xId= int.Parse(node.Attributes["id"].Value);
string xSinger = node.Attributes["artist"].Value;
string xTitle = node.Attributes["title"].Value;
SongBase sb = new SongBase(xId, xSinger, xTitle);
listSongs.Add(sb);
DownLoadLrc2(sb.Artist, sb.Title, sb.Id);
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
return;
}
}
}
public class SongBase {
public SongBase(int id,string artist,string title) {
this.id = id;
this.artist = artist;
this.title = title;
}
private int id;
private string artist;
private string title;
public string Title {
get { return title; }
set { title = value; }
}
public string Artist {
get { return artist; }
set { artist = value; }
}
public int Id {
get { return id; }
set { id = value; }
}
}
}
调用方法:
view plaincopy to clipboardprint?
QianQianLrcer loader = new QianQianLrcer();
private void button1_Click(object sender, EventArgs e)
{
loader.SearchLrc(textBox1.Text,textBox2.Text);
//textBox1为演唱的人,textBox2为歌曲名
// MessageBox.Show(((SongBase)(QianQianLrcer.listSongs[0])).Artist);
// MessageBox.Show(((SongBase)(QianQianLrcer.listSongs[1])).Artist);
}
QianQianLrcer loader = new QianQianLrcer();
private void button1_Click(object sender, EventArgs e)
{
loader.SearchLrc(textBox1.Text,textBox2.Text);
//textBox1为演唱的人,textBox2为歌曲名
// MessageBox.Show(((SongBase)(QianQianLrcer.listSongs[0])).Artist);
// MessageBox.Show(((SongBase)(QianQianLrcer.listSongs[1])).Artist);
}
另外一个方法是通过:http://www.qianqian.com/downloadmp3.php?title=千千阙歌&artist=陈慧娴
搜索 在正测表达式匹配 进行获取歌词
或者这个地址: http://www.qianqian.com/lrcresult.php?qword=冰雨%20刘德华&qfield=3