private async Task FillSimilarArtistsAsync() { if (this.lfmArtist != null && this.lfmArtist.SimilarArtists != null && this.lfmArtist.SimilarArtists.Count > 0) { await Task.Run(async() => { var localSimilarArtists = new ObservableCollection <SimilarArtistViewModel>(); foreach (Artist similarArtist in this.lfmArtist.SimilarArtists) { string artistImageUrl = string.Empty; try { // Last.fm was so nice to break their artist image API. So we need to get images from elsewhere. Artist lfmArtist = await LastfmApi.ArtistGetInfo(similarArtist.Name, true, ResourceUtils.GetString("Language_ISO639-1")); artistImageUrl = await FanartApi.GetArtistThumbnailAsync(lfmArtist.MusicBrainzId); } catch (Exception ex) { LogClient.Warning($"Could not get artist image from Fanart for artist {similarArtist.Name}. Exception: {ex}"); } localSimilarArtists.Add(new SimilarArtistViewModel { Name = similarArtist.Name, Url = similarArtist.Url, ImageUrl = artistImageUrl }); } this.SimilarArtists = localSimilarArtists; }); } RaisePropertyChanged(nameof(this.SimilarArtists)); RaisePropertyChanged(nameof(this.HasSimilarArtists)); }
private async Task ShowArtistInfoAsync(TrackViewModel track, bool forceReload) { this.previousArtistName = this.artistName; // User doesn't want to download artist info, or no track is selected. if (!SettingsClient.Get <bool>("Lastfm", "DownloadArtistInformation") || track == null) { this.ArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>(); this.artistName = string.Empty; return; } // Artist name is unknown if (string.IsNullOrEmpty(track.ArtistName)) { ArtistInfoViewModel localArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>(); await localArtistInfoViewModel.SetArtistInformation(new LastFmArtist { Name = string.Empty }, string.Empty); this.ArtistInfoViewModel = localArtistInfoViewModel; this.artistName = string.Empty; return; } this.artistName = track.ArtistName; // The artist didn't change: leave the previous artist info. if (this.artistName.Equals(this.previousArtistName) & !forceReload) { return; } // The artist changed: we need to show new artist info. string artworkPath = string.Empty; this.IsBusy = true; try { LastFmArtist lfmArtist = await LastfmApi.ArtistGetInfo(track.ArtistName, true, ResourceUtils.GetString("Language_ISO639-1")); if (lfmArtist != null) { if (string.IsNullOrEmpty(lfmArtist.Biography.Content)) { // In case there is no localized Biography, get the English one. lfmArtist = await LastfmApi.ArtistGetInfo(track.ArtistName, true, "EN"); } if (lfmArtist != null) { string artistImageUrl = string.Empty; try { // Last.fm was so nice to break their artist image API. So we need to get images from elsewhere. artistImageUrl = await FanartApi.GetArtistThumbnailAsync(lfmArtist.MusicBrainzId); } catch (Exception ex) { LogClient.Warning($"Could not get artist image from Fanart for artist {track.ArtistName}. Exception: {ex}"); } ArtistInfoViewModel localArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>(); await localArtistInfoViewModel.SetArtistInformation(lfmArtist, artistImageUrl); this.ArtistInfoViewModel = localArtistInfoViewModel; } else { throw new Exception("lfmArtist == null"); } } } catch (Exception ex) { LogClient.Error("Could not show artist information for Track {0}. Exception: {1}", track.Path, ex.Message); this.ArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>(); this.artistName = string.Empty; } this.IsBusy = false; }