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

namespace DAL
{
    /// <summary>
    /// 听哇纯音乐www.itingwa.com
    /// </summary>
   public class Tingwa: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://so.itingwa.com/?c=index&k={0}&t=1&p={1}", word,page));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "<td><a href=\"h", "height=\"20\" />");
            foreach (string info in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.GetMiddleText(info, "www.itingwa.com/listen/", "\" target=");
                s.Artist = CommonHelper.RemoveInvalidFile(CommonHelper.GetMiddleText(info, "/?c=index&k=", "\">"));
                s.Name = CommonHelper.RemoveInvalidFile(CommonHelper.GetMiddleText(info, "listen\">", "</a></td>"));
                //s.Album = CommonHelper.GetMiddleText(info, "album\":\"", "\",\"pic_id");
                s.PicId = CommonHelper.GetMiddleText(info, "<a href=\"https://www.itingwa.com/u/", "\" >");
                s.Source = "Tingwa";
                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 picsrc = HttpHelper.Get("https://www.itingwa.com/u/" + m.PicId);
            m.PicUrl = CommonHelper.GetMiddleText(picsrc, "<img src=\"", "\" width=");
            string src = HttpHelper.Get("https://www.itingwa.com/listen/" + m.Id);
            m.Url = CommonHelper.GetMiddleText(src,"init-data=\"","\">");
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Model.Music m)
        {
        }
    }
}
