Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion server/lib/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface SonarrSettings extends DVRSettings {
activeLanguageProfileId?: number;
animeTags?: number[];
enableSeasonFolders: boolean;
monitorNewItems: 'all' | 'none';
monitorNewItems: 'all' | 'none' | 'latest';
}

interface Quota {
Expand Down
11 changes: 10 additions & 1 deletion server/subscriber/MediaRequestSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import SeasonRequest from '@server/entity/SeasonRequest';
import notificationManager, { Notification } from '@server/lib/notifications';
import { getSettings } from '@server/lib/settings';
import logger from '@server/logger';
import { resolveMonitorNewItems } from '@server/utils/sonarr';
import { isEqual, truncate } from 'lodash';
import type {
EntityManager,
Expand Down Expand Up @@ -711,7 +712,15 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface<MediaRe
seriesType,
tags,
monitored: true,
monitorNewItems: sonarrSettings.monitorNewItems,
monitorNewItems: resolveMonitorNewItems({
setting: sonarrSettings.monitorNewItems ?? 'all',
requestedSeasons: entity.seasons.map(
(season) => season.seasonNumber
),
availableSeasons: series.seasons.map(
(season) => season.season_number
),
}),
searchNow: !sonarrSettings.preventSearch,
};

Expand Down
71 changes: 71 additions & 0 deletions server/utils/sonarr.test.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want tests for Sonarr yet.
@fallenbagel wdyt? Maybe we should do add all *arr tests at once in another PR?

If so, the whole PR could be simplified without that resolveMonitorNewItems helper function.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { resolveMonitorNewItems } from '@server/utils/sonarr';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

describe('resolveMonitorNewItems', () => {
it('preserves the all setting', () => {
assert.equal(
resolveMonitorNewItems({
setting: 'all',
requestedSeasons: [1],
availableSeasons: [1, 2, 3],
}),
'all'
);
});

it('preserves the none setting', () => {
assert.equal(
resolveMonitorNewItems({
setting: 'none',
requestedSeasons: [3],
availableSeasons: [1, 2, 3],
}),
'none'
);
});

it('does not monitor new seasons when the latest season is not requested', () => {
assert.equal(
resolveMonitorNewItems({
setting: 'latest',
requestedSeasons: [1, 2],
availableSeasons: [0, 1, 2, 3],
}),
'none'
);
});

it('monitors new seasons when the latest season is requested', () => {
assert.equal(
resolveMonitorNewItems({
setting: 'latest',
requestedSeasons: [1, 3],
availableSeasons: [0, 1, 2, 3],
}),
'all'
);
});

it('does not treat specials as the latest season', () => {
assert.equal(
resolveMonitorNewItems({
setting: 'latest',
requestedSeasons: [0],
availableSeasons: [0, 1],
}),
'none'
);
});

it('does not monitor new seasons when no regular seasons are available', () => {
assert.equal(
resolveMonitorNewItems({
setting: 'latest',
requestedSeasons: [0],
availableSeasons: [0],
}),
'none'
);
});
});
25 changes: 25 additions & 0 deletions server/utils/sonarr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { SonarrSeries } from '@server/api/servarr/sonarr';
import type { SonarrSettings } from '@server/lib/settings';

export const resolveMonitorNewItems = ({
setting,
requestedSeasons,
availableSeasons,
}: {
setting: SonarrSettings['monitorNewItems'];
requestedSeasons: number[];
availableSeasons: number[];
}): SonarrSeries['monitorNewItems'] => {
if (setting !== 'latest') {
return setting;
}

const latestSeason = Math.max(
...availableSeasons.filter((seasonNumber) => seasonNumber > 0)
);

return Number.isFinite(latestSeason) &&
requestedSeasons.includes(latestSeason)
? 'all'
: 'none';
};
15 changes: 12 additions & 3 deletions src/components/Settings/SonarrModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ const messages = defineMessages('components.Settings.SonarrModal', {
selecttags: 'Select tags',
monitorNewItems: 'Monitor New Seasons',
monitorNewItemsHelp:
'Whether Sonarr should monitor (All) or not (None) new seasons when a series is added.',
'Choose when Sonarr should monitor new seasons after a series is added.',
monitorNewItemsNone: 'None',
monitorNewItemsLatest: 'Latest Season Requested',
apiKeyHelp: 'Find it in Sonarr: Settings > General > Security > API Key',
baseUrlHelp:
'If you set a URL Base in Sonarr (Settings > General > Host), enter it here (e.g. /sonarr). Leave blank otherwise.',
Expand Down Expand Up @@ -1026,8 +1028,15 @@ const SonarrModal = ({ onClose, sonarr, onSave }: SonarrModalProps) => {
name="monitorNewItems"
disabled={!isValidated || isTesting}
>
<option value="all">All</option>
<option value="none">None</option>
<option value="all">
{intl.formatMessage(globalMessages.all)}
</option>
<option value="none">
{intl.formatMessage(messages.monitorNewItemsNone)}
</option>
<option value="latest">
{intl.formatMessage(messages.monitorNewItemsLatest)}
</option>
</Field>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@
"components.Settings.SonarrModal.loadingprofiles": "Loading quality profiles…",
"components.Settings.SonarrModal.loadingrootfolders": "Loading root folders…",
"components.Settings.SonarrModal.monitorNewItems": "Monitor New Seasons",
"components.Settings.SonarrModal.monitorNewItemsHelp": "Whether Sonarr should monitor (All) or not (None) new seasons when a series is added.",
"components.Settings.SonarrModal.monitorNewItemsHelp": "Choose when Sonarr should monitor new seasons after a series is added.",
"components.Settings.SonarrModal.monitorNewItemsLatest": "Latest Season Requested",
"components.Settings.SonarrModal.monitorNewItemsNone": "None",
"components.Settings.SonarrModal.notagoptions": "No tags.",
"components.Settings.SonarrModal.port": "Port",
"components.Settings.SonarrModal.qualityprofile": "Quality Profile",
Expand Down
Loading