diff --git a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs index 21a160892..bc9fdafa1 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrAPIResource.cs @@ -11,6 +11,7 @@ namespace NzbDrone.Core.ImportLists.Readarr public List Images { get; set; } public bool Monitored { get; set; } public int QualityProfileId { get; set; } + public string RootFolderPath { get; set; } public HashSet Tags { get; set; } } @@ -46,4 +47,10 @@ namespace NzbDrone.Core.ImportLists.Readarr public string Label { get; set; } public int Id { get; set; } } + + public class ReadarrRootFolder + { + public string Path { get; set; } + public int Id { get; set; } + } } diff --git a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs index 69e53ccb4..20f38edb9 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrImport.cs @@ -43,22 +43,37 @@ namespace NzbDrone.Core.ImportLists.Readarr { var remoteAuthor = authorDict[remoteBook.AuthorId]; - if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(remoteAuthor.QualityProfileId)) && - (!Settings.TagIds.Any() || Settings.TagIds.Any(x => remoteAuthor.Tags.Any(y => y == x))) && - remoteBook.Monitored && remoteAuthor.Monitored) + if (Settings.ProfileIds.Any() && !Settings.ProfileIds.Contains(remoteAuthor.QualityProfileId)) { - authorsAndBooks.Add(new ImportListItemInfo - { - BookGoodreadsId = remoteBook.ForeignBookId, - Book = remoteBook.Title, - - // ToDo: Fix me. Edition is no longer in the book resource; rethink edition logic - // Bandaid fix for now...This will cause the imported book to possibly not be same edition as the source - // EditionGoodreadsId = remoteBook.Editions.Single(x => x.Monitored).ForeignEditionId, - Author = remoteAuthor.AuthorName, - AuthorGoodreadsId = remoteAuthor.ForeignAuthorId - }); + continue; } + + if (Settings.TagIds.Any() && !Settings.TagIds.Any(x => remoteAuthor.Tags.Any(y => y == x))) + { + continue; + } + + if (Settings.RootFolderPaths.Any() && !Settings.RootFolderPaths.Any(rootFolderPath => remoteAuthor.RootFolderPath.ContainsIgnoreCase(rootFolderPath))) + { + continue; + } + + if (!remoteBook.Monitored || !remoteAuthor.Monitored) + { + continue; + } + + authorsAndBooks.Add(new ImportListItemInfo + { + BookGoodreadsId = remoteBook.ForeignBookId, + Book = remoteBook.Title, + + // ToDo: Fix me. Edition is no longer in the book resource; rethink edition logic + // Bandaid fix for now...This will cause the imported book to possibly not be same edition as the source + // EditionGoodreadsId = remoteBook.Editions.Single(x => x.Monitored).ForeignEditionId, + Author = remoteAuthor.AuthorName, + AuthorGoodreadsId = remoteAuthor.ForeignAuthorId + }); } _importListStatusService.RecordSuccess(Definition.Id); @@ -115,6 +130,23 @@ namespace NzbDrone.Core.ImportLists.Readarr }; } + if (action == "getRootFolders") + { + Settings.Validate().Filter("ApiKey").ThrowOnError(); + + var remoteRootfolders = _readarrV1Proxy.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/Readarr/ReadarrSetting.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrSetting.cs index af4f0f49b..0fa9f2fb4 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrSetting.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrSetting.cs @@ -25,6 +25,7 @@ namespace NzbDrone.Core.ImportLists.Readarr ApiKey = ""; ProfileIds = Array.Empty(); TagIds = Array.Empty(); + RootFolderPaths = Array.Empty(); } [FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Readarr instance to import from")] @@ -39,6 +40,9 @@ namespace NzbDrone.Core.ImportLists.Readarr [FieldDefinition(3, Type = FieldType.Select, SelectOptionsProviderAction = "getTags", Label = "Tags", HelpText = "Tags from the source instance to import from")] public IEnumerable TagIds { get; set; } + [FieldDefinition(4, 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/Readarr/ReadarrV1Proxy.cs b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrV1Proxy.cs index c2535c2dc..6137c74f9 100644 --- a/src/NzbDrone.Core/ImportLists/Readarr/ReadarrV1Proxy.cs +++ b/src/NzbDrone.Core/ImportLists/Readarr/ReadarrV1Proxy.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.ImportLists.Readarr List GetAuthors(ReadarrSettings settings); List GetBooks(ReadarrSettings settings); List GetProfiles(ReadarrSettings settings); + List GetRootFolders(ReadarrSettings settings); List GetTags(ReadarrSettings settings); ValidationFailure Test(ReadarrSettings settings); } @@ -44,6 +45,11 @@ namespace NzbDrone.Core.ImportLists.Readarr return Execute("/api/v1/qualityprofile", settings); } + public List GetRootFolders(ReadarrSettings settings) + { + return Execute("api/v1/rootfolder", settings); + } + public List GetTags(ReadarrSettings settings) { return Execute("/api/v1/tag", settings);