From 29112c420f9f17f9b58f33ad0a2abb081283a632 Mon Sep 17 00:00:00 2001 From: Eduard Marbach Date: Thu, 8 Aug 2024 17:04:56 +0200 Subject: [PATCH] fix: adjust changes for recyclarr 7.2.0 --- index.ts | 4 ++-- src/quality-profiles.ts | 2 ++ src/recyclarr-importer.ts | 24 +++++++++++++++++++++--- src/types.ts | 14 +++++++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 26cfb19..49c023c 100644 --- a/index.ts +++ b/index.ts @@ -22,14 +22,14 @@ import { } from "./src/quality-profiles"; import { cloneRecyclarrTemplateRepo, loadRecyclarrTemplates } from "./src/recyclarr-importer"; import { cloneTrashRepo, loadQualityDefinitionSonarrFromTrash, loadSonarrTrashCFs } from "./src/trash-guide"; -import { ArrType, RecyclarrMergedTemplates, TrashQualityDefintion, YamlConfigInstance, YamlConfigQualityProfile } from "./src/types"; +import { ArrType, MappedMergedTemplates, TrashQualityDefintion, YamlConfigInstance, YamlConfigQualityProfile } from "./src/types"; import { DEBUG_CREATE_FILES, IS_DRY_RUN } from "./src/util"; const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => { const api = getArrApi(); const recyclarrTemplateMap = loadRecyclarrTemplates(arrType); - const recylarrMergedTemplates: RecyclarrMergedTemplates = { + const recylarrMergedTemplates: MappedMergedTemplates = { custom_formats: [], quality_profiles: [], }; diff --git a/src/quality-profiles.ts b/src/quality-profiles.ts index f26b48f..bfeeda7 100644 --- a/src/quality-profiles.ts +++ b/src/quality-profiles.ts @@ -24,6 +24,8 @@ export const mapQualityProfiles = ({ carrIdMapping }: CFProcessing, customFormat continue; } + //logger.info(customFormats); + //logger.info(quality_profiles); for (const profile of quality_profiles) { for (const trashId of trash_ids) { const carr = carrIdMapping.get(trashId); diff --git a/src/recyclarr-importer.ts b/src/recyclarr-importer.ts index 943e9ff..6bc9dec 100644 --- a/src/recyclarr-importer.ts +++ b/src/recyclarr-importer.ts @@ -4,7 +4,7 @@ import simpleGit, { CheckRepoActions } from "simple-git"; import yaml from "yaml"; import { getConfig } from "./config"; import { logger } from "./logger"; -import { ArrType, RecyclarrTemplates } from "./types"; +import { ArrType, MappedTemplates, RecyclarrTemplates } from "./types"; import { recyclarrRepoPaths } from "./util"; const DEFAULT_RECYCLARR_GIT_URL = "https://github.com/recyclarr/config-templates"; @@ -57,7 +57,7 @@ export const getLocalTemplatePath = () => { return customPath; }; -export const loadRecyclarrTemplates = (arrType: ArrType) => { +export const loadRecyclarrTemplates = (arrType: ArrType): Map => { const map = new Map(); const fillMap = (path: string) => { @@ -82,5 +82,23 @@ export const loadRecyclarrTemplates = (arrType: ArrType) => { fillMap(localPath); } - return map; + return new Map( + Array.from(map, ([k, v]) => { + const customFormats = v.custom_formats?.map((cf) => { + // Changes from Recyclarr 7.2.0: https://github.com/recyclarr/recyclarr/releases/tag/v7.2.0 + if (cf.assign_scores_to == null && cf.quality_profiles == null) { + logger.warn(`Recyclarr Template "${k}" does not provide correct profile for custom format. Ignoring.`); + } + return { ...cf, quality_profiles: cf.assign_scores_to ?? cf.quality_profiles ?? [] }; + }); + + return [ + k, + { + ...v, + custom_formats: customFormats, + }, + ]; + }), + ); }; diff --git a/src/types.ts b/src/types.ts index 49e42eb..f318e18 100644 --- a/src/types.ts +++ b/src/types.ts @@ -96,6 +96,14 @@ export type TrashQualityDefintion = { qualities: TrashQualityDefintionQuality[]; }; +export type RecyclarrCustomFormats = Partial> & { + assign_scores_to?: { name: string; score?: number }[]; +}; + +export type RecyclarrConfigInstance = Omit & { + custom_formats: RecyclarrCustomFormats[]; +}; + export type YamlConfigInstance = { base_url: string; api_key: string; @@ -130,11 +138,15 @@ export type YamlConfigQualityProfileItems = { }; export type RecyclarrTemplates = Partial< - Pick + Pick >; export type RecyclarrMergedTemplates = RecyclarrTemplates & Required>; +export type MappedTemplates = Partial>; + +export type MappedMergedTemplates = MappedTemplates & Required>; + export type YamlConfig = { trashGuideUrl: string; trashRevision?: string;