|
|
|
@ -30,6 +30,8 @@ class AvailabilitySync {
|
|
|
|
|
this.sonarrSeasonsCache = {};
|
|
|
|
|
this.radarrServers = settings.radarr.filter((server) => server.syncEnabled);
|
|
|
|
|
this.sonarrServers = settings.sonarr.filter((server) => server.syncEnabled);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await this.initPlexClient();
|
|
|
|
|
|
|
|
|
|
if (!this.plexClient) {
|
|
|
|
@ -46,7 +48,6 @@ class AvailabilitySync {
|
|
|
|
|
|
|
|
|
|
const pageSize = 50;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for await (const media of this.loadAvailableMediaPaginated(pageSize)) {
|
|
|
|
|
if (!this.running) {
|
|
|
|
|
throw new Error('Job aborted');
|
|
|
|
@ -239,6 +240,7 @@ class AvailabilitySync {
|
|
|
|
|
|
|
|
|
|
const isTVType = media.mediaType === 'tv';
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const request = await requestRepository.findOne({
|
|
|
|
|
relations: {
|
|
|
|
|
media: true,
|
|
|
|
@ -247,7 +249,9 @@ class AvailabilitySync {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
|
`Media ID ${media.id} does not exist in your ${is4k ? '4k' : 'non-4k'} ${
|
|
|
|
|
`Media ID ${media.id} does not exist in your ${
|
|
|
|
|
is4k ? '4k' : 'non-4k'
|
|
|
|
|
} ${
|
|
|
|
|
isTVType ? 'Sonarr' : 'Radarr'
|
|
|
|
|
} and Plex instance. Status will be changed to unknown.`,
|
|
|
|
|
{ label: 'AvailabilitySync' }
|
|
|
|
@ -284,6 +288,12 @@ class AvailabilitySync {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await requestRepository.delete({ id: request?.id });
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
logger.debug(`Failure updating media ID ${media.id}`, {
|
|
|
|
|
errorMessage: ex.message,
|
|
|
|
|
label: 'AvailabilitySync',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async mediaExistsInRadarr(
|
|
|
|
@ -539,6 +549,7 @@ class AvailabilitySync {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const seasonToBeDeleted = await seasonRequestRepository.findOne({
|
|
|
|
|
relations: {
|
|
|
|
|
request: {
|
|
|
|
@ -617,6 +628,12 @@ class AvailabilitySync {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
logger.debug(`Failure updating media ID ${media.id}`, {
|
|
|
|
|
errorMessage: ex.message,
|
|
|
|
|
label: 'AvailabilitySync',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
seasonExistsInSonarr ||
|
|
|
|
@ -654,7 +671,10 @@ class AvailabilitySync {
|
|
|
|
|
}
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
if (!ex.message.includes('response code: 404')) {
|
|
|
|
|
throw ex;
|
|
|
|
|
logger.debug(`Failed to retrieve plex metadata`, {
|
|
|
|
|
errorMessage: ex.message,
|
|
|
|
|
label: 'AvailabilitySync',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Base case if both media versions exist in plex
|
|
|
|
@ -714,6 +734,7 @@ class AvailabilitySync {
|
|
|
|
|
let seasonExistsInPlex = false;
|
|
|
|
|
let seasonExistsInPlex4k = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (ratingKey) {
|
|
|
|
|
const children =
|
|
|
|
|
this.plexSeasonsCache[ratingKey] ??
|
|
|
|
@ -728,7 +749,6 @@ class AvailabilitySync {
|
|
|
|
|
seasonExistsInPlex = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ratingKey4k) {
|
|
|
|
|
const children4k =
|
|
|
|
|
this.plexSeasonsCache[ratingKey4k] ??
|
|
|
|
@ -743,7 +763,14 @@ class AvailabilitySync {
|
|
|
|
|
seasonExistsInPlex4k = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
if (!ex.message.includes('response code: 404')) {
|
|
|
|
|
logger.debug(`Failed to retrieve plex's children metadata`, {
|
|
|
|
|
errorMessage: ex.message,
|
|
|
|
|
label: 'AvailabilitySync',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Base case if both season versions exist in plex
|
|
|
|
|
if (seasonExistsInPlex && seasonExistsInPlex4k) {
|
|
|
|
|
return true;
|
|
|
|
|