public async Task <RestResponse <CaAlbum> > GetOneAsync(MbId mbId, CancellationToken cancellationToken = default) { string baseUri = "http://coverartarchive.org/release-group"; string requestUri = $"{baseUri}/{mbId.Value}"; return(await GetAsync <CaAlbum>(new Uri(requestUri), cancellationToken)); }
protected async Task <RestResponse <TModel> > GetOneAsync <TModel>(MbId mbId, CancellationToken cancellationToken = default) where TModel : MbModel, new() { string baseUri = $"https://musicbrainz.org/ws/2/{ModelToEndpoint<TModel>()}/{mbId.Value}"; string requestUri = $"{baseUri}?fmt=json&inc={string.Join("+", new TModel().Includes())}"; return(await GetAsync <TModel>(new Uri(requestUri), cancellationToken)); }
public async Task <ArtistSummary> GetOneAsync(MbId mbId, CancellationToken cancellationToken = default) { var mbArtistResponse = await _mbArtistRestClient.GetOneAsync(mbId, cancellationToken); mbArtistResponse.EnsureSuccessStatusCode(); var caAlbumTasks = mbArtistResponse.Content.ReleaseGroups .Select(releaseGroup => _caAlbumRestClient.GetOneAsync(new MbId(releaseGroup.Id))) .ToArray(); var wdEntitiesHolderResponse = await GetOneWdEntitiesHolderAsync(mbArtistResponse.Content, cancellationToken); var wpQueryHolderResponse = await GetOneWpQueryHolderAsync(wdEntitiesHolderResponse?.Content, cancellationToken); Task.WaitAll(caAlbumTasks, cancellationToken); var mbReleaseGroupIds = mbArtistResponse.Content.ReleaseGroups .Select(releaseGroup => releaseGroup.Id); var caImagesUris = caAlbumTasks .Select(caAlbumTask => caAlbumTask.Result) .Select(caAlbumResponse => caAlbumResponse.Content) .Select(caAlbum => caAlbum?.FrontCover?.Image); // Zip ReleaseGroup Ids with the Cover Art Image Uris // Image requests which resulted in any error are null here, which is fine var mbReleaseGroupIdsToCaImageUris = mbReleaseGroupIds .Zip(caImagesUris, (k, v) => new { k, v }) .ToDictionary(x => x.k, x => x.v); return(new ArtistSummary { Id = mbArtistResponse.Content.Id, Name = mbArtistResponse.Content.Name, Extract = wpQueryHolderResponse?.Content?.Query?.Pages.FirstOrDefault().Value?.Extract, Albums = mbArtistResponse.Content.ReleaseGroups .Select(releaseGroup => new AlbumSummary { Id = releaseGroup.Id, Name = releaseGroup.Title, Released = releaseGroup.FirstReleaseDate, CoverArtUri = mbReleaseGroupIdsToCaImageUris.GetValueOrDefault(releaseGroup.Id) }) .OrderBy(albumSummary => albumSummary.Released) .ThenBy(albumSummary => albumSummary.Name) }); }
public async Task <RestResponse <MbArtist> > GetOneAsync(MbId mbId, CancellationToken cancellationToken = default) { return(await GetOneAsync <MbArtist>(mbId, cancellationToken)); }