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

namespace DAL
{
    public class YYmp3 : IMusic
    {
        public List<Music> Search(string word, int page, int num)
        {
            List<Music> list = new List<Music>();
            string src = HttpHelper.Get(string.Format(
                "http://www.yymp3.com/search/?page={0}&key={1}&tp=1"
                , page, word));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "<input type=checkbox", "target=_blank>歌词</a></div></li>");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Artist = CommonHelper.GetMiddleText(i, "\" target=_blank>", "</a></div>").Replace("<font color=red>", "").Replace("</font>", "");
                s.Name = CommonHelper.GetMiddleText(i, "\" target=\"_yymp3\">", "</a></div>").Replace("<font color=red>", "").Replace("</font>", "");
                s.Id = CommonHelper.GetMiddleText(i, "<div class=\"p3\"><a href=\"", "\" target=\"_yymp3\">");
                s.Source = "YYmp3";
                list.Add(s);
            }
            return list;
        }

        public List<Music> SearchCollection(string id)
        {
            throw new NotImplementedException();
        }

        public bool GetData(Music m)
        {
            string src = HttpHelper.Get("http://www.yymp3.com" + m.Id);
            m.Url = "http://ting6.yymp3.net:82/new" + CommonHelper.GetMiddleText(src, "|new", ".wma") + ".mp3";
            return HttpHelper.CheckUri(m.Url);
        }

        public void GetLrc(Music m)
        {
            throw new NotImplementedException();
        }
    }
}
