feat(requests): add language profile support (#860)

This commit is contained in:
Jakob Ankarhem
2021-02-07 16:33:18 +01:00
committed by GitHub
parent 8956cb3915
commit 53f6f59798
13 changed files with 358 additions and 32 deletions

View File

@@ -112,6 +112,7 @@ interface AddSeriesOptions {
tvdbid: number;
title: string;
profileId: number;
languageProfileId?: number;
seasons: number[];
seasonFolder: boolean;
rootFolderPath: string;
@@ -120,6 +121,11 @@ interface AddSeriesOptions {
searchNow?: boolean;
}
export interface LanguageProfile {
id: number;
name: string;
}
class SonarrAPI extends ExternalAPI {
static buildSonarrUrl(sonarrSettings: SonarrSettings, path?: string): string {
return `${sonarrSettings.useSsl ? 'https' : 'http'}://${
@@ -236,6 +242,7 @@ class SonarrAPI extends ExternalAPI {
tvdbId: options.tvdbid,
title: options.title,
profileId: options.profileId,
languageProfileId: options.languageProfileId,
seasons: this.buildSeasonList(
options.seasons,
series.seasons.map((season) => ({
@@ -321,6 +328,28 @@ class SonarrAPI extends ExternalAPI {
}
}
public async getLanguageProfiles(): Promise<LanguageProfile[]> {
try {
const data = await this.getRolling<LanguageProfile[]>(
'/v3/languageprofile',
undefined,
3600
);
return data;
} catch (e) {
logger.error(
'Something went wrong while retrieving Sonarr language profiles.',
{
label: 'Sonarr API',
message: e.message,
}
);
throw new Error('Failed to get language profiles');
}
}
private buildSeasonList(
seasons: number[],
existingSeasons?: SonarrSeason[]