New: Filter Sonarr synchronization based on Root Folders

(cherry picked from commit ff3327483a233ebe54d8f178c355abaeb6f9d11e)

Closes #2399
pull/2431/head
Lars 1 year 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 bool Monitored { get; set; }
public int QualityProfileId { get; set; }
public string RootFolderPath { get; set; }
public HashSet<int> 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; }
}
}

@ -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 { };
}

@ -25,6 +25,7 @@ namespace NzbDrone.Core.ImportLists.Readarr
ApiKey = "";
ProfileIds = 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")]
@ -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<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()
{
return new NzbDroneValidationResult(Validator.Validate(this));

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

Loading…
Cancel
Save