using Helper;
using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
namespace DAL
{
    /// <summary>
    /// 一听音乐www.1ting.com
    /// </summary>
    public class _1Ting : IMusic
    {
        public List<Music> Search(string word, int page, int num)
        {
            List<Music> list = new List<Music>();
            string src = HttpHelper.Get(string.Format("https://so.1ting.com/song/json?q={0}&page={1}&size={2}", word, page, num));
            string[] infos = CommonHelper.GetMiddleTextMultiple(src, "{\"s", "\"}");
            foreach (string i in infos)
            {
                Music s = new Music();
                s.Id = CommonHelper.GetMiddleText(i, "song_id\":\"", "\",\"album_id");
                s.Name = CommonHelper.GetMiddleText(i, "song_name\":\"", "\",\"song_id");
                s.Album = CommonHelper.GetMiddleText(i, "album_name\":\"", "\",\"album_published");
                s.Artist = CommonHelper.GetMiddleText(i, "inger_name\":\"", "\",\"singer_alias");
                s.PicId = CommonHelper.GetMiddleText(i, "pic_id\":\"", "\",\"url_id");
                s.Source = "_1Ting";
                s.ToString();
                list.Add(s);
            }
            return list;
        }
        public List<Music> SearchCollection(string id)
        {
            throw new NotImplementedException();
        }
        public bool GetData(Music m)
        {
            string src = HttpHelper.Get("https://h5.1ting.com/touch/api/song?ids=" + m.Id);
            m.PicUrl = "https:" + CommonHelper.GetMiddleText(src, "album_cover\":\"", "\"}]").Replace("\\", "");
            string lrcsrc = HttpHelper.Get("https://h5.1ting.com/touch/api/lyric/" + m.Id);
            m.Lrc = CommonHelper.GetMiddleText(lrcsrc, "lyric_content\":\"", "\",\"lyric_lock");
            GetLrc(m);
            //if (Lrc.Count < 2)
            //{ base.GetLrc(); }
            m.Url = "https://96.f.1ting.com/local_to_cube_202004121813/96kmp3"
            + CommonHelper.GetMiddleText(src, "song_filepath\":\"", "\",\"singer_name").Replace("\\", "").Replace("wma", "mp3");
            return HttpHelper.CheckUri(m.Url);
        }
        public void GetLrc(Music m)
        {
            string lrcsrc = HttpHelper.Get("https://h5.1ting.com/touch/api/lyric/" + m.Id);
            m.Lrc = CommonHelper.GetMiddleText(lrcsrc, "lyric_content\":\"", "\",\"lyric_lock");
        }
    }
}
