Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more detailed warnings #31

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export default defineConfig(
}).map(([name, entry]) => ({
logLevel: 'debug',
input: entry,
watch: {
include: 'src/**/*.ts',
},
plugins: [
...definePlugins({
esm: true,
Expand Down
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
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
},
"include": [
"src/**/*"
],
"exclude": [
"src/*/dist/*"
]
}
Loading