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