Handle album artists

This commit is contained in:
FoxxMD
2025-12-04 02:54:34 +00:00
parent 1410e3a952
commit 14c8730435
2 changed files with 25 additions and 8 deletions
@@ -330,7 +330,17 @@ export default class MusicbrainzTransformer extends AtomicPartsTransformer<Exter
return transformData.data.artists;
}
protected async handleAlbumArtists(play: PlayObject, parts: ExternalMetadataTerm, transformData: PlayObject): Promise<string[] | undefined> {
// TODO
if (parts === false) {
return play.data.artists;
}
if (typeof parts === 'object') {
if (parts.when !== undefined) {
if (!testWhenConditions(parts.when, play, { testMaybeRegex: this.regex.testMaybeRegex })) {
this.logger.debug('When condition for albumArtists not met, returning original artists');
return play.data.artists;
}
}
}
return play.data.albumArtists;
}
protected async handleAlbum(play: PlayObject, parts: ExternalMetadataTerm, transformData: PlayObject): Promise<string | undefined> {
@@ -127,24 +127,31 @@ export class MusicbrainzApiClient extends AbstractApiClient {
export const recordingToPlay = (data: IRecording): PlayObject => {
let album: IRelease;
// try to find official album first
album = data.releases.find(x => x.status === 'Official');
if(album === undefined) {
// find the first album that isn't "bad"
album = data.releases.find(x => !['Expunged','Withdrawn'].includes(x.status));
let albumArtists: string[];
const artists = (data["artist-credit"] ?? []).map(x => x.name);
if(data.releases !== undefined && data.releases.length > 0) {
album = data.releases[0];
const aa = album["artist-credit"].map(x => x.name);
// if not every artist of the recording is also on the album
// then use release album artists
if(!artists.every(x => aa.includes(x))) {
albumArtists = aa;
}
}
const play: PlayObject = {
data: {
// TODO figure out album artists
track: data.title,
artists: (data["artist-credit"] ?? []).map(x => x.name),
artists,
album: album !== undefined ? album.title : undefined,
albumArtists,
meta: {
brainz: {
track: data.id,
artist: data["artist-credit"].map(x => x.artist.id),
album: album !== undefined ? album.id : undefined,
releaseGroup: album !== undefined ? album["release-group"]?.id : undefined
}
}
},