/// <summary> /// 歌词搜索 /// </summary> /// <param name="singer"></param> /// <param name="title"></param> public void SearchLrc(string singer, string title) { singer = singer.ToLower().Replace(" ", "").Replace("'", ""); title = title.ToLower().Replace(" ", "").Replace("'", ""); string htmlCode = RequestUrl(string.Format(SearchPath, HtmlHelperEncode.HexString(singer, Encoding.Unicode), HtmlHelperEncode.HexString(title, Encoding.Unicode))); XmlDocument xml = new XmlDocument(); try { xml.LoadXml(htmlCode); XmlNodeList list = xml.SelectNodes("/result/lrc"); //将歌词列表以XML的形式返回到窗体 this.OnSelectSong(list); } catch (Exception ex) { } }
/// <summary> /// 下载歌词文件 /// </summary> /// <returns></returns> public bool DownloadLrc(string lrcName) { bool flag = false; //获取当前指定的XmlNode歌词信息 XmlNode node = this.currentSong; int lrcId = -1; //判断当前XmlNode是否完整 if (node != null && node.Attributes != null && node.Attributes["id"] != null) { string id = node.Attributes["id"].Value; //判断当前Id是否是Int类型 if (int.TryParse(id, out lrcId)) { string xSinger = node.Attributes["artist"].Value; string xTitle = node.Attributes["title"].Value; string xId = node.Attributes["id"].Value; //请求Http,获取歌词信息 string htmlCode = RequestUrl(string.Format(DownloadPath, int.Parse(xId), HtmlHelperEncode.CreateEncode(xSinger, xTitle, int.Parse(xId)))); using (StreamWriter sw = new StreamWriter(string.Format("{0}\\lrc\\{1}", Application.StartupPath, lrcName), false, Encoding.UTF8)) { sw.WriteLine(htmlCode); } flag = true; } } return(flag); }