Skip to content

Commit

Permalink
Merge pull request #161 from raydak-labs/feat/clone
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark authored Jan 17, 2025
2 parents 0b4a4b6 + 18941ec commit 5d5f792
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/docs/comparison.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Notes:
| Clear all Custom Formats | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Modify Scores | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Profile renaming | :white_check_mark: | | |
| Profile cloning | :white_check_mark: | | |

## Sonarr

Expand All @@ -51,6 +52,7 @@ Notes:
| Clear all Custom Formats | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Modify Scores | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Profile renaming | :white_check_mark: | | |
| Profile cloning | :white_check_mark: | | |

## Whisparr

Expand All @@ -64,6 +66,7 @@ Notes:
| Clear all Custom Formats | :white_check_mark: | | |
| Modify Scores | :white_check_mark: | | |
| Profile renaming | :white_check_mark: | | |
| Profile cloning | :white_check_mark: | | |

## Readarr

Expand All @@ -77,6 +80,7 @@ Notes:
| Clear all Custom Formats | :white_check_mark: | | |
| Modify Scores | :white_check_mark: | | |
| Profile renaming | :white_check_mark: | | |
| Profile cloning | :white_check_mark: | | |

## Lidarr

Expand All @@ -90,3 +94,4 @@ Notes:
| Clear all Custom Formats | :white_check_mark: | | |
| Modify Scores | :white_check_mark: | | |
| Profile renaming | :white_check_mark: | | |
| Profile cloning | :white_check_mark: | | |
38 changes: 36 additions & 2 deletions docs/docs/configuration/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ sonarr:
# - from: WEB-1080p
# to: RenamedProfile

# Ability to clone profiles
# cloneQualityProfiles:
# - from: RenamedExampleProfile
# to: ClonedProfile

# Radarr Configuration
radarr:
instance1: # Instance name (can be any unique identifier)
Expand Down Expand Up @@ -361,8 +366,37 @@ Notes:

- not supported in templates and will therefore not be merged!
- rename order will be displayed in `DEBUG` log like: `DEBUG [16:37:09.377]: Will rename quality profiles in this order: 'ExampleProfile' -> 'RenamedExampleProfile','[German] HD Bluray + WEB' -> 'RenamedProfile'`
- experimental, available since `v1.10.0`
-
- **experimental**, available since `v1.10.0`

## Quality Profile Cloning {#quality-profile-clone}

Support has been added to allow cloning quality profiles.
This is useful if you use existing templates for example from TRaSH-Guides but want to duplicate and slightly adjust some Custom Format scores or mappings.

We achieve the clone by duplicating all quality profiles and duplicating all profile references in the custom formats.

:::tip
The **ordering** of `rename` and `clone` is important. At the moment we `rename` first and then `clone`!
:::

```yml
# ...
sonarr:
instance1:
# ...
# Ability to clone profiles
cloneQualityProfiles:
- from: ExampleProfile # must be the exact name of the existing profile
to: ClonedProfile1 # will be the new profile
```

Notes:

- not supported in templates and will therefore not be merged!
- clone order will be displayed in `DEBUG` log
- **experimental**, available since `v1.10.0`

## Usage

Expand Down
6 changes: 2 additions & 4 deletions docs/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,8 @@ sonarr:

### Using templates from TRaSH-Guides/Recyclarr but different names

Some features are available others not yet.

- renaming quality profiles. How to implement see here: [Renaming Feature](./configuration/config-file.md##quality-profile-rename)
- clone [#115](https://github.com/raydak-labs/configarr/issues/115)
- renaming quality profiles. How to implement see here: [Renaming Feature](./configuration/config-file.md#quality-profile-rename)
- cloning quality profiles. How to implement see here: [Cloning Feature](./configuration/config-file.md#quality-profile-clone)
- duplicate templates:
You can copy those templates and paste them into a locally mounted folder.
Then you can rename them in the templates as required.
Expand Down
5 changes: 5 additions & 0 deletions examples/full/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ sonarr:
# - from: ExampleProfile
# to: RenamedExampleProfile

# Ability to clone profiles
# cloneQualityProfiles:
# - from: RenamedExampleProfile
# to: ClonedProfile

radarr:
instance1:
# Set the URL/API Key to your actual instance
Expand Down
53 changes: 52 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
MergedConfigInstance,
} from "./types/config.types";
import { TrashQP } from "./types/trashguide.types";
import { cloneWithJSON } from "./util";

let config: ConfigSchema;
let secrets: any;
Expand Down Expand Up @@ -397,7 +398,57 @@ export const mergeConfigsAndTemplates = async (
}
}

// TODO clone
// Cloning quality profiles
if (instanceConfig.cloneQualityProfiles && instanceConfig.cloneQualityProfiles.length > 0) {
const cloneOrder: string[] = [];

const newProfiles: ConfigQualityProfile[] = [];

instanceConfig.cloneQualityProfiles.forEach((e) => {
const cloneSource = e.from;
const cloneTarget = e.to;

cloneOrder.push(`'${cloneSource}' -> '${cloneTarget}'`);

let cloneQPReferences = 0;
let cloneCFAssignments = 0;

mergedTemplates.quality_profiles.forEach((p) => {
if (p.name === cloneSource) {
const clonedQP = cloneWithJSON(p);
clonedQP.name = cloneTarget;
newProfiles.push(clonedQP);
cloneQPReferences++;
}
});

mergedTemplates.custom_formats.forEach((p) => {
const cf = p.assign_scores_to?.find((cf) => {
if (cf.name === cloneSource) {
cloneCFAssignments++;
return true;
}
return false;
});

if (cf) {
p.assign_scores_to?.push({ name: cloneTarget, score: cf.score });
}
});

if (cloneQPReferences + cloneCFAssignments > 0) {
logger.debug(
`Cloning profile: source '${cloneSource}' - target '${cloneTarget}'. Found QP references ${cloneQPReferences}, CF references ${cloneCFAssignments}`,
);
}
});

mergedTemplates.quality_profiles.push(...newProfiles);

if (cloneOrder.length > 0) {
logger.debug(`Will clone quality profiles in this order: ${cloneOrder}`);
}
}

const recyclarrProfilesMerged = mergedTemplates.quality_profiles.reduce<Map<string, ConfigQualityProfile>>((p, c) => {
const profile = p.get(c.name);
Expand Down
1 change: 1 addition & 0 deletions src/types/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type InputConfigArrInstance = {
/* @experimental */
media_naming_api?: MediaNamingApiType;
renameQualityProfiles?: { from: string; to: string }[];
cloneQualityProfiles?: { from: string; to: string }[];

// this is recyclarr specific: https://recyclarr.dev/wiki/yaml/config-reference/media-naming/
media_naming?: MediaNamingType;
Expand Down

0 comments on commit 5d5f792

Please sign in to comment.