using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using Model;
using Helper;
using System.Text.RegularExpressions;
namespace DAL
{
    /// <summary>
    /// 酷我音乐www.kuwo.cn
    /// </summary>
    public class Kuwo : IMusic
    {
        public List<Music> Search(string word, int page, int num)
        {
            List<Music> list = new List<Music>();
            string src = HttpHelper.Get(string.Format("http://search.kuwo.cn/r.s?client=kt&all={0}&pn={1}&rn={2}&ft=music&plat=pc&cluster=1&result=json&rformat=json&ver=mbox&show_copyright_off=1&vipver=MUSIC_8.1.2.0_W4&encoding=utf8", word, page - 1, num));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "{'AA", "tpay");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.GetMiddleText(i, "MUSIC_", "','MUTI_VER");
                s.Name = CommonHelper.GetMiddleText(i, "NAME':'", "','NEW");
                s.Album = CommonHelper.GetMiddleText(i, "ALBUM':'", "','ALBUMID");
                s.Artist = CommonHelper.GetMiddleText(i, "ARTIST':'", "','ARTISTID");
                s.Source = "Kuwo";
                s.ToString();
                list.Add(s);
            }
            return list;
        }
        public List<Music> SearchCollection(string id)
        {
            List<Music> list = new List<Music>();
            return list;
        }
        public bool GetData(Music m)
        {
            m.PicUrl = HttpHelper.Get("http://artistpicserver.kuwo.cn/pic.web?type=rid_pic&pictype=url&size=120&rid=" + m.Id);
            GetLrc(m);
            m.Url = HttpHelper.Get("https://antiserver.kuwo.cn/anti.s?response=url&type=convert_url&br=320kmp3&format=mp3&rid=" + m.Id);
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Music m)
        {
            m.Lrc = Lyric.ParseKuwo(m.Id).Export;
        }
    }
}
