diff --git a/packages/core/src/plugins/meta/discogs.ts b/packages/core/src/plugins/meta/discogs.ts index 3e6d8eb095..252368223c 100644 --- a/packages/core/src/plugins/meta/discogs.ts +++ b/packages/core/src/plugins/meta/discogs.ts @@ -44,7 +44,7 @@ class DiscogsMetaProvider extends MetaProvider { getCoverImage(entity: DiscogsReleaseInfo | DiscogsArtistInfo) { return _.get( - _.find(entity.images, { type: 'primary' }), + _.find(entity.images, { type: 'primary' }), 'resource_url', _.get(_.find(entity.images, { type: 'secondary' }), 'resource_url') ); @@ -64,7 +64,7 @@ class DiscogsMetaProvider extends MetaProvider { source: SearchResultsSource.Discogs }; } - + discogsArtistReleaseSearchResultToGeneric(release: DiscogsArtistReleaseSearchResult): SearchResultsAlbum { return { id: `${release.id}`, @@ -85,9 +85,9 @@ class DiscogsMetaProvider extends MetaProvider { release.tracklist.forEach(track => { if (track.sub_tracks) { - track.sub_tracks.forEach(subTrack => tracklist.push(this.discogsTrackToGeneric(subTrack))); + track.sub_tracks.forEach(subTrack => tracklist.push(this.discogsTrackToGeneric(subTrack, artist))); } else { - tracklist.push(this.discogsTrackToGeneric(track)); + tracklist.push(this.discogsTrackToGeneric(track, artist)); } }); @@ -106,13 +106,13 @@ class DiscogsMetaProvider extends MetaProvider { }; } - discogsTrackToGeneric(discogsTrack: DiscogsTrack): Track { + discogsTrackToGeneric(discogsTrack: DiscogsTrack, albumArtist: string): Track { const track = new Track(); - track.artists = discogsTrack.artists.map(artist => artist.name); + track.artists = discogsTrack.artists?.map(artist => artist.name) ?? [albumArtist]; track.title = discogsTrack.title; track.duration = discogsTrack.duration; track.position = discogsTrack.position; - discogsTrack.extraartists?.forEach(artist => track.artists.push(artist.name)); + track.artists = track.artists.concat(_.map(discogsTrack.extraartists, 'name')); track.type = discogsTrack.type_; return track; } @@ -157,15 +157,15 @@ class DiscogsMetaProvider extends MetaProvider { (item.type === 'artist') ? [this.discogsArtistSearchResultToGeneric(item)] : [] ); - + const releases = json.results.flatMap(item => (item.type === 'master' || item.type === 'release' ) ? [this.discogsReleaseSearchResultToGeneric(item)] : [] ); - + return Promise.resolve({ artists, releases, tracks: [] }); } - + return Promise.resolve({ artists: [], releases: [], tracks: [] }); }); } @@ -225,7 +225,7 @@ class DiscogsMetaProvider extends MetaProvider { albumType, { resource_url: resourceUrl } )).json(); - + return Promise.resolve( this.discogsReleaseInfoToGeneric( albumData, diff --git a/packages/core/src/rest/Discogs.types.ts b/packages/core/src/rest/Discogs.types.ts index c07ecefa5e..04276e5224 100644 --- a/packages/core/src/rest/Discogs.types.ts +++ b/packages/core/src/rest/Discogs.types.ts @@ -104,7 +104,7 @@ export type DiscogsTrack = { duration: string; position: string; title: string; - artists: { + artists?: { name: string; id: number; }[];