Exemple #1
0
 /// <summary>
 /// 提取搜索结果中有用的信息
 /// </summary>
 /// <param name="title">搜索标题</param>
 /// <returns></returns>
 public static FiltratedData[] GetFiltratedSearchResult(string title)
 {
     QQMusicSearchData rawdata = GetSearchResult(title);
     FiltratedData[] datas=new FiltratedData[rawdata.data.song.list.Count];
     for (int i = 0; i < datas.Length; i++)
     {
         datas[i]=new FiltratedData();
         datas[i].Album = rawdata.data.song.list[i].albumname;
         foreach (var singer in rawdata.data.song.list[i].singer)
         {
             if (datas[i].Aritist != null) datas[i].Aritist += "/" + singer.name;
             else datas[i].Aritist = singer.name;
         }
         datas[i].SongId = rawdata.data.song.list[i].songid;
         datas[i].SongMid = rawdata.data.song.list[i].songmid;
         datas[i].SongTitle = rawdata.data.song.list[i].songname;
     }
     return datas;
 }
Exemple #2
0
 /// <summary>
 /// 得到音乐搜索结果
 /// </summary>
 /// <param name="title"></param>
 /// <returns></returns>
 private static QQMusicSearchData GetSearchResult(string title)
 {
     WebClient webClient = new WebClient();
     webClient.Encoding = Encoding.UTF8;
     string rawjson = webClient.DownloadString(
         @"https://c.y.qq.com/soso/fcgi-bin/search_cp?remoteplace=txt.yqq.center&searchid=37159670560306796&t=0&aggr=1&cr=1&catZhIDA=1&lossless=0&flag_qc=0&p=1&n=100&w=" +
         title +
         "&g_tk=5381&jsonpCallback=searchCallbacksong1291&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0");
     string[] datas=rawjson.Split(new char[] {'(', ')'});
     string json = null;
     for (int i = 1; i < datas.Length - 1; i++)
     {
         json += datas[i];
     }
     JsonSerializerSettings setting=new JsonSerializerSettings();
     setting.NullValueHandling = NullValueHandling.Ignore;
     QQMusicSearchData resultData = JsonConvert.DeserializeObject<QQMusicSearchData>(json,setting);//反序列化
     return resultData;
 }