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 _127 : IMusic
    {
        public List<Music> Search(string word, int page, int num)
        {
            List<Music> list = new List<Music>();
            string src = HttpHelper.Get(string.Format("http://mp3.flash127.com/sou/{0}/{1}.html",  word,page,num));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "type=\"checkbox", "class=\"m_z\" target=\"play\">");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.Extract("class=\"check\" value=\"(.*?)\"> .*? - .*?",i);
                s.Name = CommonHelper.Extract("class=\"check\" value=\".*?\"> .*? - (.*?)",i);
                s.Album = CommonHelper.Extract("",i);
                s.Artist = CommonHelper.Extract("class=\"check\" value=\".*?\"> (.*?) - .*?",i);
                s.PicId = CommonHelper.Extract("",i);
                s.Source = "_127";
                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 = CommonHelper.Extract("<img src=\"(.*?)\" class=\"qrcode\" />",src);
            m.Url = CommonHelper.Extract("\"url\":\"(.*?)\",\"url2",src);
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Music m)
        {
            throw new NotImplementedException();
        }
    }
}