using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using Model;
using Helper;
using System.Text.RegularExpressions;
//0类名;1搜索api;2-3分离信息字符串左右部分;4-8歌曲基本信息
namespace DAL
{
    public class YDJ8 : 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.ydj8.com/?search={0}&p={1}.html", word, page, num));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "<span class=\"aleft\">", "<span class=\"time\">");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.Extract("href=\"/play/(.*?).html", i);
                s.Name = CommonHelper.Extract("target=\"p\">(.*?)</a></span>", i);
                s.Album = CommonHelper.Extract("", i);
                s.Artist = CommonHelper.Extract("href='/user.*?'>(.*?)</a></span>", i);
                s.PicId = CommonHelper.Extract("", i);
                s.Source = "YDJ8";
                s.ToString();
                list.Add(s);
            }
            return list;
        }
        public List<Model.Music> SearchCollection(string id)
        {
            throw new NotImplementedException("该平台暂未支持歌单解析");
        }
        public bool GetData(Music m)
        {
            string src = HttpHelper.Get(string.Format("http://mp3.flash127.com/play/{0}.html", m.Id));
            m.PicUrl = "http://www.ydj8.com/css/css/logo.png";
            m.Url = CommonHelper.Extract("src : \"(.*?)\",", src);
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Music m)
        {
            throw new NotImplementedException();
        }
    }
}