mirror of
https://github.com/Readarr/Readarr
synced 2025-12-29 11:47:12 +01:00
New: Filter Sonarr synchronization based on Root Folders
(cherry picked from commit ff3327483a233ebe54d8f178c355abaeb6f9d11e) Closes #2399
This commit is contained in:
parent
8d41d0106a
commit
d51f7cc02b
4 changed files with 63 additions and 14 deletions
|
|
@ -11,6 +11,7 @@ public class ReadarrAuthor
|
|||
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 @@ public class ReadarrTag
|
|||
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 @@ public override IList<ImportListItemInfo> Fetch()
|
|||
{
|
||||
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 @@ public override object RequestAction(string action, IDictionary<string, string>
|
|||
};
|
||||
}
|
||||
|
||||
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 @@ public ReadarrSettings()
|
|||
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 @@ public ReadarrSettings()
|
|||
[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 @@ public interface IReadarrV1Proxy
|
|||
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 @@ public List<ReadarrProfile> GetProfiles(ReadarrSettings 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)
|
||||
{
|
||||
return Execute<ReadarrTag>("/api/v1/tag", settings);
|
||||
|
|
|
|||
Loading…
Reference in a new issue