Skip to content

Commit

Permalink
feat: Add "Original Language" rule to Sonarr & Radarr
Browse files Browse the repository at this point in the history
  • Loading branch information
benscobie committed Dec 6, 2024
1 parent a651ab2 commit 800bcdc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface RadarrMovieOptions {
export interface RadarrMovie {
id: number;
title: string;
originalLanguage: RadarrLanguage;
isAvailable: boolean;
monitored: boolean;
tmdbId: number;
Expand All @@ -34,6 +35,11 @@ export interface RadarrMovie {
tags: number[];
}

export interface RadarrLanguage {
id: number;
name: string | null;
}

export interface RadarrInfo {
appName: string;
version: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface SonarrEpisode {
export interface SonarrSeries {
title: string;
sortTitle: string;
originalLanguage: SonarrLanguage;
seasonCount: number;
status: string;
overview: string;
Expand Down Expand Up @@ -131,6 +132,11 @@ export interface SonarrSeries {
ended?: boolean;
}

export interface SonarrLanguage {
id: number;
name: string | null;
}

export interface AddSeriesOptions {
tvdbid: number;
title: string;
Expand Down
14 changes: 14 additions & 0 deletions server/src/modules/rules/constants/rules.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
},
{
Expand Down Expand Up @@ -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,
],
},
{
Expand Down
28 changes: 16 additions & 12 deletions server/src/modules/rules/getter/radarr-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,63 +56,62 @@ 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];
}
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)
Expand All @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions server/src/modules/rules/getter/sonarr-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ export class SonarrGetterService {
: false;
}
}
case 'originalLanguage': {
return showResponse.originalLanguage?.name
? showResponse.originalLanguage.name
: null;
}
}
} else return null;
} else {
Expand Down

0 comments on commit 800bcdc

Please sign in to comment.