GetArtistInfo() public method

public GetArtistInfo ( string artistName ) : Task
artistName string
return Task
        private static async Task <bool> DownloadArtistPictureFromLastFm(MusicLibraryViewModel.ArtistItem artist)
        {
            var lastFmClient = new LastFmClient();
            var lastFmArtist = await lastFmClient.GetArtistInfo(artist.Name);

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

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

                InMemoryRandomAccessStream streamWeb = new InMemoryRandomAccessStream();

                DataWriter writer = new DataWriter(streamWeb.GetOutputStreamAt(0));
                writer.WriteBytes(img);

                await writer.StoreAsync();

                StorageFolder artistPic = await ApplicationData.Current.LocalFolder.CreateFolderAsync("artistPic",
                                                                                                      CreationCollisionOption.OpenIfExists);

                string fileName = artist.Name + "_" + "dPi";

                var file = await artistPic.CreateFileAsync(fileName + ".jpg", CreationCollisionOption.OpenIfExists);

                var raStream = await file.OpenAsync(FileAccessMode.ReadWrite);

                using (var thumbnailStream = streamWeb.GetInputStreamAt(0))
                {
                    using (var stream = raStream.GetOutputStreamAt(0))
                    {
                        await RandomAccessStream.CopyAsync(thumbnailStream, stream);
                    }
                }
                StorageFolder appDataFolder           = ApplicationData.Current.LocalFolder;
                string        supposedPictureUriLocal = appDataFolder.Path + "\\artistPic\\" + artist.Name + "_" + "dPi" + ".jpg";
                DispatchHelper.InvokeAsync(() => artist.Picture = supposedPictureUriLocal);
                return(true);
            }
            catch (Exception)
            {
                Debug.WriteLine("Error getting or saving art from LastFm.");
                return(false);
            }
        }
        public static async Task GetArtistBiography(MusicLibraryViewModel.ArtistItem artist)
        {
            string biography = string.Empty;

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

                biography = artistInformation.Biography;
            }
            catch
            {
                Debug.WriteLine("Failed to get artist biography from LastFM. Returning nothing.");
            }
            artist.Biography = System.Net.WebUtility.HtmlDecode(biography);
        }
Exemplo n.º 3
0
        private static async Task<bool> DownloadArtistPictureFromLastFm(MusicLibraryViewModel.ArtistItem artist)
        {
            var lastFmClient = new LastFmClient();
            var lastFmArtist = await lastFmClient.GetArtistInfo(artist.Name);
            if (lastFmArtist == null) return false;
            try
            {
                var clientPic = new HttpClient();
                var imageElement = lastFmArtist.Images.LastOrDefault(node => !string.IsNullOrEmpty(node.Url));
                if (imageElement == null) return false;
                HttpResponseMessage responsePic = await clientPic.GetAsync(imageElement.Url);
                byte[] img = await responsePic.Content.ReadAsByteArrayAsync();
                InMemoryRandomAccessStream streamWeb = new InMemoryRandomAccessStream();

                DataWriter writer = new DataWriter(streamWeb.GetOutputStreamAt(0));
                writer.WriteBytes(img);

                await writer.StoreAsync();

                StorageFolder artistPic = await ApplicationData.Current.LocalFolder.CreateFolderAsync("artistPic",
                    CreationCollisionOption.OpenIfExists);
                string fileName = artist.Name + "_" + "dPi";

                var file = await artistPic.CreateFileAsync(fileName + ".jpg", CreationCollisionOption.OpenIfExists);
                var raStream = await file.OpenAsync(FileAccessMode.ReadWrite);

                using (var thumbnailStream = streamWeb.GetInputStreamAt(0))
                {
                    using (var stream = raStream.GetOutputStreamAt(0))
                    {
                        await RandomAccessStream.CopyAsync(thumbnailStream, stream);
                    }
                }
                StorageFolder appDataFolder = ApplicationData.Current.LocalFolder;
                string supposedPictureUriLocal = appDataFolder.Path + "\\artistPic\\" + artist.Name + "_" + "dPi" + ".jpg";
                DispatchHelper.InvokeAsync(() => artist.Picture = supposedPictureUriLocal);
                return true;
            }
            catch (Exception)
            {
                Debug.WriteLine("Error getting or saving art from LastFm.");
                return false;
            }
        }
Exemplo n.º 4
0
 public static async Task GetArtistBiography(MusicLibraryViewModel.ArtistItem artist)
 {
     string biography = string.Empty;
     try
     {
         var lastFmClient = new LastFmClient();
         var artistInformation = await lastFmClient.GetArtistInfo(artist.Name);
         biography = artistInformation.Biography;
     }
     catch
     {
         Debug.WriteLine("Failed to get artist biography from LastFM. Returning nothing.");
     }
     artist.Biography = System.Net.WebUtility.HtmlDecode(biography);
 }