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