using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using Model;
using Helper;
using System.Text.RegularExpressions;
using System.Net;
namespace DAL
{
    /// <summary>
    /// 酷狗音乐www.kugou.com
    /// </summary>
    public class Kugou : IMusic
    {
        public List<Model.Music> Search(string word, int page, int num)
        {
            List<Music> list = new List<Music>();
            string src = HttpHelper.Get(string.Format(
                "https://yinle.rzzkk520.cn/api.php?callback=jQuery11130182920795747622_1585018563804&types=search&count={0}&source=kugou&pages={1}&name={2}"
                , num, page, word));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "{\"", "},");
            foreach (string info in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.GetMiddleText(info, "id\":\"", "\",\"name");
                s.Artist = CommonHelper.GetMiddleText(info, "artist\":[\"", "\"],\"album");
                s.Name = CommonHelper.GetMiddleText(info, "name\":\"", "\",\"artist");
                s.Album = CommonHelper.GetMiddleText(info, "album\":\"", "\",\"url_id");
                s.PicId = CommonHelper.GetMiddleText(info, "pic_id\":\"", "\",\"lyric_id");
                s.Source = "Kugou";
                s.ToString();
                list.Add(s);
            }
            return list;
        }
        public List<Model.Music> SearchCollection(string id)
        {
            List<Music> list = new List<Music>();
            return list;
        }
        public bool GetData(Model.Music m)
        {
            string Src = HttpHelper.Get(string.Format(
                "http://guozhivip.com/yinyue/api.php?callback=jQuery11130182920795747622_1585018563804&types=url&id={0}&source=kugou"
                , m.Id));
            string picsrc = HttpHelper.Get(string.Format(
                "http://yinle.rzzkk520.cn/api.php?callback=jQuery11130182920795747622_1585018563804&types=pic&id={0}&source=kugou"
                , m.PicId));
            m.PicUrl = CommonHelper.GetMiddleText(picsrc, "url\":\"","\"})").Replace("\\", "");
            GetLrc(m);
            m.Url = CommonHelper.GetMiddleText(Src, "url\":\"", "\",\"size").Replace("\\", "");
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Model.Music m)
        {
            string Lrcsrc = HttpHelper.Get(string.Format(
                "http://guozhivip.com/yinyue/api.php?callback=jQuery11130182920795747622_1585018563804&types=lyric&id={0}&source=kugou"
                , m.Id));
            m.Lrc = CommonHelper.GetMiddleText(Lrcsrc, "lyric\":\"", "\",\"tlyric").Trim().Replace("\\n", "\n").Replace("\\r", "");
        }
    }
}
