Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            Result.Clear();
            WebClient web     = new WebClient();
            string    webSite = "http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=" + textBox1.Text + "&page=1&pagesize=30";

            byte[]        buffer = web.DownloadData(webSite);
            string        html   = Encoding.UTF8.GetString(buffer);
            JObject       kugou  = JObject.Parse(html);
            List <JToken> all    = kugou["data"]["info"].Children().ToList();

            all.ForEach(x =>
            {
                KugouResult kg = JsonConvert.DeserializeObject <KugouResult>(x.ToString());
                //kg.hash = x["320hash"].ToString();
                if (kg.sqhash != "")
                {
                    SkinListBoxItem sl = new SkinListBoxItem(kg.filename);

                    listBox1.Items.Add(sl);
                    kg.key       = GetMD5(kg.sqhash + "kgcloud");
                    webSite      = "http://trackercdn.kugou.com/i/?cmd=4&hash=" + kg.sqhash + "&key=" + kg.key + "&pid=1&forceDown=0&vip=1";
                    buffer       = web.DownloadData(webSite);
                    html         = Encoding.UTF8.GetString(buffer);
                    JObject flac = JObject.Parse(html);
                    Result.Add(flac["url"].ToString().Replace("\\", ""));
                }
            });
        }
Esempio n. 2
0
        /// <summary>
        /// 获取歌曲列表
        /// </summary>
        /// <param name="page"></param>
        private void GetList(int page)
        {
            StartProcessBar();
            pageNum.Text = "第" + page + "页";
            resultListView.Items.Clear();
            toolStripStatusLabel1.Text = "搜索中...";
            List <ListViewItem> listViewItems = new List <ListViewItem>();
            Task getListTask = new Task(() =>
            {
                WebClient web     = new WebClient();
                string webSite    = "http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=" + textBox1.Text + "&page=" + page + "&pagesize=100";
                byte[] buffer     = web.DownloadData(webSite);
                string html       = Encoding.UTF8.GetString(buffer);
                JObject kugou     = JObject.Parse(html);
                List <JToken> all = kugou["data"]["info"].Children().ToList();
                all.ForEach(x =>
                {
                    KugouResult kg = JsonConvert.DeserializeObject <KugouResult>(x.ToString());
                    //kg.hash = x["320hash"].ToString();    //320音质的hash值
                    if (kg.sqhash != "")
                    {
                        kg.key       = GetMD5(kg.sqhash + "kgcloud");
                        webSite      = "http://trackercdn.kugou.com/i/?cmd=4&hash=" + kg.sqhash + "&key=" + kg.key + "&pid=1&forceDown=0&vip=1";
                        buffer       = web.DownloadData(webSite);
                        html         = Encoding.UTF8.GetString(buffer);
                        JObject flac = JObject.Parse(html);
                        if (flac["status"].ToString() == "1")     //成功获取才添加到显示列表和Result中
                        {
                            //SkinListBoxItem sl = new SkinListBoxItem(kg.filename);
                            //resultListView.Items.Add(sl);

                            ListViewItem lvi = new ListViewItem();
                            lvi.Text         = kg.filename;
                            lvi.SubItems.Add(flac["bitRate"].ToString());
                            lvi.SubItems.Add(flac["extName"].ToString());
                            lvi.SubItems.Add((double.Parse(flac["fileSize"].ToString()) / (1024 * 1024)).ToString("F2") + "MB"); //将文件大小装换成MB的单位
                            TimeSpan ts = new TimeSpan(0, 0, int.Parse(flac["timeLength"].ToString()));                          //把秒数换算成分钟数
                            lvi.SubItems.Add(ts.Minutes + ":" + ts.Seconds.ToString("00"));
                            lvi.Tag = flac["url"].ToString().Replace("\\", "");
                            listViewItems.Add(lvi);
                        }
                    }
                });
                UpdateUI(listViewItems);
            });

            getListTask.Start();
        }
Esempio n. 3
0
        //List<string> Result = new List<string>();

        //搜索
        private void button1_Click(object sender, EventArgs e)
        {
            //listBox1.Items.Clear();
            resultListView.Items.Clear();
            //Result.Clear();
            WebClient web     = new WebClient();
            string    webSite = "http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=" + textBox1.Text + "&page=1&pagesize=30";

            byte[]        buffer = web.DownloadData(webSite);
            string        html   = Encoding.UTF8.GetString(buffer);
            JObject       kugou  = JObject.Parse(html);
            List <JToken> all    = kugou["data"]["info"].Children().ToList();

            resultListView.BeginUpdate();   //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            all.ForEach(x =>
            {
                KugouResult kg = JsonConvert.DeserializeObject <KugouResult>(x.ToString());
                //kg.hash = x["320hash"].ToString();    //320音质的hash值
                if (kg.sqhash != "")
                {
                    kg.key       = GetMD5(kg.sqhash + "kgcloud");
                    webSite      = "http://trackercdn.kugou.com/i/?cmd=4&hash=" + kg.sqhash + "&key=" + kg.key + "&pid=1&forceDown=0&vip=1";
                    buffer       = web.DownloadData(webSite);
                    html         = Encoding.UTF8.GetString(buffer);
                    JObject flac = JObject.Parse(html);
                    if (flac["status"].ToString() == "1")   //成功获取才添加到显示列表和Result中
                    {
                        //SkinListBoxItem sl = new SkinListBoxItem(kg.filename);
                        //resultListView.Items.Add(sl);

                        ListViewItem lvi = new ListViewItem();
                        lvi.Text         = kg.filename;
                        lvi.SubItems.Add(flac["bitRate"].ToString());
                        lvi.SubItems.Add(flac["extName"].ToString());
                        lvi.SubItems.Add((double.Parse(flac["fileSize"].ToString()) / (1024 * 1024)).ToString("F2") + "MB"); //将文件大小装换成MB的单位
                        TimeSpan ts = new TimeSpan(0, 0, int.Parse(flac["timeLength"].ToString()));                          //把秒数换算成分钟数
                        lvi.SubItems.Add(ts.Minutes + ":" + ts.Seconds.ToString("00"));
                        lvi.Tag = flac["url"].ToString().Replace("\\", "");
                        resultListView.Items.Add(lvi);

                        //Result.Add(flac["url"].ToString().Replace("\\", ""));
                    }
                }
            });
            resultListView.EndUpdate();  //结束数据处理,UI界面一次性绘制
        }