diff --git a/server/api/servarr/radarr.ts b/server/api/servarr/radarr.ts index 1637a8d8e4..958e156c8f 100644 --- a/server/api/servarr/radarr.ts +++ b/server/api/servarr/radarr.ts @@ -14,6 +14,20 @@ export interface RadarrMovieOptions { searchNow?: boolean; } +export interface RadarrExclusionList { + page: number; + pageSize: number; + sortKey: string; + sortDirection: string; + totalRecords: number; + records: { + tmdbId: number; + movieTitle: string; + movieYear: number; + id: number; + }[]; +} + export interface RadarrMovie { id: number; title: string; @@ -78,9 +92,39 @@ class RadarrAPI extends ServarrBase<{ movieId: number }> { } } + private async checkMovieExclusionsByTmdbId(id: number): Promise { + try { + const response = await this.axios.get( + '/exclusions/paged', + { + params: { + page: 1, + pageSize: -1, + }, + } + ); + return response.data.records.some((record) => record.tmdbId === id); + } catch (e) { + logger.error('Error retrieving exclusions by TMDB ID', { + label: 'Radarr API', + errorMessage: e.message, + tmdbId: id, + }); + throw new Error('Radarr exclusion list got error'); + } + } + public addMovie = async ( options: RadarrMovieOptions ): Promise => { + if (await this.checkMovieExclusionsByTmdbId(options.tmdbId)) { + logger.info('Movie is excluded from Radarr', { + label: 'Radarr', + tmdbId: options.tmdbId, + }); + throw new Error('Movie is excluded from Radarr'); + } + try { const movie = await this.getMovieByTmdbId(options.tmdbId); diff --git a/server/api/servarr/sonarr.ts b/server/api/servarr/sonarr.ts index 6cda2a49c4..f66ecc4b30 100644 --- a/server/api/servarr/sonarr.ts +++ b/server/api/servarr/sonarr.ts @@ -87,6 +87,19 @@ export interface SonarrSeries { }; } +export interface SonarrExclusionList { + page: number; + pageSize: number; + sortKey: string; + sortDirection: string; + totalRecords: number; + records: { + tvdbId: number; + title: string; + id: number; + }[]; +} + export interface AddSeriesOptions { tvdbid: number; title: string; @@ -181,7 +194,37 @@ class SonarrAPI extends ServarrBase<{ } } + private async checkSeriesExclusionsByTvdbId(id: number): Promise { + try { + const response = await this.axios.get( + '/importlistexclusion/paged', + { + params: { + page: 1, + pageSize: -1, + }, + } + ); + + return response.data.records.some((record) => record.tvdbId === id); + } catch (e) { + logger.error('Error retrieving importlistexclusion by tvdb ID', { + label: 'Sonarr API', + errorMessage: e.message, + tvdbId: id, + }); + throw new Error('Sonarr exclusion list got error'); + } + } + public async addSeries(options: AddSeriesOptions): Promise { + if (await this.checkSeriesExclusionsByTvdbId(options.tvdbid)) { + logger.info('Series is excluded from Sonarr', { + label: 'Sonarr', + tvdbId: options.tvdbid, + }); + throw new Error('Series is excluded from Sonarr'); + } try { const series = await this.getSeriesByTvdbId(options.tvdbid);