public void Setup() { _mockLastFmService = new MockLastFmService(new MockLastFmConfigurationProvider()); _mockEchoNestService = new MockEchoNestService(); _subject = new ArtistInfoViewModel { LastFmService = _mockLastFmService, EchoNestService = _mockEchoNestService, }; }
public async Task ShowArtistInfo() { if (ActiveItem == null) { return; } if (State != PlaybackViewModelStateEnum.Details) { _previousState = State; State = PlaybackViewModelStateEnum.Details; } ArtistInfoViewModel.Parameter = ActiveItem.Artist; await ArtistInfoViewModel.Populate(); }
private async Task ShowArtistInfoAsync(PlayableTrack track, bool forceReload) { this.previousArtist = this.artist; // 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.artist = null; return; } // Artist name is unknown if (track.ArtistName == Defaults.UnknownArtistText) { ArtistInfoViewModel localArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>(); await localArtistInfoViewModel.SetLastFmArtistAsync(new Core.Api.Lastfm.Artist { Name = Defaults.UnknownArtistText }); this.ArtistInfoViewModel = localArtistInfoViewModel; this.artist = null; return; } this.artist = new Data.Entities.Artist { ArtistName = track.ArtistName }; // The artist didn't change: leave the previous artist info. if (this.artist.Equals(this.previousArtist) & !forceReload) { return; } // The artist changed: we need to show new artist info. string artworkPath = string.Empty; this.IsBusy = true; try { Core.Api.Lastfm.Artist 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) { ArtistInfoViewModel localArtistInfoViewModel = this.container.Resolve <ArtistInfoViewModel>(); await localArtistInfoViewModel.SetLastFmArtistAsync(lfmArtist); 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.artist = null; } this.IsBusy = false; }
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; }