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 Lingdu : 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.0dutv.com/include/search.php?ac=play&key={0}&pages={1}", word, page, num));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src,  "<li class=\"","</span></li>");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.Extract("id=\"songid\" did='(.*?)'><i>",i);
                s.Name = CommonHelper.Extract("target=\"play\">(.*?)</a></span>",i);
                s.Artist = CommonHelper.Extract( "target=\"singer\">(.*?)</a>", i);
                s.PicId = CommonHelper.Extract( "", i);
                s.Source = "Lingdu";
                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://www.0dutv.com/play/{0}.html", m.Id));
            m.PicUrl = "http://www.0dutv.com/" + CommonHelper.Extract("<img src=\"(.*?)\" width=", src);
            m.Url = CommonHelper.Extract("(https:\\/\\/([\\w.]+\\/?)\\S*\\.(rm|mp3|wma))",src);
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Music m)
        {
            throw new NotImplementedException();
        }
    }
}