Skip to content

Commit

Permalink
Merge pull request #1389 from jorenn92/fix-multi-arr-handle
Browse files Browse the repository at this point in the history
fix: Handling collections & Sonarr media existence check
  • Loading branch information
benscobie authored Nov 22, 2024
2 parents 5f8bd24 + 8cd0030 commit 5881fe7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
12 changes: 7 additions & 5 deletions server/src/modules/api/servarr-api/helpers/sonarr.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ export class SonarrApi extends ServarrApi<{
}
}
}

this.logger.log(
`Unmonitored ${
typeof type === 'number' ? `season ${type}` : 'seasons'
} from Sonarr show with ID ${seriesId}`,
);

return data;
} catch (e) {
this.logger.log("Couldn't unmonitor/delete. Does it exist in sonarr?", {
Expand All @@ -379,11 +386,6 @@ export class SonarrApi extends ServarrApi<{
});
this.logger.debug(e);
}
this.logger.log(
`Unmonitored ${
typeof type === 'number' ? `season ${type}` : 'seasons'
} from Sonarr show with ID ${seriesId}`,
);
}

private buildSeasonList(
Expand Down
8 changes: 4 additions & 4 deletions server/src/modules/api/servarr-api/servarr.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { SonarrSettingRawDto } from "../../settings/dto's/sonarr-setting.dto";
@Injectable()
export class ServarrService {
SonarrApi: SonarrApi;
private radarrApiCache?: Record<string, RadarrApi> = {};
private sonarrApiCache?: Record<string, SonarrApi> = {};
private radarrApiCache: Record<string, RadarrApi> = {};
private sonarrApiCache: Record<string, SonarrApi> = {};

constructor(
@Inject(forwardRef(() => SettingsService))
Expand All @@ -27,7 +27,7 @@ export class ServarrService {
if (!this.sonarrApiCache[id]) {
const setting = await this.settings.getSonarrSetting(id);

if (!('id' in setting)) {
if (setting == null || !('id' in setting)) {
throw new Error('Sonarr setting not found');
}

Expand Down Expand Up @@ -57,7 +57,7 @@ export class ServarrService {
if (!this.radarrApiCache[id]) {
const setting = await this.settings.getRadarrSetting(id);

if (!('id' in setting)) {
if (setting == null || !('id' in setting)) {
throw new Error('Radarr setting not found');
}

Expand Down
58 changes: 35 additions & 23 deletions server/src/modules/collections/collection-worker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ export class CollectionWorkerService extends TaskBase {

this.collectionService.saveCollection(collection);

const radarrApiClient = collection.radarrSettings.id
? await this.servarrApi.getRadarrApiClient(collection.radarrSettings.id)
const radarrApiClient = collection.radarrSettingsId
? await this.servarrApi.getRadarrApiClient(collection.radarrSettingsId)
: undefined;

const sonarrApiClient = collection.sonarrSettings.id
? await this.servarrApi.getSonarrApiClient(collection.sonarrSettings.id)
const sonarrApiClient = collection.sonarrSettingsId
? await this.servarrApi.getSonarrApiClient(collection.sonarrSettingsId)
: undefined;

if (plexLibrary.type === 'movie') {
Expand Down Expand Up @@ -256,7 +256,7 @@ export class CollectionWorkerService extends TaskBase {

if (tvdbId) {
let sonarrMedia = await sonarrApiClient.getSeriesByTvdbId(tvdbId);
if (sonarrMedia) {
if (sonarrMedia?.id) {
switch (collection.arrAction) {
case ServarrAction.DELETE:
switch (collection.type) {
Expand Down Expand Up @@ -322,12 +322,16 @@ export class CollectionWorkerService extends TaskBase {
'all',
false,
);
// unmonitor show
sonarrMedia.monitored = false;
sonarrApiClient.updateSeries(sonarrMedia);
this.infoLogger(
`[Sonarr] Unmonitored show '${sonarrMedia.title}'`,
);

if (sonarrMedia) {
// unmonitor show
sonarrMedia.monitored = false;
sonarrApiClient.updateSeries(sonarrMedia);
this.infoLogger(
`[Sonarr] Unmonitored show '${sonarrMedia.title}'`,
);
}

break;
}
break;
Expand Down Expand Up @@ -360,12 +364,16 @@ export class CollectionWorkerService extends TaskBase {
'all',
true,
);
// unmonitor show
sonarrMedia.monitored = false;
sonarrApiClient.updateSeries(sonarrMedia);
this.infoLogger(
`[Sonarr] Unmonitored show '${sonarrMedia.title}' and removed all episodes`,
);

if (sonarrMedia) {
// unmonitor show
sonarrMedia.monitored = false;
sonarrApiClient.updateSeries(sonarrMedia);
this.infoLogger(
`[Sonarr] Unmonitored show '${sonarrMedia.title}' and removed all episodes`,
);
}

break;
}
break;
Expand Down Expand Up @@ -399,12 +407,16 @@ export class CollectionWorkerService extends TaskBase {
'existing',
true,
);
// unmonitor show
sonarrMedia.monitored = false;
sonarrApiClient.updateSeries(sonarrMedia);
this.infoLogger(
`[Sonarr] Unmonitored show '${sonarrMedia.title}' and Removed exisiting episodes`,
);

if (sonarrMedia) {
// unmonitor show
sonarrMedia.monitored = false;
sonarrApiClient.updateSeries(sonarrMedia);
this.infoLogger(
`[Sonarr] Unmonitored show '${sonarrMedia.title}' and Removed exisiting episodes`,
);
}

break;
}
break;
Expand Down

0 comments on commit 5881fe7

Please sign in to comment.