Skip to content

Commit

Permalink
feat: more detailed warnings
Browse files Browse the repository at this point in the history
adds track number and role to artist find warnings
  • Loading branch information
dvirtz committed Dec 17, 2024
1 parent 33f551d commit 3c2cb85
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
18 changes: 14 additions & 4 deletions src/acum-work-import/acum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ type CreatorBase<Type extends string> = Bean<Type> & {

export type Creator = CreatorBase<'org.acum.site.searchdb.dto.bean.CreatorBean'>;

export enum RoleCode {
Composer = 'C',
Author = 'A',
Arranger = 'AR',
Translator = 'AT',
ComposerAndAuthor = 'CA',
}

export type CreatorFull = CreatorBase<'org.acum.site.searchdb.dto.bean.CreatorFullBean'> & {
number: string;
roleCode: RoleCode;
};

export type Creators = ReadonlyArray<CreatorFull>;
Expand Down Expand Up @@ -44,10 +53,11 @@ type AlbumInfoResponse = Response<{
export type WorkVersion = WorkBean & {
versionNumber: string;
creators: Creators;
authors: ReadonlyArray<Creator>;
composers: ReadonlyArray<Creator>;
arrangers: ReadonlyArray<Creator> | undefined;
translators: ReadonlyArray<Creator> | undefined;
authors?: ReadonlyArray<Creator>;
composers?: ReadonlyArray<Creator>;
arrangers?: ReadonlyArray<Creator>;
translators?: ReadonlyArray<Creator>;
composersAndAuthors?: ReadonlyArray<Creator>;
versionIswcNumber: string;
versionEssenceType: string;
albumTrackNumber: string;
Expand Down
20 changes: 17 additions & 3 deletions src/acum-work-import/artists.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {filter, from, lastValueFrom, mergeMap, tap} from 'rxjs';
import {tryFetchJSON} from 'src/common/musicbrainz/fetch';
import {Creator, CreatorFull, Creators, IPBaseNumber} from './acum';
import {Creator, CreatorFull, Creators, IPBaseNumber, RoleCode} from './acum';
import {AddWarning} from './ui/warnings';

function nameMatch(creator: CreatorFull, artist: ArtistSearchResultsT['artists'][number]): boolean {
Expand All @@ -17,6 +17,20 @@ async function findArtist(
): Promise<ArtistT | null> {
const artistMBID = await (async () => {
const creator = creators.find(creator => creator.creatorIpBaseNumber === ipBaseNumber)!;
const role = (() => {
switch (creator.roleCode) {
case RoleCode.Composer:
return 'composer';
case RoleCode.Author:
return 'lyricist';
case RoleCode.Arranger:
return 'arranger';
case RoleCode.Translator:
return 'translator';
case RoleCode.ComposerAndAuthor:
return 'composer and lyricist';
}
})();
const byIpi = await tryFetchJSON<ArtistSearchResultsT>(`/ws/2/artist?query=ipi:${creator.number}&limit=1&fmt=json`);
if (byIpi && byIpi.artists.length > 0) {
return byIpi.artists[0].id;
Expand All @@ -26,11 +40,11 @@ async function findArtist(
`/ws/2/artist?query=name:(${creator.creatorHebName} OR ${creator.creatorEngName})&limit=1&fmt=json`
);
if (byName && byName.artists.length > 0 && nameMatch(creator, byName.artists[0])) {
addWarning(`artist ${byName.artists[0].name} found by name search, please verify (IPI = ${creator.number})`);
addWarning(`${role} ${byName.artists[0].name} found by name search, please verify (IPI = ${creator.number})`);
return byName.artists[0].id;
}

addWarning(`failed to find ${creator.creatorHebName || creator.creatorEngName}, IPI ${creator.number}`);
addWarning(`failed to find ${role} ${creator.creatorHebName || creator.creatorEngName}, IPI ${creator.number}`);
return null;
})();

Expand Down
17 changes: 10 additions & 7 deletions src/acum-work-import/import-album.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export async function importAlbum(
work: WorkT,
writers: ReadonlyArray<Creator> | undefined,
creators: Creators,
linkTypeId: number
linkTypeId: number,
addWarning: AddWarning
) => {
await linkArtists(
artistCache,
Expand All @@ -63,7 +64,8 @@ export async function importAlbum(
const linkArrangers = async (
recording: RecordingT,
arrangers: ReadonlyArray<Creator> | undefined,
creators: Creators
creators: Creators,
addWarning: AddWarning
) => {
await linkArtists(
artistCache,
Expand Down Expand Up @@ -96,10 +98,11 @@ export async function importAlbum(
WorkStateWithEditDataT,
]): Promise<WorkStateWithEditDataT> => {
const work = workState.work;
await linkWriters(work, track.authors, track.creators, LYRICIST_LINK_TYPE_ID);
await linkWriters(work, track.composers, track.creators, COMPOSER_LINK_TYPE_ID);
await linkWriters(work, track.translators, track.creators, TRANSLATOR_LINK_TYPE_ID);
await linkArrangers(recording, track.arrangers, track.creators);
const addWarning = addTrackWarning(track);
await linkWriters(work, track.authors, track.creators, LYRICIST_LINK_TYPE_ID, addWarning);
await linkWriters(work, track.composers, track.creators, COMPOSER_LINK_TYPE_ID, addWarning);
await linkWriters(work, track.translators, track.creators, TRANSLATOR_LINK_TYPE_ID, addWarning);
await linkArrangers(recording, track.arrangers, track.creators, addWarning);
return workState;
};

Expand Down Expand Up @@ -128,7 +131,7 @@ export async function importAlbum(
tap(([track, recordingState, addWarning]) => {
const recording = recordingState.recording;
if (track[searchName(recording.name)] != recording.name) {
addWarning(`Work name of ${recording.name} is different than recording name, please verify`);
addWarning(`Work name of ${recording.name} is different from recording name, please verify`);
}
}),
mergeMap(
Expand Down

0 comments on commit 3c2cb85

Please sign in to comment.