UI Updates, Separate Auto and Manual Searches per Indexer

This commit is contained in:
Qstick 2017-12-02 00:03:12 -05:00
commit 27d65937c0
28 changed files with 202 additions and 117 deletions

View file

@ -8,13 +8,13 @@ namespace Lidarr.Api.V1.AlbumStudio
public class AlbumStudioModule : LidarrV1Module
{
private readonly IArtistService _artistService;
private readonly IAlbumMonitoredService _episodeMonitoredService;
private readonly IAlbumMonitoredService _albumMonitoredService;
public AlbumStudioModule(IArtistService artistService, IAlbumMonitoredService episodeMonitoredService)
public AlbumStudioModule(IArtistService artistService, IAlbumMonitoredService albumMonitoredService)
: base("/albumstudio")
{
_artistService = artistService;
_episodeMonitoredService = episodeMonitoredService;
_albumMonitoredService = albumMonitoredService;
Post["/"] = artist => UpdateAll();
}
@ -33,20 +33,7 @@ namespace Lidarr.Api.V1.AlbumStudio
artist.Monitored = s.Monitored.Value;
}
if (s.Albums != null && s.Albums.Any())
{
foreach (var artistAlbum in artist.Albums)
{
var album = s.Albums.FirstOrDefault(c => c.Id == artistAlbum.Id);
if (album != null)
{
artistAlbum.Monitored = album.Monitored;
}
}
}
_episodeMonitoredService.SetAlbumMonitoredStatus(artist, request.MonitoringOptions);
_albumMonitoredService.SetAlbumMonitoredStatus(artist, request.MonitoringOptions);
}
return "ok".AsResponse(HttpStatusCode.Accepted);

View file

@ -1,11 +1,12 @@
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers;
namespace Lidarr.Api.V1.Indexers
{
public class IndexerResource : ProviderResource
{
public bool EnableRss { get; set; }
public bool EnableSearch { get; set; }
public bool EnableAutomaticSearch { get; set; }
public bool EnableInteractiveSearch { get; set; }
public bool SupportsRss { get; set; }
public bool SupportsSearch { get; set; }
public DownloadProtocol Protocol { get; set; }
@ -20,7 +21,8 @@ namespace Lidarr.Api.V1.Indexers
var resource = base.ToResource(definition);
resource.EnableRss = definition.EnableRss;
resource.EnableSearch = definition.EnableSearch;
resource.EnableAutomaticSearch = definition.EnableAutomaticSearch;
resource.EnableInteractiveSearch = definition.EnableInteractiveSearch;
resource.SupportsRss = definition.SupportsRss;
resource.SupportsSearch = definition.SupportsSearch;
resource.Protocol = definition.Protocol;
@ -35,9 +37,10 @@ namespace Lidarr.Api.V1.Indexers
var definition = base.ToModel(resource);
definition.EnableRss = resource.EnableRss;
definition.EnableSearch = resource.EnableSearch;
definition.EnableAutomaticSearch = resource.EnableAutomaticSearch;
definition.EnableInteractiveSearch = resource.EnableInteractiveSearch;
return definition;
}
}
}
}

View file

@ -89,7 +89,7 @@ namespace Lidarr.Api.V1.Indexers
{
try
{
var decisions = _nzbSearchService.AlbumSearch(albumId, true, true);
var decisions = _nzbSearchService.AlbumSearch(albumId, true, true, true);
var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(decisions);
return MapDecisions(prioritizedDecisions);

View file

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.HealthCheck.Checks;
@ -20,7 +20,11 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Returns(new List<IIndexer>());
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.SearchEnabled(It.IsAny<bool>()))
.Setup(s => s.AutomaticSearchEnabled(It.IsAny<bool>()))
.Returns(new List<IIndexer>());
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.InteractiveSearchEnabled(It.IsAny<bool>()))
.Returns(new List<IIndexer>());
}
@ -35,17 +39,28 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Returns(new List<IIndexer> { _indexerMock.Object });
}
private void GivenSearchEnabled()
private void GivenAutomaticSearchEnabled()
{
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.SearchEnabled(It.IsAny<bool>()))
.Setup(s => s.AutomaticSearchEnabled(It.IsAny<bool>()))
.Returns(new List<IIndexer> { _indexerMock.Object });
}
private void GivenInteractiveSearchEnabled()
{
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.InteractiveSearchEnabled(It.IsAny<bool>()))
.Returns(new List<IIndexer> { _indexerMock.Object });
}
private void GivenSearchFiltered()
{
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.SearchEnabled(false))
.Setup(s => s.AutomaticSearchEnabled(false))
.Returns(new List<IIndexer> { _indexerMock.Object });
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.InteractiveSearchEnabled(false))
.Returns(new List<IIndexer> { _indexerMock.Object });
}
@ -64,14 +79,33 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
}
[Test]
public void should_return_ok_when_search_is_enabled()
public void should_return_ok_when_automatic_and__search_is_enabled()
{
GivenIndexer(false, true);
GivenSearchEnabled();
GivenAutomaticSearchEnabled();
GivenInteractiveSearchEnabled();
Subject.Check().ShouldBeOk();
}
[Test]
public void should_return_warning_when_only_automatic_search_is_enabled()
{
GivenIndexer(false, true);
GivenAutomaticSearchEnabled();
Subject.Check().ShouldBeWarning();
}
[Test]
public void should_return_warning_when_only_interactive_search_is_enabled()
{
GivenIndexer(false, true);
GivenInteractiveSearchEnabled();
Subject.Check().ShouldBeWarning();
}
[Test]
public void should_return_warning_if_search_is_supported_but_disabled()
{

View file

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
.Returns(_artist);
Mocker.GetMock<ISearchForNzb>()
.Setup(s => s.ArtistSearch(_artist.Id, false, true))
.Setup(s => s.ArtistSearch(_artist.Id, false, true, false))
.Returns(new List<DownloadDecision>());
Mocker.GetMock<IProcessDownloadDecisions>()
@ -48,7 +48,7 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
Subject.Execute(new ArtistSearchCommand {ArtistId = _artist.Id, Trigger = CommandTrigger.Manual});
Mocker.GetMock<ISearchForNzb>()
.Verify(v => v.ArtistSearch(_artist.Id, false, true),
.Verify(v => v.ArtistSearch(_artist.Id, false, true, false),
Times.Exactly(_artist.Albums.Count(s => s.Monitored)));
}
}

View file

@ -0,0 +1,19 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(6)]
public class separate_automatic_and_interactive_search : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Rename.Column("EnableSearch").OnTable("Indexers").To("EnableAutomaticSearch");
Alter.Table("Indexers").AddColumn("EnableInteractiveSearch").AsBoolean().Nullable();
Execute.Sql("UPDATE Indexers SET EnableInteractiveSearch = EnableAutomaticSearch");
Alter.Table("Indexers").AlterColumn("EnableInteractiveSearch").AsBoolean().NotNullable();
}
}
}

View file

@ -19,14 +19,21 @@ namespace NzbDrone.Core.HealthCheck.Checks
public override HealthCheck Check()
{
var enabled = _indexerFactory.SearchEnabled(false);
var automaticSearchEnabled = _indexerFactory.AutomaticSearchEnabled(false);
if (enabled.Empty())
if (automaticSearchEnabled.Empty())
{
return new HealthCheck(GetType(), HealthCheckResult.Warning, "No indexers available with Search enabled, Lidarr will not provide any search results");
return new HealthCheck(GetType(), HealthCheckResult.Warning, "No indexers available with Automatic Search enabled, Lidarr will not provide any automatic search results");
}
var active = _indexerFactory.SearchEnabled(true);
var interactiveSearchEnabled = _indexerFactory.InteractiveSearchEnabled(false);
if (interactiveSearchEnabled.Empty())
{
return new HealthCheck(GetType(), HealthCheckResult.Warning, "No indexers available with Interactive Search enabled, Lidarr will not provide any interactive search results");
}
var active = _indexerFactory.AutomaticSearchEnabled(true);
if (active.Empty())
{

View file

@ -44,7 +44,7 @@ namespace NzbDrone.Core.IndexerSearch
foreach (var album in albums)
{
List<DownloadDecision> decisions;
decisions = _nzbSearchService.AlbumSearch(album.Id, false, userInvokedSearch);
decisions = _nzbSearchService.AlbumSearch(album.Id, false, userInvokedSearch, false);
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
downloadedCount += processed.Grabbed.Count;
@ -59,7 +59,7 @@ namespace NzbDrone.Core.IndexerSearch
foreach (var albumId in message.AlbumIds)
{
var decisions =
_nzbSearchService.AlbumSearch(albumId, false, message.Trigger == CommandTrigger.Manual);
_nzbSearchService.AlbumSearch(albumId, false, message.Trigger == CommandTrigger.Manual, false);
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
_logger.ProgressInfo("Album search completed. {0} reports downloaded.", processed.Grabbed.Count);

View file

@ -1,4 +1,4 @@
using NLog;
using NLog;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Messaging.Commands;
@ -22,7 +22,7 @@ namespace NzbDrone.Core.IndexerSearch
public void Execute(ArtistSearchCommand message)
{
var decisions = _nzbSearchService.ArtistSearch(message.ArtistId, false, message.Trigger == CommandTrigger.Manual);
var decisions = _nzbSearchService.ArtistSearch(message.ArtistId, false, message.Trigger == CommandTrigger.Manual, false);
var processed = _processDownloadDecisions.ProcessDecisions(decisions);
_logger.ProgressInfo("Artist search completed. {0} reports downloaded.", processed.Grabbed.Count);

View file

@ -18,6 +18,7 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
public virtual bool MonitoredEpisodesOnly { get; set; }
public virtual bool UserInvokedSearch { get; set; }
public virtual bool InteractiveSearch { get; set; }
public Artist Artist { get; set; }
public List<Album> Albums { get; set; }

View file

@ -16,8 +16,8 @@ namespace NzbDrone.Core.IndexerSearch
{
public interface ISearchForNzb
{
List<DownloadDecision> AlbumSearch(int albumId, bool missingOnly, bool userInvokedSearch);
List<DownloadDecision> ArtistSearch(int artistId, bool missingOnly, bool userInvokedSearch);
List<DownloadDecision> AlbumSearch(int albumId, bool missingOnly, bool userInvokedSearch, bool interactiveSearch);
List<DownloadDecision> ArtistSearch(int artistId, bool missingOnly, bool userInvokedSearch, bool interactiveSearch);
}
public class NzbSearchService : ISearchForNzb
@ -41,21 +41,21 @@ namespace NzbDrone.Core.IndexerSearch
_logger = logger;
}
public List<DownloadDecision> AlbumSearch(int albumId, bool missingOnly, bool userInvokedSearch)
public List<DownloadDecision> AlbumSearch(int albumId, bool missingOnly, bool userInvokedSearch, bool interactiveSearch)
{
var album = _albumService.GetAlbum(albumId);
return AlbumSearch(album, missingOnly, userInvokedSearch);
return AlbumSearch(album, missingOnly, userInvokedSearch, interactiveSearch);
}
public List<DownloadDecision> ArtistSearch(int artistId, bool missingOnly, bool userInvokedSearch)
public List<DownloadDecision> ArtistSearch(int artistId, bool missingOnly, bool userInvokedSearch, bool interactiveSearch)
{
var artist = _artistService.GetArtist(artistId);
return ArtistSearch(artist, missingOnly, userInvokedSearch);
return ArtistSearch(artist, missingOnly, userInvokedSearch, interactiveSearch);
}
public List<DownloadDecision> ArtistSearch(Artist artist, bool missingOnly, bool userInvokedSearch)
public List<DownloadDecision> ArtistSearch(Artist artist, bool missingOnly, bool userInvokedSearch, bool interactiveSearch)
{
var searchSpec = Get<ArtistSearchCriteria>(artist, userInvokedSearch);
var searchSpec = Get<ArtistSearchCriteria>(artist, userInvokedSearch, interactiveSearch);
var albums = _albumService.GetAlbumsByArtist(artist.Id);
searchSpec.Albums = albums;
@ -63,11 +63,11 @@ namespace NzbDrone.Core.IndexerSearch
return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
}
public List<DownloadDecision> AlbumSearch(Album album, bool missingOnly, bool userInvokedSearch)
public List<DownloadDecision> AlbumSearch(Album album, bool missingOnly, bool userInvokedSearch, bool interactiveSearch)
{
var artist = _artistService.GetArtist(album.ArtistId);
var searchSpec = Get<AlbumSearchCriteria>(artist, new List<Album> { album }, userInvokedSearch);
var searchSpec = Get<AlbumSearchCriteria>(artist, new List<Album> { album }, userInvokedSearch, interactiveSearch);
searchSpec.AlbumTitle = album.Title;
if (album.ReleaseDate.HasValue)
@ -78,29 +78,34 @@ namespace NzbDrone.Core.IndexerSearch
return Dispatch(indexer => indexer.Fetch(searchSpec), searchSpec);
}
private TSpec Get<TSpec>(Artist artist, List<Album> albums, bool userInvokedSearch) where TSpec : SearchCriteriaBase, new()
private TSpec Get<TSpec>(Artist artist, List<Album> albums, bool userInvokedSearch, bool interactiveSearch) where TSpec : SearchCriteriaBase, new()
{
var spec = new TSpec();
spec.Albums = albums;
spec.Artist = artist;
spec.UserInvokedSearch = userInvokedSearch;
spec.InteractiveSearch = interactiveSearch;
return spec;
}
private static TSpec Get<TSpec>(Artist artist, bool userInvokedSearch) where TSpec : SearchCriteriaBase, new()
private static TSpec Get<TSpec>(Artist artist, bool userInvokedSearch, bool interactiveSearch) where TSpec : SearchCriteriaBase, new()
{
var spec = new TSpec();
spec.Artist = artist;
spec.UserInvokedSearch = userInvokedSearch;
spec.InteractiveSearch = interactiveSearch;
return spec;
}
private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReleaseInfo>> searchAction, SearchCriteriaBase criteriaBase)
{
var indexers = _indexerFactory.SearchEnabled();
var indexers = criteriaBase.InteractiveSearch ?
_indexerFactory.InteractiveSearchEnabled() :
_indexerFactory.AutomaticSearchEnabled();
var reports = new List<ReleaseInfo>();
_logger.ProgressInfo("Searching {0} indexers for {1}", indexers.Count, criteriaBase);

View file

@ -61,7 +61,8 @@ namespace NzbDrone.Core.Indexers.Gazelle
return new IndexerDefinition
{
EnableRss = false,
EnableSearch = false,
EnableAutomaticSearch = false,
EnableInteractiveSearch = false,
Name = name,
Implementation = GetType().Name,
Settings = settings,

View file

@ -48,7 +48,8 @@ namespace NzbDrone.Core.Indexers
{
Name = GetType().Name,
EnableRss = config.Validate().IsValid && SupportsRss,
EnableSearch = config.Validate().IsValid && SupportsSearch,
EnableAutomaticSearch = config.Validate().IsValid && SupportsSearch,
EnableInteractiveSearch = config.Validate().IsValid && SupportsSearch,
Implementation = GetType().Name,
Settings = config
};

View file

@ -1,16 +1,17 @@
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public class IndexerDefinition : ProviderDefinition
{
public bool EnableRss { get; set; }
public bool EnableSearch { get; set; }
public bool EnableAutomaticSearch { get; set; }
public bool EnableInteractiveSearch { get; set; }
public DownloadProtocol Protocol { get; set; }
public bool SupportsRss { get; set; }
public bool SupportsSearch { get; set; }
public override bool Enable => EnableRss || EnableSearch;
public override bool Enable => EnableRss || EnableAutomaticSearch || EnableInteractiveSearch;
public IndexerStatus Status { get; set; }
}

View file

@ -11,7 +11,8 @@ namespace NzbDrone.Core.Indexers
public interface IIndexerFactory : IProviderFactory<IIndexer, IndexerDefinition>
{
List<IIndexer> RssEnabled(bool filterBlockedIndexers = true);
List<IIndexer> SearchEnabled(bool filterBlockedIndexers = true);
List<IIndexer> AutomaticSearchEnabled(bool filterBlockedIndexers = true);
List<IIndexer> InteractiveSearchEnabled(bool filterBlockedIndexers = true);
}
public class IndexerFactory : ProviderFactory<IIndexer, IndexerDefinition>, IIndexerFactory
@ -57,9 +58,21 @@ namespace NzbDrone.Core.Indexers
return enabledIndexers.ToList();
}
public List<IIndexer> SearchEnabled(bool filterBlockedIndexers = true)
public List<IIndexer> AutomaticSearchEnabled(bool filterBlockedIndexers = true)
{
var enabledIndexers = GetAvailableProviders().Where(n => ((IndexerDefinition)n.Definition).EnableSearch);
var enabledIndexers = GetAvailableProviders().Where(n => ((IndexerDefinition)n.Definition).EnableAutomaticSearch);
if (filterBlockedIndexers)
{
return FilterBlockedIndexers(enabledIndexers).ToList();
}
return enabledIndexers.ToList();
}
public List<IIndexer> InteractiveSearchEnabled(bool filterBlockedIndexers = true)
{
var enabledIndexers = GetAvailableProviders().Where(n => ((IndexerDefinition)n.Definition).EnableInteractiveSearch);
if (filterBlockedIndexers)
{

View file

@ -66,7 +66,8 @@ namespace NzbDrone.Core.Indexers.Newznab
return new IndexerDefinition
{
EnableRss = false,
EnableSearch = false,
EnableAutomaticSearch = false,
EnableInteractiveSearch = false,
Name = name,
Implementation = GetType().Name,
Settings = settings,

View file

@ -54,7 +54,8 @@ namespace NzbDrone.Core.Indexers.Torznab
return new IndexerDefinition
{
EnableRss = false,
EnableSearch = false,
EnableAutomaticSearch = false,
EnableInteractiveSearch = false,
Name = name,
Implementation = GetType().Name,
Settings = settings,

View file

@ -34,15 +34,7 @@ namespace NzbDrone.Core.Music
var albums = _albumService.GetAlbumsByArtist(artist.Id);
if (monitoringOptions.Monitored)
{
ToggleAlbumsMonitoredState(albums, true);
}
else
{
ToggleAlbumsMonitoredState(albums, false);
}
ToggleAlbumsMonitoredState(albums, monitoringOptions.Monitored);
//TODO Add Other Options for Future/Exisitng/Missing Once we have a good way to check for Album Related Files.

View file

@ -177,6 +177,7 @@
<Compile Include="Datastore\Migration\005_metadata_profiles.cs" />
<Compile Include="Datastore\Migration\004_add_various_qualities_in_profile.cs" />
<Compile Include="Datastore\Migration\003_add_medium_support.cs" />
<Compile Include="Datastore\Migration\006_separate_automatic_and_interactive_search.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" />

View file

@ -28,7 +28,8 @@ namespace NzbDrone.Integration.Test
Indexers.Post(new Lidarr.Api.V1.Indexers.IndexerResource
{
EnableRss = false,
EnableSearch = false,
EnableInteractiveSearch = false,
EnableAutomaticSearch = false,
ConfigContract = nameof(NewznabSettings),
Implementation = nameof(Newznab),
Name = "NewznabTest",