Ejemplo n.º 1
0
        /// <summary>
        /// 网易云音乐搜索歌曲
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        List <MusicInfo> NeteaseSearch(string Key, int Page = 1, int limit = 100)
        {
            if (Key == null || Key == "")
            {
                return(null);
            }
            WebClientPro wc     = new WebClientPro();
            string       offset = ((Page - 1) * 100).ToString();
            string       url    = NeteaseApiUrl + "search?keywords=" + Key + "&limit=" + limit.ToString() + "&offset=" + offset;
            string       json   = GetHTML(url);

            if (json == null || json == "")
            {
                return(null);
            }
            Json.SearchResultJson.Root srj = JsonConvert.DeserializeObject <Json.SearchResultJson.Root>(json);
            List <Json.MusicInfo>      ret = new List <Json.MusicInfo>();

            if (srj.result.songs == null)
            {
                return(null);
            }
            string ids = "";

            for (int i = 0; i < srj.result.songs.Count; i++)
            {
                ids += srj.result.songs[i].id + ",";
            }
            string _u = NeteaseApiUrl + "song/detail?ids=" + ids.Substring(0, ids.Length - 1);
            string j  = GetHTML(_u);

            Json.NeteaseMusicDetails.Root mdr = JsonConvert.DeserializeObject <Json.NeteaseMusicDetails.Root>(j);
            for (int i = 0; i < mdr.songs.Count; i++)
            {
                string singer = "";
                for (int x = 0; x < mdr.songs[i].ar.Count; x++)
                {
                    singer += mdr.songs[i].ar[x].name + "、";
                    //singerid.Add(mdr.songs[i].ar[x].id.ToString());
                }
                Json.MusicInfo mi = new Json.MusicInfo()
                {
                    Album  = mdr.songs[i].al.name,
                    Id     = mdr.songs[i].id.ToString(),
                    LrcUrl = NeteaseApiUrl + "lyric?id=" + mdr.songs[i].id.ToString(),
                    PicUrl = mdr.songs[i].al.picUrl + "?param=300y300",
                    Singer = singer.Substring(0, singer.Length - 1),
                    Title  = mdr.songs[i].name,
                    Api    = 1
                };
                ret.Add(mi);
            }
            return(ret);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 解析网易云音乐歌单的内部方法
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        private List <MusicInfo> _GetNeteaseMusicList(string ids)
        {
            List <Json.MusicInfo> ret = new List <Json.MusicInfo>();
            string _u = NeteaseApiUrl + "song/detail?ids=" + ids;
            string j  = GetHTML(_u);

            Json.NeteaseMusicDetails.Root mdr = JsonConvert.DeserializeObject <Json.NeteaseMusicDetails.Root>(j);
            string u = NeteaseApiUrl + "song/url?id=" + ids + "&br=" + setting.DownloadQuality;

            Json.GetUrl.Root urls = JsonConvert.DeserializeObject <Json.GetUrl.Root>(GetHTML(u));
            for (int i = 0; i < mdr.songs.Count; i++)
            {
                string        singer   = "";
                List <string> singerid = new List <string>();
                string        _url     = "";

                for (int x = 0; x < mdr.songs[i].ar.Count; x++)
                {
                    singer += mdr.songs[i].ar[x].name + "、";
                    singerid.Add(mdr.songs[i].ar[x].id.ToString());
                }

                for (int x = 0; x < urls.data.Count; x++)
                {
                    if (urls.data[x].id == mdr.songs[i].id)
                    {
                        _url = urls.data[x].url;
                    }
                }

                MusicInfo mi = new MusicInfo()
                {
                    Album  = mdr.songs[i].al.name,
                    Id     = mdr.songs[i].id.ToString(),
                    LrcUrl = NeteaseApiUrl + "lyric?id=" + mdr.songs[i].id.ToString(),
                    PicUrl = mdr.songs[i].al.picUrl + "?param=300y300",
                    Singer = singer.Substring(0, singer.Length - 1),
                    Title  = mdr.songs[i].name,
                    Api    = 1
                };
                ret.Add(mi);
            }
            return(ret);
        }