diff --git a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrAPIResource.cs b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrAPIResource.cs index f34da0d8d..1ce4ea9f8 100644 --- a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrAPIResource.cs +++ b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrAPIResource.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.ImportLists.Sonarr public string TitleSlug { get; set; } public int QualityProfileId { get; set; } public int LanguageProfileId { get; set; } + public string RootFolderPath { get; set; } public HashSet Tags { get; set; } } @@ -29,4 +30,10 @@ namespace NzbDrone.Core.ImportLists.Sonarr public string Label { get; set; } public int Id { get; set; } } + + public class SonarrRootFolder + { + public string Path { get; set; } + public int Id { get; set; } + } } diff --git a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrImport.cs b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrImport.cs index 6159b71c8..23f49231b 100644 --- a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrImport.cs +++ b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrImport.cs @@ -39,16 +39,31 @@ namespace NzbDrone.Core.ImportLists.Sonarr foreach (var item in remoteSeries) { - if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(item.QualityProfileId)) && - (!Settings.LanguageProfileIds.Any() || Settings.LanguageProfileIds.Contains(item.LanguageProfileId)) && - (!Settings.TagIds.Any() || Settings.TagIds.Any(tagId => item.Tags.Any(itemTagId => itemTagId == tagId)))) + if (Settings.ProfileIds.Any() && !Settings.ProfileIds.Contains(item.QualityProfileId)) { - series.Add(new ImportListItemInfo - { - TvdbId = item.TvdbId, - Title = item.Title - }); + continue; + } + + if (Settings.LanguageProfileIds.Any() && !Settings.LanguageProfileIds.Contains(item.LanguageProfileId)) + { + continue; } + + if (Settings.TagIds.Any() && !Settings.TagIds.Any(tagId => item.Tags.Any(itemTagId => itemTagId == tagId))) + { + continue; + } + + if (Settings.RootFolderPaths.Any() && !Settings.RootFolderPaths.Any(rootFolderPath => item.RootFolderPath.ContainsIgnoreCase(rootFolderPath))) + { + continue; + } + + series.Add(new ImportListItemInfo + { + TvdbId = item.TvdbId, + Title = item.Title + }); } _importListStatusService.RecordSuccess(Definition.Id); @@ -121,6 +136,23 @@ namespace NzbDrone.Core.ImportLists.Sonarr }; } + if (action == "getRootFolders") + { + Settings.Validate().Filter("ApiKey").ThrowOnError(); + + var remoteRootfolders = _sonarrV3Proxy.GetRootFolders(Settings); + + return new + { + options = remoteRootfolders.OrderBy(d => d.Path, StringComparer.InvariantCultureIgnoreCase) + .Select(d => new + { + value = d.Path, + name = d.Path + }) + }; + } + return new { }; } diff --git a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs index 5e7655f12..ced896f8f 100644 --- a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs @@ -26,12 +26,13 @@ namespace NzbDrone.Core.ImportLists.Sonarr ProfileIds = Array.Empty(); LanguageProfileIds = Array.Empty(); TagIds = Array.Empty(); + RootFolderPaths = Array.Empty(); } - [FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Sonarr V3 instance to import from")] + [FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Sonarr instance to import from")] public string BaseUrl { get; set; } - [FieldDefinition(1, Label = "API Key", HelpText = "Apikey of the Sonarr V3 instance to import from")] + [FieldDefinition(1, Label = "API Key", HelpText = "Apikey of the Sonarr instance to import from")] public string ApiKey { get; set; } [FieldDefinition(2, Type = FieldType.Select, SelectOptionsProviderAction = "getProfiles", Label = "Quality Profiles", HelpText = "Quality Profiles from the source instance to import from")] @@ -43,6 +44,9 @@ namespace NzbDrone.Core.ImportLists.Sonarr [FieldDefinition(4, Type = FieldType.Select, SelectOptionsProviderAction = "getTags", Label = "Tags", HelpText = "Tags from the source instance to import from")] public IEnumerable TagIds { get; set; } + [FieldDefinition(5, Type = FieldType.Select, SelectOptionsProviderAction = "getRootFolders", Label = "Root Folders", HelpText = "Root Folders from the source instance to import from")] + public IEnumerable RootFolderPaths { get; set; } + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); diff --git a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs index 7e4bcdbb2..f51cb2f87 100644 --- a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs +++ b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrV3Proxy.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.ImportLists.Sonarr List GetSeries(SonarrSettings settings); List GetQualityProfiles(SonarrSettings settings); List GetLanguageProfiles(SonarrSettings settings); + List GetRootFolders(SonarrSettings settings); List GetTags(SonarrSettings settings); ValidationFailure Test(SonarrSettings settings); } @@ -44,6 +45,11 @@ namespace NzbDrone.Core.ImportLists.Sonarr return Execute("/api/v3/languageprofile", settings); } + public List GetRootFolders(SonarrSettings settings) + { + return Execute("api/v3/rootfolder", settings); + } + public List GetTags(SonarrSettings settings) { return Execute("/api/v3/tag", settings);