public void MapFrom(ArtistInformation artistInformation) { var artist = artistInformation.Artist; this.Name = artist.Name; this.Url = Url; // I hope this is not stupid code. It broke on Boolean.Parse :(. switch (artist.Ontour) { case "0": this.OnTour = false; break; case "1": this.OnTour = true; break; default: this.OnTour = false; break; } this.Images = new List <Image>(); foreach (var image in artist.Image) { var artistImage = new Image(); artistImage.MapFrom(image); this.Images.Add(artistImage); } this.Playcount = Convert.ToInt64(this.Playcount); this.Listeners = Convert.ToInt64(this.Listeners); string biography; var resourceLoader = new ResourceLoader(); var bioSummary = artist.Bio.Summary; if (bioSummary != null) { // Deleting the html tags biography = Regex.Replace(bioSummary, "<.*?>", string.Empty); // Remove leading new lines. biography = biography.TrimStart('\r', '\n'); // Remove leading and ending white spaces. biography = biography.Trim(); // TODO: Replace string "remove" with something better. It may not work on all artists and in all languages. biography = !string.IsNullOrEmpty(biography) ? biography.Remove(biography.Length - "Read more about on Last.fm".Length - artist.Name.Length - 6) : resourceLoader.GetString("NoBiographyFound"); } else { biography = resourceLoader.GetString("NoBiographyFound"); } this.Biography = biography; }
public async Task <ArtistInformation> GetArtistInformation(string artistId) { var artist = await _musicBrainzApi.GetArtistInformation(artistId); var lidarrSettings = await GetLidarrSettings(); Task <ArtistResult> lidarrArtistTask = null; if (lidarrSettings.Enabled) { lidarrArtistTask = _lidarrApi.GetArtistByForeignId(artistId, lidarrSettings.ApiKey, lidarrSettings.FullUri); } var info = new ArtistInformation { Id = artistId, Name = artist.Name, Country = artist.Country, Region = artist.Area?.Name, Type = artist.Type, StartYear = artist.LifeSpan?.Begin ?? "", EndYear = artist.LifeSpan?.End ?? "", Disambiguation = artist.Disambiguation, ReleaseGroups = new List <ReleaseGroup>(), Members = new List <BandMember>() }; foreach (var g in artist.ReleaseGroups) { var release = new ReleaseGroup { ReleaseType = g.PrimaryType, Id = g.Id, Title = g.Title, ReleaseDate = g.FirstReleaseDate, }; await RunSearchRules(release); info.ReleaseGroups.Add(release); } info.Links = GetLinksForArtist(artist); info.Members = GetBandMembers(artist); if (lidarrArtistTask != null) { try { var artistResult = await lidarrArtistTask; info.Banner = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("banner", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl(); info.Logo = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("logo", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl(); info.Poster = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("poster", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl(); info.FanArt = artistResult.images?.FirstOrDefault(x => x.coverType.Equals("fanart", StringComparison.InvariantCultureIgnoreCase))?.url.ToHttpsUrl(); info.Overview = artistResult.overview; } catch (JsonSerializationException) { // swallow, Lidarr probably doesn't have this artist } } return(info); }