Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(servarr): Make Overseerr respect List Exclusions in Radarr/Sonarr #3941

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions server/api/servarr/radarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,9 +92,39 @@ class RadarrAPI extends ServarrBase<{ movieId: number }> {
}
}

private async checkMovieExclusionsByTmdbId(id: number): Promise<boolean> {
try {
const response = await this.axios.get<RadarrExclusionList>(
'/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<RadarrMovie> => {
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);

Expand Down
43 changes: 43 additions & 0 deletions server/api/servarr/sonarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -181,7 +194,37 @@ class SonarrAPI extends ServarrBase<{
}
}

private async checkSeriesExclusionsByTvdbId(id: number): Promise<boolean> {
try {
const response = await this.axios.get<SonarrExclusionList>(
'/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<SonarrSeries> {
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);

Expand Down
Loading