diff --git a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrAPIResource.cs b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrAPIResource.cs index 6ba3b81e0..d8b0478cb 100644 --- a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrAPIResource.cs +++ b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrAPIResource.cs @@ -11,6 +11,7 @@ namespace NzbDrone.Core.ImportLists.Lidarr 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; } } @@ -36,4 +37,10 @@ namespace NzbDrone.Core.ImportLists.Lidarr public string Label { get; set; } public int Id { get; set; } } + + public class LidarrRootFolder + { + public string Path { get; set; } + public int Id { get; set; } + } } diff --git a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrImport.cs b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrImport.cs index 209969410..c85b8683b 100644 --- a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrImport.cs +++ b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrImport.cs @@ -42,18 +42,34 @@ namespace NzbDrone.Core.ImportLists.Lidarr foreach (var remoteAlbum in remoteAlbums) { var remoteArtist = artistDict[remoteAlbum.ArtistId]; - if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(remoteArtist.QualityProfileId)) && - (!Settings.TagIds.Any() || Settings.TagIds.Any(x => remoteArtist.Tags.Any(y => y == x))) && - remoteAlbum.Monitored && remoteArtist.Monitored) + + if (Settings.ProfileIds.Any() && !Settings.ProfileIds.Contains(remoteArtist.QualityProfileId)) + { + continue; + } + + if (Settings.TagIds.Any() && !Settings.TagIds.Any(x => remoteArtist.Tags.Any(y => y == x))) + { + continue; + } + + if (Settings.RootFolderPaths.Any() && !Settings.RootFolderPaths.Any(rootFolderPath => remoteArtist.RootFolderPath.ContainsIgnoreCase(rootFolderPath))) + { + continue; + } + + if (!remoteAlbum.Monitored || !remoteArtist.Monitored) { - artistsAndAlbums.Add(new ImportListItemInfo - { - ArtistMusicBrainzId = remoteArtist.ForeignArtistId, - Artist = remoteArtist.ArtistName, - AlbumMusicBrainzId = remoteAlbum.ForeignAlbumId, - Album = remoteAlbum.Title - }); + continue; } + + artistsAndAlbums.Add(new ImportListItemInfo + { + ArtistMusicBrainzId = remoteArtist.ForeignArtistId, + Artist = remoteArtist.ArtistName, + AlbumMusicBrainzId = remoteAlbum.ForeignAlbumId, + Album = remoteAlbum.Title + }); } _importListStatusService.RecordSuccess(Definition.Id); @@ -109,6 +125,23 @@ namespace NzbDrone.Core.ImportLists.Lidarr }; } + if (action == "getRootFolders") + { + Settings.Validate().Filter("ApiKey").ThrowOnError(); + + var remoteRootfolders = _lidarrV1Proxy.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/Lidarr/LidarrSettings.cs b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrSettings.cs index 330bc418f..1ec08d710 100644 --- a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrSettings.cs @@ -25,6 +25,7 @@ namespace NzbDrone.Core.ImportLists.Lidarr ApiKey = ""; ProfileIds = Array.Empty(); TagIds = Array.Empty(); + RootFolderPaths = Array.Empty(); } [FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Lidarr instance to import from")] @@ -39,6 +40,9 @@ namespace NzbDrone.Core.ImportLists.Lidarr [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/Lidarr/LidarrV1Proxy.cs b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrV1Proxy.cs index a3ebacb65..f8e1ad5fb 100644 --- a/src/NzbDrone.Core/ImportLists/Lidarr/LidarrV1Proxy.cs +++ b/src/NzbDrone.Core/ImportLists/Lidarr/LidarrV1Proxy.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.ImportLists.Lidarr List GetArtists(LidarrSettings settings); List GetAlbums(LidarrSettings settings); List GetProfiles(LidarrSettings settings); + List GetRootFolders(LidarrSettings settings); List GetTags(LidarrSettings settings); ValidationFailure Test(LidarrSettings settings); } @@ -44,6 +45,11 @@ namespace NzbDrone.Core.ImportLists.Lidarr return Execute("/api/v1/qualityprofile", settings); } + public List GetRootFolders(LidarrSettings settings) + { + return Execute("api/v1/rootfolder", settings); + } + public List GetTags(LidarrSettings settings) { return Execute("/api/v1/tag", settings);