using Helper;
using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public class UUBZW : 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.uiu.cc/search/index/p/{0}/s/{1}"
                , page, word));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "<td>《<a title=", "</span> 试听");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Artist = CommonHelper.GetMiddleText(i, " <a title=\"", "的所有伴奏");
                s.Name = CommonHelper.GetMiddleText(i, "target=\"_blank\">", "</a>");
                s.Id = CommonHelper.GetMiddleText(i, "/accompaniment/show/id/", "\" target=\"_blank");
                s.Source = "UUBZW";
                list.Add(s);
            }
            return list;
        }

        public List<Music> SearchCollection(string id)
        {
            throw new NotImplementedException();
        }

        public bool GetData(Music m)
        {
            string src = HttpHelper.Get("https://www.uiu.cc/accompaniment/generate-preview-file/id/" + m.Id + "/keyChange/0").Replace("\\", "");
            m.PicUrl = "https://uiu-web-resources.sh1a.qingstor.com/images/artists_avar/320/" + CommonHelper.GetMiddleText(src, "photo\":\"", "\",\"cap");
            m.Url =HttpHelper.ConvereUrl( "https://www.uiu.cc/" + CommonHelper.GetMiddleText(src, "url\":\"", "\",\"accName"));
            return HttpHelper.CheckUri(m.Url);
        }

        public void GetLrc(Music m)
        {
            throw new NotImplementedException();
        }
    }
}
