From 136d874cba37babf9c0670844b002871710e6d99 Mon Sep 17 00:00:00 2001 From: sct Date: Sat, 30 Jan 2021 05:26:24 +0000 Subject: [PATCH] fix(sync): do not update series status if already available and no new seasons fixes #777 --- server/job/plexsync/index.ts | 30 ++++++++++++++++++++++-------- server/job/sonarrsync/index.ts | 22 +++++++++++++++++----- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/server/job/plexsync/index.ts b/server/job/plexsync/index.ts index 4fec09c69..cab4f5ef9 100644 --- a/server/job/plexsync/index.ts +++ b/server/job/plexsync/index.ts @@ -626,15 +626,29 @@ class JobPlexSync { media.mediaAddedAt = new Date(plexitem.addedAt * 1000); } - media.status = isAllStandardSeasons - ? MediaStatus.AVAILABLE - : media.seasons.some( - (season) => season.status !== MediaStatus.UNKNOWN - ) - ? MediaStatus.PARTIALLY_AVAILABLE - : MediaStatus.UNKNOWN; + // If the show is already available, and there are no new seasons, dont adjust + // the status + const shouldStayAvailable = + media.status === MediaStatus.AVAILABLE && + newSeasons.filter( + (season) => season.status !== MediaStatus.UNKNOWN + ).length === 0; + const shouldStayAvailable4k = + media.status4k === MediaStatus.AVAILABLE && + newSeasons.filter( + (season) => season.status4k !== MediaStatus.UNKNOWN + ).length === 0; + + media.status = + isAllStandardSeasons || shouldStayAvailable + ? MediaStatus.AVAILABLE + : media.seasons.some( + (season) => season.status !== MediaStatus.UNKNOWN + ) + ? MediaStatus.PARTIALLY_AVAILABLE + : MediaStatus.UNKNOWN; media.status4k = - isAll4kSeasons && this.enable4kShow + (isAll4kSeasons || shouldStayAvailable4k) && this.enable4kShow ? MediaStatus.AVAILABLE : this.enable4kShow && media.seasons.some( diff --git a/server/job/sonarrsync/index.ts b/server/job/sonarrsync/index.ts index cd498d040..6ef45254c 100644 --- a/server/job/sonarrsync/index.ts +++ b/server/job/sonarrsync/index.ts @@ -229,11 +229,23 @@ class JobSonarrSync { ); } - media[server4k ? 'status4k' : 'status'] = isAllSeasons - ? MediaStatus.AVAILABLE - : media.seasons.some((season) => season.status !== MediaStatus.UNKNOWN) - ? MediaStatus.PARTIALLY_AVAILABLE - : MediaStatus.UNKNOWN; + // If the show is already available, and there are no new seasons, dont adjust + // the status + const shouldStayAvailable = + media.status === MediaStatus.AVAILABLE && + newSeasons.filter( + (season) => + season[server4k ? 'status4k' : 'status'] !== MediaStatus.UNKNOWN + ).length === 0; + + media[server4k ? 'status4k' : 'status'] = + isAllSeasons || shouldStayAvailable + ? MediaStatus.AVAILABLE + : media.seasons.some( + (season) => season.status !== MediaStatus.UNKNOWN + ) + ? MediaStatus.PARTIALLY_AVAILABLE + : MediaStatus.UNKNOWN; await mediaRepository.save(media); } else {