Skip to content

Commit

Permalink
fix: adjust changes for recyclarr 7.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark committed Aug 8, 2024
1 parent 8cae749 commit 29112c4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
};
Expand Down
2 changes: 2 additions & 0 deletions src/quality-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 21 additions & 3 deletions src/recyclarr-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -57,7 +57,7 @@ export const getLocalTemplatePath = () => {
return customPath;
};

export const loadRecyclarrTemplates = (arrType: ArrType) => {
export const loadRecyclarrTemplates = (arrType: ArrType): Map<string, MappedTemplates> => {
const map = new Map<string, RecyclarrTemplates>();

const fillMap = (path: string) => {
Expand All @@ -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,
},
];
}),
);
};
14 changes: 13 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export type TrashQualityDefintion = {
qualities: TrashQualityDefintionQuality[];
};

export type RecyclarrCustomFormats = Partial<Pick<YamlList, "trash_ids" | "quality_profiles">> & {
assign_scores_to?: { name: string; score?: number }[];
};

export type RecyclarrConfigInstance = Omit<YamlConfigInstance, "custom_formats"> & {
custom_formats: RecyclarrCustomFormats[];
};

export type YamlConfigInstance = {
base_url: string;
api_key: string;
Expand Down Expand Up @@ -130,11 +138,15 @@ export type YamlConfigQualityProfileItems = {
};

export type RecyclarrTemplates = Partial<
Pick<YamlConfigInstance, "quality_definition" | "custom_formats" | "include" | "quality_profiles">
Pick<RecyclarrConfigInstance, "quality_definition" | "custom_formats" | "include" | "quality_profiles">
>;

export type RecyclarrMergedTemplates = RecyclarrTemplates & Required<Pick<RecyclarrTemplates, "custom_formats" | "quality_profiles">>;

export type MappedTemplates = Partial<Pick<YamlConfigInstance, "quality_definition" | "custom_formats" | "include" | "quality_profiles">>;

export type MappedMergedTemplates = MappedTemplates & Required<Pick<MappedTemplates, "custom_formats" | "quality_profiles">>;

export type YamlConfig = {
trashGuideUrl: string;
trashRevision?: string;
Expand Down

0 comments on commit 29112c4

Please sign in to comment.