Ejemplo n.º 1
0
        private async Task DownloadArtworkAsync()
        {
            this.IsBusy = true;

            try
            {
                Common.Api.Lastfm.Album lfmAlbum = await LastfmApi.AlbumGetInfo((string)this.Album.AlbumArtist, (string)this.Album.AlbumTitle, false, "EN");

                byte[] artworkData = null;

                if (!string.IsNullOrEmpty(lfmAlbum.LargestImage()))
                {
                    string temporaryFilePath = await this.cacheService.DownloadFileToTemporaryCacheAsync(new Uri(lfmAlbum.LargestImage()));

                    if (!string.IsNullOrEmpty(temporaryFilePath))
                    {
                        this.UpdateArtwork(ImageUtils.Image2ByteArray(temporaryFilePath));
                    }
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("An error occurred while downloading artwork for the album with title='{0}' and artist='{1}'. Exception: {2}", (string)this.Album.AlbumTitle, (string)this.Album.AlbumArtist, ex.Message);
            }

            this.IsBusy = false;
        }
Ejemplo n.º 2
0
        public async Task <string> GetAlbumImageAsync(string albumTitle, IList <string> albumArtists, string trackTitle = "", IList <string> trackArtists = null)
        {
            string        title   = string.Empty;
            List <string> artists = new List <string>();

            // Title
            if (!string.IsNullOrEmpty(albumTitle))
            {
                title = albumTitle;
            }
            else if (!string.IsNullOrEmpty(trackTitle))
            {
                title = trackTitle;
            }

            // Artist
            if (albumArtists != null && albumArtists.Count > 0)
            {
                artists.AddRange(albumArtists.Where(a => !string.IsNullOrEmpty(a)));
            }

            if (trackArtists != null && trackArtists.Count > 0)
            {
                artists.AddRange(trackArtists.Where(a => !string.IsNullOrEmpty(a)));
            }

            if (string.IsNullOrEmpty(title) || artists == null)
            {
                return(null);
            }

            foreach (string artist in artists)
            {
                LastFmAlbum lfmAlbum = await LastfmApi.AlbumGetInfo(artist, title, false, "EN");

                if (!string.IsNullOrEmpty(lfmAlbum.LargestImage()))
                {
                    return(lfmAlbum.LargestImage());
                }
            }

            return(null);
        }