Esempio n. 1
0
        public async Task <List <DataRow> > GetArtists(CancellationToken token)
        {
            List <DataRow> data = new List <DataRow>();

            data.Add(new HeaderDataRow("Artists", null));

            var request  = new RestRequest("library/artist", HttpMethod.Get);
            var response = await DoRestRequest(request, 100000, token);

            var jroot = JToken.Parse(response.Body);

            token.ThrowIfCancellationRequested();
            if (!jroot.IsNullOrEmpty() && !jroot["data"].IsNullOrEmpty() && !jroot["data"]["artists"].IsNullOrEmpty())
            {
                var jartists = (JArray)jroot["data"]["artists"];
                foreach (var jartist in jartists)
                {
                    var dataRow = ArtistDataRow.Parse((JObject)jartist);
                    data.Add(dataRow);
                    token.ThrowIfCancellationRequested();
                }
            }

            return(data);
        }
Esempio n. 2
0
        public async Task <List <ArtistDataRow> > SearchArtists(string songName, string albumName, string artistName, CancellationToken token)
        {
            List <ArtistDataRow> data = new List <ArtistDataRow>();

            List <KeyValuePair <string, string> > searchParams = new List <KeyValuePair <string, string> >();

            if (!string.IsNullOrEmpty(songName))
            {
                searchParams.Add(new KeyValuePair <string, string>("song", songName));
            }
            if (!string.IsNullOrEmpty(albumName))
            {
                searchParams.Add(new KeyValuePair <string, string>("album", albumName));
            }
            if (!string.IsNullOrEmpty(artistName))
            {
                searchParams.Add(new KeyValuePair <string, string>("artist", artistName));
            }

            searchParams.Add(new KeyValuePair <string, string>("list", "artists"));

            var request  = new RestRequest($"library/search2", HttpMethod.Get, null, searchParams.ToArray());
            var response = await DoRestRequest(request, 100000, token);

            var jroot = JToken.Parse(response.Body);

            token.ThrowIfCancellationRequested();
            if (!jroot.IsNullOrEmpty() && !jroot["data"].IsNullOrEmpty() && !jroot["data"]["artists"].IsNullOrEmpty())
            {
                foreach (JObject artistObject in jroot["data"]["artists"])
                {
                    var dataRow = ArtistDataRow.Parse(artistObject);
                    data.Add(dataRow);
                }
            }

            return(data);
        }