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

fix(rules): Season action 'unmonitor and delete existing episodes' wi… #951

Merged
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
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);
}
}
Loading