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
{
    /// <summary>
    /// 猫耳FM
    /// </summary>
    public class Missevan : IMusic
    {
        public List<Music> Search(string word, int page, int num)
        {
            List<Music> list = new List<Music>();
            string src = HttpHelper.Get(string.Format("https://www.missevan.com/sound/getsearch?s={0}&p={1}&type=3&page_size={2}&cid=48",  word,page,num));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "{\"sou", "view_count_formatted");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.Extract("\"id\":\"(.*?)\",",i);
                s.Name = CommonHelper.Extract("str\":\"(.*?)\",\"username",i);
                s.Album = CommonHelper.Extract("",i);
                s.Artist = CommonHelper.Extract("username\":\"(.*?)\",\"id",i);
                s.PicId = CommonHelper.Extract("front_cover\":\"(.*?)\",\"video",i);
                s.Source = "Missevan";
                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("https://www.missevan.com/sound/getsound?soundid={0}", m.Id));
            m.PicUrl = m.PicId;
            m.Url = CommonHelper.Extract("soundurl\":\"(.*?)\",",src);
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Music m)
        {
            throw new NotImplementedException();
        }
    }
}