From 800bcdccaf81dafd1dae3b8b86ace27284b3b684 Mon Sep 17 00:00:00 2001 From: Ben Scobie Date: Thu, 28 Nov 2024 23:06:24 +0000 Subject: [PATCH] feat: Add "Original Language" rule to Sonarr & Radarr --- .../interfaces/radarr.interface.ts | 6 ++++ .../interfaces/sonarr.interface.ts | 6 ++++ .../rules/constants/rules.constants.ts | 14 ++++++++++ .../rules/getter/radarr-getter.service.ts | 28 +++++++++++-------- .../rules/getter/sonarr-getter.service.ts | 5 ++++ 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/server/src/modules/api/servarr-api/interfaces/radarr.interface.ts b/server/src/modules/api/servarr-api/interfaces/radarr.interface.ts index 46976eaf..6aa1af64 100644 --- a/server/src/modules/api/servarr-api/interfaces/radarr.interface.ts +++ b/server/src/modules/api/servarr-api/interfaces/radarr.interface.ts @@ -14,6 +14,7 @@ export interface RadarrMovieOptions { export interface RadarrMovie { id: number; title: string; + originalLanguage: RadarrLanguage; isAvailable: boolean; monitored: boolean; tmdbId: number; @@ -34,6 +35,11 @@ export interface RadarrMovie { tags: number[]; } +export interface RadarrLanguage { + id: number; + name: string | null; +} + export interface RadarrInfo { appName: string; version: string; diff --git a/server/src/modules/api/servarr-api/interfaces/sonarr.interface.ts b/server/src/modules/api/servarr-api/interfaces/sonarr.interface.ts index bae6851c..f47b212b 100644 --- a/server/src/modules/api/servarr-api/interfaces/sonarr.interface.ts +++ b/server/src/modules/api/servarr-api/interfaces/sonarr.interface.ts @@ -83,6 +83,7 @@ export interface SonarrEpisode { export interface SonarrSeries { title: string; sortTitle: string; + originalLanguage: SonarrLanguage; seasonCount: number; status: string; overview: string; @@ -131,6 +132,11 @@ export interface SonarrSeries { ended?: boolean; } +export interface SonarrLanguage { + id: number; + name: string | null; +} + export interface AddSeriesOptions { tvdbid: number; title: string; diff --git a/server/src/modules/rules/constants/rules.constants.ts b/server/src/modules/rules/constants/rules.constants.ts index d37ac18d..37e05209 100644 --- a/server/src/modules/rules/constants/rules.constants.ts +++ b/server/src/modules/rules/constants/rules.constants.ts @@ -430,6 +430,13 @@ export class RuleConstants { mediaType: MediaType.MOVIE, type: RuleType.TEXT, } as Property, + { + id: 13, + name: 'originalLanguage', + humanName: 'Original language', + mediaType: MediaType.MOVIE, + type: RuleType.TEXT, + } as Property, ], }, { @@ -555,6 +562,13 @@ export class RuleConstants { mediaType: MediaType.SHOW, type: RuleType.TEXT, } as Property, + { + id: 15, + name: 'originalLanguage', + humanName: 'Original language', + mediaType: MediaType.SHOW, + type: RuleType.TEXT, + } as Property, ], }, { diff --git a/server/src/modules/rules/getter/radarr-getter.service.ts b/server/src/modules/rules/getter/radarr-getter.service.ts index f82dc878..dc8925f5 100644 --- a/server/src/modules/rules/getter/radarr-getter.service.ts +++ b/server/src/modules/rules/getter/radarr-getter.service.ts @@ -56,27 +56,27 @@ export class RadarrGetterService { return movieResponse.added ? new Date(movieResponse.added) : null; } case 'fileDate': { - return movieResponse?.movieFile?.dateAdded + return movieResponse.movieFile?.dateAdded ? new Date(movieResponse.movieFile.dateAdded) : null; } case 'filePath': { - return movieResponse?.movieFile?.path + return movieResponse.movieFile?.path ? movieResponse.movieFile.path : null; } case 'fileQuality': { - return movieResponse?.movieFile?.quality?.quality?.resolution + return movieResponse.movieFile?.quality?.quality?.resolution ? movieResponse.movieFile.quality.quality.resolution : null; } case 'fileAudioChannels': { - return movieResponse?.movieFile + return movieResponse.movieFile ? movieResponse.movieFile.mediaInfo?.audioChannels : null; } case 'runTime': { - if (movieResponse?.movieFile?.mediaInfo?.runTime) { + if (movieResponse.movieFile?.mediaInfo?.runTime) { const hms = movieResponse.movieFile.mediaInfo.runTime; const splitted = hms.split(':'); return +splitted[0] * 60 + +splitted[1]; @@ -84,35 +84,34 @@ export class RadarrGetterService { return null; } case 'monitored': { - return movieResponse?.monitored + return movieResponse.monitored ? movieResponse.monitored ? 1 : 0 : null; } case 'tags': { - const movieTags = movieResponse?.tags; + const movieTags = movieResponse.tags; return (await radarrApiClient.getTags()) ?.filter((el) => movieTags.includes(el.id)) .map((el) => el.label); } case 'profile': { - const movieProfile = movieResponse?.qualityProfileId; + const movieProfile = movieResponse.qualityProfileId; return (await radarrApiClient.getProfiles())?.find( (el) => el.id === movieProfile, ).name; } case 'fileSize': { - return movieResponse?.sizeOnDisk + return movieResponse.sizeOnDisk ? Math.round(movieResponse.sizeOnDisk / 1048576) : movieResponse.movieFile?.size ? Math.round(movieResponse.movieFile.size / 1048576) : null; } case 'releaseDate': { - return movieResponse?.physicalRelease && - movieResponse?.digitalRelease + return movieResponse.physicalRelease && movieResponse.digitalRelease ? (await new Date(movieResponse.physicalRelease)) > new Date(movieResponse.digitalRelease) ? new Date(movieResponse.digitalRelease) @@ -124,10 +123,15 @@ export class RadarrGetterService { : null; } case 'inCinemas': { - return movieResponse?.inCinemas + return movieResponse.inCinemas ? new Date(movieResponse.inCinemas) : null; } + case 'originalLanguage': { + return movieResponse.originalLanguage?.name + ? movieResponse.originalLanguage.name + : null; + } } } else { this.logger.debug( diff --git a/server/src/modules/rules/getter/sonarr-getter.service.ts b/server/src/modules/rules/getter/sonarr-getter.service.ts index 6bf9af86..5c0cbf36 100644 --- a/server/src/modules/rules/getter/sonarr-getter.service.ts +++ b/server/src/modules/rules/getter/sonarr-getter.service.ts @@ -263,6 +263,11 @@ export class SonarrGetterService { : false; } } + case 'originalLanguage': { + return showResponse.originalLanguage?.name + ? showResponse.originalLanguage.name + : null; + } } } else return null; } else {