Example #1
0
        private async Task <byte[]> DownloadArtistPictureFromLastFm(string artistName)
        {
            var lastFmClient = new LastFmClient();
            var lastFmArtist = await lastFmClient.GetArtistInfo(artistName);

            if (lastFmArtist == null)
            {
                return(null);
            }
            try
            {
                var clientPic    = new HttpClient();
                var imageElement = lastFmArtist.Images.LastOrDefault(node => !string.IsNullOrEmpty(node.Url));
                if (imageElement == null)
                {
                    return(null);
                }
                HttpResponseMessage responsePic = await clientPic.GetAsync(imageElement.Url);

                byte[] img = await responsePic.Content.ReadAsByteArrayAsync();

                return(img);
            }
            catch (Exception)
            {
                Debug.WriteLine("Error getting or saving art from LastFm.");
                return(null);
            }
        }
Example #2
0
        public async Task <string> GetArtistBiography(string artistName)
        {
            if (string.IsNullOrEmpty(artistName))
            {
                return(null);
            }
            var biography = string.Empty;

            try
            {
                var lastFmClient      = new LastFmClient();
                var artistInformation = await lastFmClient.GetArtistInfo(artistName);

                biography = artistInformation != null ? artistInformation.Biography : String.Empty;
            }
            catch
            {
                Debug.WriteLine("Failed to get artist biography from LastFM. Returning nothing.");
            }
            return(biography);
        }
Example #3
0
        private async Task <byte[]> DownloadArtistPictureFromLastFm(string artistName)
        {
            var lastFmClient = new LastFmClient();
            var lastFmArtist = await lastFmClient.GetArtistInfo(artistName);

            if (lastFmArtist == null)
            {
                return(null);
            }
            try
            {
                var clientPic    = new HttpClient();
                var nonEmptyImgs = lastFmArtist.Images.Where(node => !string.IsNullOrEmpty(node.Url)).ToList();
                var index        = nonEmptyImgs.Count - 1;
                if (nonEmptyImgs.Count == 6)
                {
                    index -= 1;
                }
                if (index == -1)
                {
                    return(null);
                }
                var imageElement = nonEmptyImgs.ElementAt(index);
                if (imageElement == null)
                {
                    return(null);
                }
                HttpResponseMessage responsePic = await clientPic.GetAsync(imageElement.Url);

                byte[] img = await responsePic.Content.ReadAsByteArrayAsync();

                return(img);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error getting or saving art from LastFm.");
                return(null);
            }
        }