New: Filter Sonarr synchronization based on Root Folders

(cherry picked from commit ff3327483a233ebe54d8f178c355abaeb6f9d11e)

Closes #2399
pull/2431/head
Lars 2 years ago committed by Bogdan
parent 8d41d0106a
commit d51f7cc02b

@ -11,6 +11,7 @@ namespace NzbDrone.Core.ImportLists.Readarr
public List<MediaCover.MediaCover> Images { get; set; } public List<MediaCover.MediaCover> Images { get; set; }
public bool Monitored { get; set; } public bool Monitored { get; set; }
public int QualityProfileId { get; set; } public int QualityProfileId { get; set; }
public string RootFolderPath { get; set; }
public HashSet<int> Tags { get; set; } public HashSet<int> Tags { get; set; }
} }
@ -46,4 +47,10 @@ namespace NzbDrone.Core.ImportLists.Readarr
public string Label { get; set; } public string Label { get; set; }
public int Id { get; set; } public int Id { get; set; }
} }
public class ReadarrRootFolder
{
public string Path { get; set; }
public int Id { get; set; }
}
} }

@ -43,10 +43,26 @@ namespace NzbDrone.Core.ImportLists.Readarr
{ {
var remoteAuthor = authorDict[remoteBook.AuthorId]; var remoteAuthor = authorDict[remoteBook.AuthorId];
if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(remoteAuthor.QualityProfileId)) && 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)
{ {
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 authorsAndBooks.Add(new ImportListItemInfo
{ {
BookGoodreadsId = remoteBook.ForeignBookId, BookGoodreadsId = remoteBook.ForeignBookId,
@ -59,7 +75,6 @@ namespace NzbDrone.Core.ImportLists.Readarr
AuthorGoodreadsId = remoteAuthor.ForeignAuthorId AuthorGoodreadsId = remoteAuthor.ForeignAuthorId
}); });
} }
}
_importListStatusService.RecordSuccess(Definition.Id); _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 { }; return new { };
} }

@ -25,6 +25,7 @@ namespace NzbDrone.Core.ImportLists.Readarr
ApiKey = ""; ApiKey = "";
ProfileIds = Array.Empty<int>(); ProfileIds = Array.Empty<int>();
TagIds = Array.Empty<int>(); TagIds = Array.Empty<int>();
RootFolderPaths = Array.Empty<string>();
} }
[FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Readarr instance to import from")] [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")] [FieldDefinition(3, Type = FieldType.Select, SelectOptionsProviderAction = "getTags", Label = "Tags", HelpText = "Tags from the source instance to import from")]
public IEnumerable<int> TagIds { get; set; } public IEnumerable<int> 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<string> RootFolderPaths { get; set; }
public NzbDroneValidationResult Validate() public NzbDroneValidationResult Validate()
{ {
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));

@ -14,6 +14,7 @@ namespace NzbDrone.Core.ImportLists.Readarr
List<ReadarrAuthor> GetAuthors(ReadarrSettings settings); List<ReadarrAuthor> GetAuthors(ReadarrSettings settings);
List<ReadarrBook> GetBooks(ReadarrSettings settings); List<ReadarrBook> GetBooks(ReadarrSettings settings);
List<ReadarrProfile> GetProfiles(ReadarrSettings settings); List<ReadarrProfile> GetProfiles(ReadarrSettings settings);
List<ReadarrRootFolder> GetRootFolders(ReadarrSettings settings);
List<ReadarrTag> GetTags(ReadarrSettings settings); List<ReadarrTag> GetTags(ReadarrSettings settings);
ValidationFailure Test(ReadarrSettings settings); ValidationFailure Test(ReadarrSettings settings);
} }
@ -44,6 +45,11 @@ namespace NzbDrone.Core.ImportLists.Readarr
return Execute<ReadarrProfile>("/api/v1/qualityprofile", settings); return Execute<ReadarrProfile>("/api/v1/qualityprofile", settings);
} }
public List<ReadarrRootFolder> GetRootFolders(ReadarrSettings settings)
{
return Execute<ReadarrRootFolder>("api/v1/rootfolder", settings);
}
public List<ReadarrTag> GetTags(ReadarrSettings settings) public List<ReadarrTag> GetTags(ReadarrSettings settings)
{ {
return Execute<ReadarrTag>("/api/v1/tag", settings); return Execute<ReadarrTag>("/api/v1/tag", settings);

Loading…
Cancel
Save