From ac0ca72f612f0e41f74096fb164c1e96f86e50ab Mon Sep 17 00:00:00 2001 From: "Max T. Kristiansen" Date: Sat, 21 Sep 2024 09:37:33 +0200 Subject: [PATCH] fix: prevent Fetcharr from adding existing items to services --- src/Provider.Radarr/src/RadarrClient.cs | 23 ++++++++++++++--------- src/Provider.Sonarr/src/SonarrClient.cs | 23 ++++++++++++++--------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/Provider.Radarr/src/RadarrClient.cs b/src/Provider.Radarr/src/RadarrClient.cs index c9121d3..0cea6e7 100644 --- a/src/Provider.Radarr/src/RadarrClient.cs +++ b/src/Provider.Radarr/src/RadarrClient.cs @@ -194,17 +194,22 @@ await this._client return await newMovieResponse.GetJsonAsync(); } - IFlurlResponse createdMovieResponse = await this._client - .Request("/api/v3/movie") - .PostJsonAsync(requestBody); + if(movie.Id is null) + { + IFlurlResponse createdMovieResponse = await this._client + .Request("/api/v3/movie") + .PostJsonAsync(requestBody); + + logger.LogDebug( + "Added '{Title} ({Year})' to Radarr instance '{Instance}'.", + movie.Title, + movie.Year, + this.Name); - logger.LogDebug( - "Added '{Title} ({Year})' to Radarr instance '{Instance}'.", - movie.Title, - movie.Year, - this.Name); + return await createdMovieResponse.GetJsonAsync(); + } - return await createdMovieResponse.GetJsonAsync(); + return null; } /// diff --git a/src/Provider.Sonarr/src/SonarrClient.cs b/src/Provider.Sonarr/src/SonarrClient.cs index a4e058b..e0c40f4 100644 --- a/src/Provider.Sonarr/src/SonarrClient.cs +++ b/src/Provider.Sonarr/src/SonarrClient.cs @@ -155,17 +155,22 @@ await this._client return await newSeriesResponse.GetJsonAsync(); } - IFlurlResponse createdSeriesResponse = await this._client - .Request("/api/v3/series") - .PostJsonAsync(requestBody); + if(series.Id is null) + { + IFlurlResponse createdSeriesResponse = await this._client + .Request("/api/v3/series") + .PostJsonAsync(requestBody); + + logger.LogDebug( + "Added '{Title} ({Year})' to Sonarr instance '{Instance}'.", + series.Title, + series.Year, + this.Name); - logger.LogDebug( - "Added '{Title} ({Year})' to Sonarr instance '{Instance}'.", - series.Title, - series.Year, - this.Name); + return await createdSeriesResponse.GetJsonAsync(); + } - return await createdSeriesResponse.GetJsonAsync(); + return null; } ///