Exemplo n.º 1
0
        public static async Task <NcmAlbum[]> SearchAlbumAsync(Album album, int limit, bool withArtists)
        {
            List <string> keywords;
            JToken        json;

            keywords = new List <string>();
            if (album.Name.Length != 0)
            {
                keywords.Add(album.Name);
            }
            if (withArtists)
            {
                keywords.AddRange(album.Artists);
            }
            if (keywords.Count == 0)
            {
                throw new ArgumentException("专辑信息无效");
            }
            for (int i = 0; i < keywords.Count; i++)
            {
                keywords[i] = keywords[i].WholeWordReplace();
            }
            json = await NcmApi.SearchAsync(keywords, NcmApi.SearchType.Album, limit);

            if ((int)json["albumCount"] == 0)
            {
                return(Array.Empty <NcmAlbum>());
            }
            return(((JArray)json["albums"]).Select(t => ParseAlbum(t)).ToArray());
        }
Exemplo n.º 2
0
        public static async Task <NcmTrack[]> SearchTrackAsync(Track track, int limit, bool withArtists)
        {
            List <string> keywords;
            JToken        json;

            keywords = new List <string>();
            if (track.Name.Length != 0)
            {
                keywords.Add(track.Name);
            }
            if (withArtists)
            {
                keywords.AddRange(track.Artists);
            }
            if (keywords.Count == 0)
            {
                throw new ArgumentException("歌曲信息无效");
            }
            for (int i = 0; i < keywords.Count; i++)
            {
                keywords[i] = keywords[i].WholeWordReplace();
            }
            json = await NcmApi.SearchAsync(keywords, NcmApi.SearchType.Track, limit);

            if ((int)json["songCount"] == 0)
            {
                return(Array.Empty <NcmTrack>());
            }
            return(((JArray)json["songs"]).Select(t => ParseTrack(t, false)).ToArray());
        }