From ed0a7fbdf5122a26fa936e83b76a97c55781782d Mon Sep 17 00:00:00 2001 From: sct Date: Thu, 4 Mar 2021 05:04:15 +0000 Subject: [PATCH] fix(sonarr): correctly search when updating existing sonarr series fixes #588 --- server/api/sonarr.ts | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/server/api/sonarr.ts b/server/api/sonarr.ts index 7369b0b6..e2e8bd19 100644 --- a/server/api/sonarr.ts +++ b/server/api/sonarr.ts @@ -207,11 +207,6 @@ class SonarrAPI extends ExternalAPI { if (series.id) { series.seasons = this.buildSeasonList(options.seasons, series.seasons); - series.addOptions = { - ignoreEpisodesWithFiles: true, - searchForMissingEpisodes: options.searchNow, - }; - const newSeriesResponse = await this.axios.put( '/series', series @@ -225,6 +220,9 @@ class SonarrAPI extends ExternalAPI { label: 'Sonarr', movie: newSeriesResponse.data, }); + if (options.searchNow) { + this.searchSeries(newSeriesResponse.data.id); + } } else { logger.error('Failed to update series in Sonarr', { label: 'Sonarr', @@ -350,6 +348,33 @@ class SonarrAPI extends ExternalAPI { } } + public async searchSeries(seriesId: number): Promise { + logger.info('Executing series search command', { + label: 'Sonarr API', + seriesId, + }); + await this.runCommand('SeriesSearch', { seriesId }); + } + + private async runCommand( + commandName: string, + options: Record + ): Promise { + try { + await this.axios.post(`/command`, { + name: commandName, + ...options, + }); + } catch (e) { + logger.error('Something went wrong attempting to run a Sonarr command.', { + label: 'Sonarr API', + message: e.message, + }); + + throw new Error('Failed to run Sonarr command.'); + } + } + private buildSeasonList( seasons: number[], existingSeasons?: SonarrSeason[]