static async Task <SearchResult> SearchByKey(string key, EnumMusicType type)
    {
        if (type == EnumMusicType.all)
        {
            return(await SearchAll(key));
        }
        int page = 1;

        while (true)
        {
            SearchResult sr = await _searchByKey(key, page, type);

            /////////////////////////////////////////
            if (sr == null || sr.Count == 0 || SearchManager.State == EnumSearchState.Cancelling)
            {
                break;
            }
            Artwork.MessageBus.MessageBus.Instance.Publish(sr);
            SearchManager.notifyState(sr);
            if (!sr.HasNext)
            {
                break;
            }
            page++;
        }
        return(null);
    }
Exemplo n.º 2
0
        public static IMusic CreateFromJson(dynamic obj, EnumMusicType type)
        {
            IMusic res = null;

            switch (type)
            {
            case EnumMusicType.album:
                res = new Album();
                break;

            case EnumMusicType.artist:
                res = new Artist();
                break;

            case EnumMusicType.collect:
                res = new Collection();
                break;

            case EnumMusicType.song:
                res = new Song();
                break;

            default:
                break;
            }
            if (res != null)
            {
                res.CreateFromJson(obj);
            }
            return(res);
        }
Exemplo n.º 3
0
 public static string UrlPlaylistByIdAndType(string id, EnumMusicType type)
 {
     return url_type_id.WithParams(new Dictionary<string, string>{
         {"id",id},
         {"type",type.ToString()}
     });
 }
Exemplo n.º 4
0
 public static string UrlSearch(string key, int page, EnumMusicType type)
 {
     return url_search_all.WithParams(new Dictionary<string, string>
     {
         {"key",key},
         {"type",type.ToString()+"s"},
         {"page",page.ToString()}
     });
 }
Exemplo n.º 5
0
 public static string UrlSearch(string key, int page, EnumMusicType type)
 {
     return(url_search_all.WithParams(new Dictionary <string, string>
     {
         { "key", key },
         { "type", type.ToString() + "s" },
         { "page", page.ToString() }
     }));
 }
	static async Task<SearchResult> SearchByType(EnumMusicType type, string id)
	{
		string url = XiamiUrl.UrlPlaylistByIdAndType(id, type);
		if(type == EnumMusicType.artist)
		{
			url = XiamiUrl.UrlArtistTopSong(id);
		}
		var json = await NetAccess.DownloadStringAsync(url);
		///////////////////////////////////////////////////////
		if(json == null) return null;
		List<IMusic> items = new List<IMusic>();
		switch(type)
		{
			case EnumMusicType.album:
				items = GetSongsOfAlbum(json);
				break;
			case EnumMusicType.artist:
				items = GetSongsOfArtist(json);
				break;
			case EnumMusicType.collect:
				items = GetSongsOfCollect(json);
				break;
			case EnumMusicType.song:
				var song = await GetSong(id);
				if(song != null)
					items.Add(song);
				break;
			case EnumMusicType.any:
				break;
			default:
				break;
		}
		var res = new SearchResult
		{
			Items = items,
			Keyword = id,
			SearchType = EnumSearchType.type,
			Page = 1,
		};
		return res;
	}
    async static Task <SearchResult> _searchByKey(string keyword, int page, EnumMusicType type = EnumMusicType.song)
    {
        dynamic obj = await NetAccess.Json(XiamiUrl.url_search_all, "key", keyword, "page", page.ToString());

        /////////////
        if (obj == null)
        {
            return(null);
        }
        //string typestr = type.ToString();
        //dynamic obj = await XiamiClient.GetDefault().Call_xiami_api(string.Format("Search.{0}s", typestr),
        //    string.Format("\"key={0}\"", keyword),
        //    string.Format("page={0}", page));
        //if (obj == null) return null;
        dynamic data = obj[type.ToString() + "s"];

        if (data == null)
        {
            return(null);
        }
        var items = new List <IMusic>();

        foreach (dynamic x in data)
        {
            items.Add(MusicFactory.CreateFromJson(x, type));
        }
        var searchType = EnumSearchType.song;

        Enum.TryParse <EnumSearchType>(type.ToString(), out searchType);
        bool hasNext = page.ToString() != obj["next"];
        var  res     = new SearchResult
        {
            Items      = items,
            Keyword    = keyword,
            Page       = page,
            HasNext    = hasNext,
            SearchType = searchType,
        };

        return(res);
    }
Exemplo n.º 8
0
 public static IMusic CreateFromJson(dynamic obj, EnumMusicType type)
 {
     IMusic res = null;
     switch(type)
     {
         case EnumMusicType.album:
             res = new Album();
             break;
         case EnumMusicType.artist:
             res = new Artist();
             break;
         case EnumMusicType.collect:
             res = new Collection();
             break;
         case EnumMusicType.song:
             res = new Song();
             break;
         default:
             break;
     }
     if(res != null)
         res.CreateFromJson(obj);
     return res;
 }
 async static Task<SearchResult> _searchByKey(string keyword, int page, EnumMusicType type = EnumMusicType.song)
 {
     dynamic obj = await NetAccess.Json(XiamiUrl.url_search_all, "key", keyword, "page", page.ToString());
     /////////////
     if (obj == null) return null;
     //string typestr = type.ToString();
     //dynamic obj = await XiamiClient.GetDefault().Call_xiami_api(string.Format("Search.{0}s", typestr),
     //    string.Format("\"key={0}\"", keyword),
     //    string.Format("page={0}", page));
     //if (obj == null) return null;
     dynamic data = obj[type.ToString() + "s"];
     if (data == null) return null;
     var items = new List<IMusic>();
     foreach (dynamic x in data)
     {
         items.Add(MusicFactory.CreateFromJson(x, type));
     }
     var searchType = EnumSearchType.song;
     Enum.TryParse<EnumSearchType>(type.ToString(), out searchType);
     bool hasNext = page.ToString() != obj["next"];
     var res = new SearchResult
     {
         Items = items,
         Keyword = keyword,
         Page = page,
         HasNext = hasNext,
         SearchType = searchType,
     };
     return res;
 }
 static async Task<SearchResult> SearchByKey(string key, EnumMusicType type)
 {
     if (type == EnumMusicType.all)
     {
         return await SearchAll(key);
     }
     int page = 1;
     while (true)
     {
         SearchResult sr = await _searchByKey(key, page, type);
         /////////////////////////////////////////
         if (sr == null || sr.Count == 0 || SearchManager.State == EnumSearchState.Cancelling)
         {
             break;
         }
         Artwork.MessageBus.MessageBus.Instance.Publish(sr);
         SearchManager.notifyState(sr);
         if (!sr.HasNext) break;
         page++;
     }
     return null;
 }
Exemplo n.º 11
0
        public static async Task GetSongOfType(string id, EnumMusicType type)
        {
            if (string.IsNullOrEmpty(id)) return;
			var key=string.Format("http://www.xiami.com/type/{0}/id/{1}",type.ToString(),id);
			await Search(key);
        }
Exemplo n.º 12
0
	async static Task<SearchResult> _search(string keyword, int page, EnumMusicType type = EnumMusicType.song)
	{
		string url = XiamiUrl.UrlSearch(keyword, page, type);
		string json = await NetAccess.DownloadStringAsync(url);
		/////////////
		if(json == null) return null;
		dynamic obj = json.ToDynamicObject();
		if(obj == null) return null;
		var data = obj.data as IList<dynamic>;
		if(data == null) return null;
		var items = new List<IMusic>();
		foreach(dynamic x in data)
		{
			items.Add(MusicFactory.CreateFromJson(x, type));
		}
		var res = new SearchResult
		{
			Items = items,
			Keyword = keyword,
			Page = page,
			SearchType = EnumSearchType.key
		};
		return res;
	}
Exemplo n.º 13
0
    static async Task getUserMusic(string key)
    {
        bool isKeyValidMusicType = new Regex("^(song|album|artist|collect)$").IsMatch(key.Trim());
        var  searchType          = EnumSearchType.song;
        var  musicType           = EnumMusicType.song;

        if (isKeyValidMusicType)
        {
            Enum.TryParse(key, out searchType);
            Enum.TryParse(key, out musicType);
        }
        int page = 1;

        while (true)
        {
            dynamic obj = null;
            if (key == "daily")
            {
                obj = await XiamiClient.GetDefault().Call_xiami_api("Recommend.DailySongs");
            }
            else if (key == "guess")
            {
                if (!isGuessUsed)
                {
                    await Http.Get("http://www.xiami.com/index/feeds", null);

                    isGuessUsed = true;
                }
                musicType  = EnumMusicType.all;
                searchType = EnumSearchType.all;
                var html = await Http.Get(string.Format(XiamiUrl.url_recommend_guess, page), null);

                var doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);
                obj      = new JObject();
                obj.alls = new JArray();
                HtmlNodeCollection nodes = null;
                nodes = doc.DocumentNode.SelectNodes("*[contains(concat(' ', @class, ' '), ' album ')]");
                if (nodes != null)
                {
                    foreach (var x in nodes)
                    {
                        string id, name, artist_id, artist_name;
                        string logo = x.SelectSingleNode(".//img").Attributes["src"].Value;
                        getIdName(x, "/album/", out id, out name);
                        getIdName(x, "/artist/", out artist_id, out artist_name);
                        try
                        {
                            obj.alls.Add(JObject.Parse(string.Format(@"
                            {{
                                Type: 'album',
                                album_id : '{0}',
                                album_name : '{1}',
                                artist_id : '{2}',
                                artist_name : '{3}',
                                logo:'{4}',
                            }}", id, name, artist_id, artist_name, logo)));
                        }
                        catch
                        {
                        }
                    }
                }
                nodes = doc.DocumentNode.SelectNodes("*[contains(concat(' ', @class, ' '), ' collect ')]");
                if (nodes != null)
                {
                    foreach (var x in nodes)
                    {
                        string id, name, artist_id, artist_name;
                        string logo = x.SelectSingleNode(".//img").Attributes["src"].Value;
                        getIdName(x, "/song/showcollect/id/", out id, out name);
                        getIdName(x, "/u/", out artist_id, out artist_name);
                        try
                        {
                            obj.alls.Add(JObject.Parse(string.Format(@"
                    {{
                        Type: 'collect',
                        list_id : '{0}',
                        collect_name : '{1}',
                        user_id : '{2}',
                        user_name : '{3}',
                        logo:'{4}',
                    }}", id, name, artist_id, artist_name, logo)));
                        }
                        catch
                        {
                        }
                    }
                }
            }
            else if (key == "collect_recommend")
            {
                musicType  = EnumMusicType.collect;
                searchType = EnumSearchType.collect;
                obj        = await XiamiClient.GetDefault().Call_xiami_api("Collects.recommend");
            }
            else if (isKeyValidMusicType)
            {
                obj = await NetAccess.Json(XiamiUrl.url_lib_music, "music", key, "uid", Global.AppSettings["xiami_uid"], "page", page.ToString());
            }
            else
            {
                Logger.Error(new Exception("user:"******" is not supported"));
                break;
            }
            if (obj == null)
            {
                break;
            }
            var items = new List <IMusic>();
            if (obj[musicType.ToString() + "s"] != null)
            {
                obj = obj[musicType.ToString() + "s"] as dynamic;
            }
            foreach (dynamic item in obj)
            {
                try
                {
                    EnumMusicType t = musicType;
                    if (item["Type"] != null)
                    {
                        Enum.TryParse(item["Type"].ToString(), out t);
                    }
                    items.Add(MusicFactory.CreateFromJson(item, t));
                }
                catch (Exception e)
                {
                }
            }
            var sr = new SearchResult {
                Keyword = "user:"******"song")
            {
                foreach (Song item in sr.Items)
                {
                    item.InFav = true;
                }
            }
            SearchManager.notifyState(sr);
            //if (obj.more != null && obj.more != "true")
            //    break;
            page++;
        }
    }