using Helper;
using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Text;

namespace DAL
{
   public class Migu: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://myhkw.cn/api/web?callback=jQuery111302529165284412005_1606220690477&types=search&count={0}&source=migu&pages={1}&name={2}&_=1606220690483", 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.RemoveInvalidFile(CommonHelper.GetMiddleText(info, "artist\":[\"", "\"],\"album"));
                s.Name = CommonHelper.RemoveInvalidFile(CommonHelper.GetMiddleText(info, "name\":\"", "\",\"artist"));
                s.Album = CommonHelper.GetMiddleText(info, "album\":\"", "\",\"pic_id");
                s.PicId = CommonHelper.GetMiddleText(info, "pic_id\":\"", "\",\"url_id");
                s.Source = "Migu";
                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)
        {
            m.PicUrl =string.Format("https://myhkw.cn/api/musicPic?picId={0}&type=mg&size=big", m.PicId);
            GetLrc(m);
            m.Url = HttpHelper.ConvereUrl( string.Format("https://myhkw.cn/api/musicUrl?songId={0}&type=mg&id=155782152289",m.Id));
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Model.Music m)
        {
            string Lrcsrc = HttpHelper.Get(string.Format("https://myhkw.cn/api/musicLyric?callback=jQuery111302529165284412005_1606220690477&type=mg&songId={0}&id=myhkwebplayer&_=1606220690481", m.Id));
            m.Lrc = CommonHelper.GetMiddleText(Lrcsrc, "lyric\":\"", "\",\"br").Trim().Replace("\\n", "\n").Replace("\\r", "");
        }

    }
}
