Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions fetcharr.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ sonarr:
## Default: 3
# short_series_threshold: 1

## Adds the given tags to any items added by Fetcharr.
## Default: []
# tags: []

## Example of a Sonarr instance, exclusively for anime.
# sonarr_anime:
# base_url: http://localhost:8989
Expand Down Expand Up @@ -157,6 +161,10 @@ radarr:
## Default: MovieOnly
# monitored_items: MovieAndCollection

## Adds the given tags to any items added by Fetcharr.
## Default: []
# tags: []

## Example of a Radarr instance, exclusively for anime.
# radarr_anime:
# base_url: http://localhost:7878
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ public abstract class FetcharrServiceConfiguration
/// </summary>
[YamlMember(Alias = "update_existing")]
public bool UpdateExisting { get; set; } = true;

/// <summary>
/// Gets or sets any tags which should be added to any items added by Fetcharr.
/// </summary>
[YamlMember(Alias = "tags")]
public List<string> Tags { get; set; } = [];
}
}
18 changes: 18 additions & 0 deletions src/Provider.Radarr/src/Models/RadarrTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Fetcharr.Provider.Radarr.Models
{
/// <summary>
/// Representation of a Radarr tag.
/// </summary>
public class RadarrTag
{
/// <summary>
/// Gets or sets the ID of the tag, within Radarr.
/// </summary>
public int Id { get; set; }

/// <summary>
/// Gets or sets the label of the tag.
/// </summary>
public string Label { get; set; } = string.Empty;
}
}
28 changes: 27 additions & 1 deletion src/Provider.Radarr/src/RadarrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ await this._client

RadarrRootFolder rootFolder = await this.DetermineRootFolderAsync(options);
RadarrQualityProfile qualityProfile = await this.DetermineQualityProfileAsync(options);
List<int> tags = await this.EnsureTagsExistsAsync();

object requestBody = new
{
Expand All @@ -162,7 +163,7 @@ await this._client
_ => throw new NotSupportedException()
},
monitored = options.Monitored ?? configuration.Monitored,
tags = Array.Empty<int>(),
tags,
addOptions = new
{
ignoreEpisodesWithFiles = true,
Expand Down Expand Up @@ -270,5 +271,30 @@ private async Task<RadarrQualityProfile> DetermineQualityProfileAsync(RadarrMovi
v.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
?? throw new InvalidOperationException($"[{this.Name}] No quality profile defined.");
}

/// <summary>
/// Ensures that the tags specified in the configuration exist on the instance, and sets <see cref="TagIDs"/>
/// to the IDs of those tags.
/// </summary>
private async Task<List<int>> EnsureTagsExistsAsync()
{
List<int> IDs = [];

foreach(string tag in configuration.Tags)
{
IFlurlResponse createdTagResponse = await this._client
.Request("/api/v3/tag")
.PostJsonAsync(new
{
label = tag,
});

IDs.Add((await createdTagResponse.GetJsonAsync<RadarrTag>()).Id);

logger.LogDebug("Added tag '{Tag}' to Radarr instance '{Instance}'.", tag, this.Name);
}

return IDs;
}
}
}
18 changes: 18 additions & 0 deletions src/Provider.Sonarr/src/Models/SonarrTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Fetcharr.Provider.Sonarr.Models
{
/// <summary>
/// Representation of a Sonarr tag.
/// </summary>
public class SonarrTag
{
/// <summary>
/// Gets or sets the ID of the tag, within Sonarr.
/// </summary>
public int Id { get; set; }

/// <summary>
/// Gets or sets the label of the tag.
/// </summary>
public string Label { get; set; } = string.Empty;
}
}
28 changes: 27 additions & 1 deletion src/Provider.Sonarr/src/SonarrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ await this._client

SonarrRootFolder rootFolder = await this.DetermineRootFolderAsync(options);
SonarrQualityProfile qualityProfile = await this.DetermineQualityProfileAsync(options);
List<int> tags = await this.EnsureTagsExistsAsync();

object requestBody = new
{
Expand All @@ -117,7 +118,7 @@ await this._client
monitorNewItems = (options.MonitorNewItems ?? configuration.MonitorNewItems) ? "all" : "none",
seriesType = options.SeriesType ?? configuration.SeriesType,
seasons = Array.Empty<int>(),
tags = Array.Empty<int>(),
tags,
addOptions = new
{
ignoreEpisodesWithFiles = true,
Expand Down Expand Up @@ -231,5 +232,30 @@ private async Task<SonarrQualityProfile> DetermineQualityProfileAsync(SonarrSeri
v.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
?? throw new InvalidOperationException($"[{this.Name}] No quality profile defined.");
}

/// <summary>
/// Ensures that the tags specified in the configuration exist on the instance, and sets <see cref="TagIDs"/>
/// to the IDs of those tags.
/// </summary>
private async Task<List<int>> EnsureTagsExistsAsync()
{
List<int> IDs = [];

foreach(string tag in configuration.Tags)
{
IFlurlResponse createdTagResponse = await this._client
.Request("/api/v3/tag")
.PostJsonAsync(new
{
label = tag,
});

IDs.Add((await createdTagResponse.GetJsonAsync<SonarrTag>()).Id);

logger.LogDebug("Added tag '{Tag}' to Sonarr instance '{Instance}'.", tag, this.Name);
}

return IDs;
}
}
}