Skip to content

Commit 042c442

Browse files
authored
Merge pull request #7 from raydak-labs/feat/cfs-in-config
2 parents 4ce5129 + 56500e1 commit 042c442

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ Possible ideas:
4242
- Include own defined custom formats
4343
- Custom defined formats for different languages/countries like Germany
4444
- Support all CustomFormat specifications
45-
- Maybe this?: https://github.com/recyclarr/recyclarr/issues/225
45+
- Provide CFs in different ways
46+
- Sync from TrashGuide
47+
- Sync with local file CFs
48+
- Provide CFs directly in config (Convert JSON with https://www.bairesdev.com/tools/json2yaml/)
49+
- Merge order is `TrashGuide -> LocalFiles -> CFs in Config`
4650

4751
## Work TODOs
4852

examples/full/config/config.yml

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
localCustomFormatsPath: /app/cfs
44
localConfigTemplatesPath: /app/templates
55

6+
customFormatDefinitions:
7+
- trash_id: example-in-config-cf
8+
trash_scores:
9+
default: -10000
10+
trash_description: "Language: German Only"
11+
name: "Language: Not German"
12+
includeCustomFormatWhenRenaming: false
13+
specifications:
14+
- name: Not German Language
15+
implementation: LanguageSpecification
16+
negate: true
17+
required: false
18+
fields:
19+
value: 4
20+
621
sonarr:
722
instance1:
823
# Set the URL/API Key to your actual instance

index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import fs from "fs";
44
import { CustomFormatResource } from "./src/__generated__/generated-sonarr-api";
55
import { configureRadarrApi, configureSonarrApi, getArrApi, unsetApi } from "./src/api";
66
import { getConfig } from "./src/config";
7-
import { calculateCFsToManage, loadLocalCfs, loadServerCustomFormats, manageCf, mergeCfSources } from "./src/custom-formats";
7+
import {
8+
calculateCFsToManage,
9+
loadCFFromConfig,
10+
loadLocalCfs,
11+
loadServerCustomFormats,
12+
manageCf,
13+
mergeCfSources,
14+
} from "./src/custom-formats";
815
import { logHeading, logger } from "./src/logger";
916
import { calculateQualityDefinitionDiff, loadQualityDefinitionFromServer } from "./src/quality-definitions";
1017
import {
@@ -95,9 +102,10 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => {
95102

96103
recylarrMergedTemplates.quality_profiles = filterInvalidQualityProfiles(recylarrMergedTemplates.quality_profiles);
97104

98-
const result = await loadLocalCfs();
99105
const trashCFs = await loadSonarrTrashCFs(arrType);
100-
const mergedCFs = mergeCfSources([trashCFs, result]);
106+
const localFileCFs = await loadLocalCfs();
107+
const configCFDefinition = loadCFFromConfig();
108+
const mergedCFs = mergeCfSources([trashCFs, localFileCFs, configCFDefinition]);
101109

102110
const idsToManage = calculateCFsToManage(recylarrMergedTemplates);
103111

src/custom-formats.ts

+32
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,38 @@ export const loadLocalCfs = async (): Promise<CFProcessing | null> => {
136136
cfNameToCarrConfig: cfNameToCarrObject,
137137
};
138138
};
139+
140+
export const loadCFFromConfig = (): CFProcessing | null => {
141+
// TODO typings
142+
const defs = getConfig().customFormatDefinitions;
143+
144+
if (defs == null) {
145+
logger.debug(`No CustomFormat definitions defined.`);
146+
return null;
147+
}
148+
149+
const carrIdToObject = new Map<string, { carrConfig: ConfigarrCF; requestConfig: CustomFormatResource }>();
150+
const cfNameToCarrObject = new Map<string, ConfigarrCF>();
151+
152+
for (const def of defs) {
153+
const cfD = toCarrCF(def);
154+
155+
carrIdToObject.set(cfD.configarr_id, {
156+
carrConfig: cfD,
157+
requestConfig: mapImportCfToRequestCf(cfD),
158+
});
159+
160+
if (cfD.name) {
161+
cfNameToCarrObject.set(cfD.name, cfD);
162+
}
163+
}
164+
165+
return {
166+
carrIdMapping: carrIdToObject,
167+
cfNameToCarrConfig: cfNameToCarrObject,
168+
};
169+
};
170+
139171
export const calculateCFsToManage = (yaml: YamlInput) => {
140172
const cfTrashToManage: Set<string> = new Set();
141173

src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ export type YamlConfig = {
142142
recyclarrRevision?: string;
143143
localCustomFormatsPath?: string;
144144
localConfigTemplatesPath?: string;
145+
customFormatDefinitions?: [];
146+
145147
sonarr: {
146148
[key: string]: YamlConfigInstance;
147149
};

0 commit comments

Comments
 (0)