From c40d59573ab6d30d38b8b330406491c84c6e7d24 Mon Sep 17 00:00:00 2001 From: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Date: Fri, 23 Feb 2024 07:30:56 +0500 Subject: [PATCH] fix: season mapping for plex Fixes a bug introduced with this PR where media availability sync job removed the seasons from all series even when those seasons existed --- server/lib/availabilitySync.ts | 65 ++++++++++++++-------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/server/lib/availabilitySync.ts b/server/lib/availabilitySync.ts index 8adf21889..5bdbf593e 100644 --- a/server/lib/availabilitySync.ts +++ b/server/lib/availabilitySync.ts @@ -299,45 +299,42 @@ class AvailabilitySync { const finalSeasons: Map = new Map(); if (mediaServerType === MediaServerType.PLEX) { - const plexMap = new Map([ - ...plexSeasonsMap, - ...filteredSeasonsMap, - ...sonarrSeasonsMap, - ]); - plexMap.forEach((value, key) => { + plexSeasonsMap.forEach((value, key) => { finalSeasons.set(key, value); }); + + filteredSeasonsMap.forEach((value, key) => { + if (!finalSeasons.has(key)) { + finalSeasons.set(key, value); + } + }); + + sonarrSeasonsMap.forEach((value, key) => { + if (!finalSeasons.has(key)) { + finalSeasons.set(key, value); + } + }); } else if ( mediaServerType === MediaServerType.JELLYFIN || mediaServerType === MediaServerType.EMBY ) { - // Adding values from jellyfinSeasonsMap jellyfinSeasonsMap.forEach((value, key) => { finalSeasons.set(key, value); }); - // Adding values from filteredSeasonsMap and handling missing keys filteredSeasonsMap.forEach((value, key) => { - // Check if the key is missing in jellyfinSeasonsMap if (!finalSeasons.has(key)) { finalSeasons.set(key, value); } }); - // Adding values from sonarrSeasonsMap and handling missing keys sonarrSeasonsMap.forEach((value, key) => { - // Check if the key is missing in jellyfinSeasonsMap and filteredSeasonsMap if (!finalSeasons.has(key)) { finalSeasons.set(key, value); } }); } - // ...(mediaServerType === MediaServerType.PLEX ? plexSeasonsMap : []), - // ...(mediaServerType === MediaServerType.JELLYFIN || - // mediaServerType === MediaServerType.EMBY ? jellyfinSeasonsMap - // : []), - const filteredSeasonsMap4k: Map = new Map(); media.seasons @@ -350,50 +347,40 @@ class AvailabilitySync { filteredSeasonsMap4k.set(season.seasonNumber, false) ); - // const finalSeasons4k: Map = new Map([ - // ...(mediaServerType === MediaServerType.PLEX - // ? plexSeasonsMap4k - // : []), - // ...(mediaServerType === MediaServerType.JELLYFIN || - // mediaServerType === MediaServerType.EMBY - // ? jellyfinSeasonsMap4k - // : []), - // ...filteredSeasonsMap4k, - // ...sonarrSeasonsMap4k, - // ]); - // 4k const finalSeasons4k: Map = new Map(); if (mediaServerType === MediaServerType.PLEX) { - const plexMap4k = new Map([ - ...plexSeasonsMap4k, - ...filteredSeasonsMap4k, - ...sonarrSeasonsMap4k, - ]); - plexMap4k.forEach((value, key) => { + plexSeasonsMap4k.forEach((value, key) => { finalSeasons4k.set(key, value); }); + + filteredSeasonsMap4k.forEach((value, key) => { + if (!finalSeasons4k.has(key)) { + finalSeasons4k.set(key, value); + } + }); + + sonarrSeasonsMap4k.forEach((value, key) => { + if (!finalSeasons4k.has(key)) { + finalSeasons4k.set(key, value); + } + }); } else if ( mediaServerType === MediaServerType.JELLYFIN || mediaServerType === MediaServerType.EMBY ) { - // Adding values from jellyfinSeasonsMap jellyfinSeasonsMap4k.forEach((value, key) => { finalSeasons4k.set(key, value); }); - // Adding values from filteredSeasonsMap and handling missing keys filteredSeasonsMap4k.forEach((value, key) => { - // Check if the key is missing in jellyfinSeasonsMap if (!finalSeasons4k.has(key)) { finalSeasons4k.set(key, value); } }); - // Adding values from sonarrSeasonsMap and handling missing keys sonarrSeasonsMap4k.forEach((value, key) => { - // Check if the key is missing in jellyfinSeasonsMap and filteredSeasonsMap if (!finalSeasons4k.has(key)) { finalSeasons4k.set(key, value); }