|
|
|
@ -24,7 +24,8 @@ export interface RunnableScanner<T> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface MediaIds {
|
|
|
|
|
tmdbId: number;
|
|
|
|
|
tmdbId?: number;
|
|
|
|
|
mbId?: string;
|
|
|
|
|
imdbId?: string;
|
|
|
|
|
tvdbId?: number;
|
|
|
|
|
isHama?: boolean;
|
|
|
|
@ -79,13 +80,19 @@ class BaseScanner<T> {
|
|
|
|
|
this.updateRate = updateRate ?? UPDATE_RATE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async getExisting(tmdbId: number, mediaType: MediaType) {
|
|
|
|
|
private async getExisting(id: number | string, mediaType: MediaType) {
|
|
|
|
|
const mediaRepository = getRepository(Media);
|
|
|
|
|
|
|
|
|
|
const existing = await mediaRepository.findOne({
|
|
|
|
|
where: { tmdbId: tmdbId, mediaType },
|
|
|
|
|
let existing: Media | null;
|
|
|
|
|
if (mediaType === MediaType.MOVIE || mediaType === MediaType.TV) {
|
|
|
|
|
existing = await mediaRepository.findOne({
|
|
|
|
|
where: { tmdbId: id as number, mediaType },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
existing = await mediaRepository.findOne({
|
|
|
|
|
where: { mbId: id as string, mediaType },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return existing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -110,8 +117,8 @@ class BaseScanner<T> {
|
|
|
|
|
if (existing) {
|
|
|
|
|
let changedExisting = false;
|
|
|
|
|
|
|
|
|
|
if (existing[is4k ? 'status4k' : 'status'] !== MediaStatus.AVAILABLE) {
|
|
|
|
|
existing[is4k ? 'status4k' : 'status'] = processing
|
|
|
|
|
if (existing['status'] !== MediaStatus.AVAILABLE) {
|
|
|
|
|
existing['status'] = processing
|
|
|
|
|
? MediaStatus.PROCESSING
|
|
|
|
|
: MediaStatus.AVAILABLE;
|
|
|
|
|
if (mediaAddedAt) {
|
|
|
|
@ -125,29 +132,21 @@ class BaseScanner<T> {
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
ratingKey &&
|
|
|
|
|
existing[is4k ? 'ratingKey4k' : 'ratingKey'] !== ratingKey
|
|
|
|
|
) {
|
|
|
|
|
existing[is4k ? 'ratingKey4k' : 'ratingKey'] = ratingKey;
|
|
|
|
|
if (ratingKey && existing['ratingKey'] !== ratingKey) {
|
|
|
|
|
existing['ratingKey'] = ratingKey;
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
serviceId !== undefined &&
|
|
|
|
|
existing[is4k ? 'serviceId4k' : 'serviceId'] !== serviceId
|
|
|
|
|
) {
|
|
|
|
|
existing[is4k ? 'serviceId4k' : 'serviceId'] = serviceId;
|
|
|
|
|
if (serviceId !== undefined && existing['serviceId'] !== serviceId) {
|
|
|
|
|
existing['serviceId'] = serviceId;
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
externalServiceId !== undefined &&
|
|
|
|
|
existing[is4k ? 'externalServiceId4k' : 'externalServiceId'] !==
|
|
|
|
|
externalServiceId
|
|
|
|
|
existing['externalServiceId'] !== externalServiceId
|
|
|
|
|
) {
|
|
|
|
|
existing[is4k ? 'externalServiceId4k' : 'externalServiceId'] =
|
|
|
|
|
externalServiceId;
|
|
|
|
|
existing['externalServiceId'] = externalServiceId;
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -384,12 +383,11 @@ class BaseScanner<T> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (serviceId !== undefined) {
|
|
|
|
|
media[is4k ? 'serviceId4k' : 'serviceId'] = serviceId;
|
|
|
|
|
media['serviceId'] = serviceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (externalServiceId !== undefined) {
|
|
|
|
|
media[is4k ? 'externalServiceId4k' : 'externalServiceId'] =
|
|
|
|
|
externalServiceId;
|
|
|
|
|
media['externalServiceId'] = externalServiceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (externalServiceSlug !== undefined) {
|
|
|
|
@ -505,6 +503,93 @@ class BaseScanner<T> {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async processArtist(
|
|
|
|
|
mbId: string,
|
|
|
|
|
{
|
|
|
|
|
mediaAddedAt,
|
|
|
|
|
ratingKey,
|
|
|
|
|
serviceId,
|
|
|
|
|
externalServiceId,
|
|
|
|
|
processing = false,
|
|
|
|
|
title = 'Unknown Title',
|
|
|
|
|
}: ProcessOptions = {}
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
const mediaRepository = getRepository(Media);
|
|
|
|
|
|
|
|
|
|
await this.asyncLock.dispatch(mbId, async () => {
|
|
|
|
|
const existing = await this.getExisting(mbId, MediaType.MUSIC);
|
|
|
|
|
|
|
|
|
|
if (existing) {
|
|
|
|
|
let changedExisting = false;
|
|
|
|
|
|
|
|
|
|
if (existing['status'] !== MediaStatus.AVAILABLE) {
|
|
|
|
|
existing['status'] = processing
|
|
|
|
|
? MediaStatus.PROCESSING
|
|
|
|
|
: MediaStatus.AVAILABLE;
|
|
|
|
|
if (mediaAddedAt) {
|
|
|
|
|
existing.mediaAddedAt = mediaAddedAt;
|
|
|
|
|
}
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!changedExisting && !existing.mediaAddedAt && mediaAddedAt) {
|
|
|
|
|
existing.mediaAddedAt = mediaAddedAt;
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ratingKey && existing['ratingKey'] !== ratingKey) {
|
|
|
|
|
existing['ratingKey'] = ratingKey;
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (serviceId !== undefined && existing['serviceId'] !== serviceId) {
|
|
|
|
|
existing['serviceId'] = serviceId;
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
externalServiceId !== undefined &&
|
|
|
|
|
existing['externalServiceId'] !== externalServiceId
|
|
|
|
|
) {
|
|
|
|
|
existing['externalServiceId'] = externalServiceId;
|
|
|
|
|
changedExisting = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (changedExisting) {
|
|
|
|
|
await mediaRepository.save(existing);
|
|
|
|
|
this.log(
|
|
|
|
|
`Media for ${title} exists. Changes were detected and the title will be updated.`,
|
|
|
|
|
'info'
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
this.log(`Title already exists and no changes detected for ${title}`);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const newMedia = new Media();
|
|
|
|
|
newMedia.mbId = mbId;
|
|
|
|
|
|
|
|
|
|
newMedia.status = !processing
|
|
|
|
|
? MediaStatus.AVAILABLE
|
|
|
|
|
: processing
|
|
|
|
|
? MediaStatus.PROCESSING
|
|
|
|
|
: MediaStatus.UNKNOWN;
|
|
|
|
|
newMedia.mediaType = MediaType.MUSIC;
|
|
|
|
|
newMedia.serviceId = serviceId;
|
|
|
|
|
newMedia.externalServiceId = externalServiceId;
|
|
|
|
|
|
|
|
|
|
if (mediaAddedAt) {
|
|
|
|
|
newMedia.mediaAddedAt = mediaAddedAt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ratingKey) {
|
|
|
|
|
newMedia.ratingKey = ratingKey;
|
|
|
|
|
}
|
|
|
|
|
await mediaRepository.save(newMedia);
|
|
|
|
|
this.log(`Saved new media: ${title}`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call startRun from child class whenever a run is starting to
|
|
|
|
|
* ensure required values are set
|
|
|
|
|