Skip to content

Commit

Permalink
fix(rules): Season action 'unmonitor and delete existing episodes' wi…
Browse files Browse the repository at this point in the history
…ll now correctly remove and unmonitor existing episodes. The season itself will stay monitored. (#951)
  • Loading branch information
jorenn92 committed Mar 4, 2024
1 parent 070b381 commit c5a135b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
31 changes: 21 additions & 10 deletions server/src/modules/api/servarr-api/helpers/sonarr.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,29 @@ export class SonarrApi extends ServarrApi<{
const data: SonarrSeries = (await this.axios.get(`series/${seriesId}`))
.data;

const episodes: SonarrEpisode[] = await this.get(
`episodefile?seriesId=${seriesId}`,
);

// loop seasons
data.seasons = data.seasons.map((s) => {
if (
type === 'all' ||
((type === 'existing' ||
(forceExisting && type === s.seasonNumber)) &&
s.statistics?.episodeFileCount > 0)
) {
if (type === 'all') {
s.monitored = false;
} else if (
type === 'existing' ||
(forceExisting && type === s.seasonNumber)
) {
// existing episodes only, so don't unmonitor season
episodes.forEach((e) => {
if (e.seasonNumber === s.seasonNumber) {
this.UnmonitorDeleteEpisodes(
+seriesId,
e.seasonNumber,
[e.id],
false,
);
}
});
} else if (typeof type === 'number') {
// specific season
if (s.seasonNumber === type) {
Expand All @@ -334,10 +349,6 @@ export class SonarrApi extends ServarrApi<{

// delete files
if (deleteFiles) {
const episodes: SonarrEpisode[] = await this.get(
`episodefile?seriesId=${seriesId}`,
);

for (const e of episodes) {
if (typeof type === 'number') {
if (e.seasonNumber === type) {
Expand Down
4 changes: 0 additions & 4 deletions server/src/modules/api/servarr-api/radarr.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ export class RadarrController {
getMovie() {
return this.servarr.RadarrApi.getMovie({ id: 2780 });
}
@Get('/test')
testRadarr() {
this.servarr.SonarrApi.unmonitorSeasons(87, 'existing', false);
}
}

0 comments on commit c5a135b

Please sign in to comment.