From 61681857b123802aaeff02a8f61b1ba046c5d333 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Wed, 9 Feb 2022 21:42:20 -0500 Subject: [PATCH] fix(sonarr): only scan seasons that exist in TMDb (#2523) --- server/lib/scanners/sonarr/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server/lib/scanners/sonarr/index.ts b/server/lib/scanners/sonarr/index.ts index db3aef98b..044f74ec7 100644 --- a/server/lib/scanners/sonarr/index.ts +++ b/server/lib/scanners/sonarr/index.ts @@ -1,6 +1,7 @@ import { uniqWith } from 'lodash'; import { getRepository } from 'typeorm'; import SonarrAPI, { SonarrSeries } from '../../../api/servarr/sonarr'; +import { TmdbTvDetails } from '../../../api/themoviedb/interfaces'; import Media from '../../../entity/Media'; import { getSettings, SonarrSettings } from '../../settings'; import BaseScanner, { @@ -83,24 +84,26 @@ class SonarrScanner const mediaRepository = getRepository(Media); const server4k = this.enable4kShow && this.currentServer.is4k; const processableSeasons: ProcessableSeason[] = []; - let tmdbId: number; + let tvShow: TmdbTvDetails; const media = await mediaRepository.findOne({ where: { tvdbId: sonarrSeries.tvdbId }, }); if (!media || !media.tmdbId) { - const tvShow = await this.tmdb.getShowByTvdbId({ + tvShow = await this.tmdb.getShowByTvdbId({ tvdbId: sonarrSeries.tvdbId, }); - - tmdbId = tvShow.id; } else { - tmdbId = media.tmdbId; + tvShow = await this.tmdb.getTvShow({ tvId: media.tmdbId }); } + const tmdbId = tvShow.id; + const filteredSeasons = sonarrSeries.seasons.filter( - (sn) => sn.seasonNumber !== 0 + (sn) => + sn.seasonNumber !== 0 && + tvShow.seasons.find((s) => s.season_number === sn.seasonNumber) ); for (const season of filteredSeasons) {