mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Consolidate sync code to ApplicationService
This commit is contained in:
@@ -54,7 +54,6 @@ namespace NzbDrone.Core.Applications
|
|||||||
public abstract void AddIndexer(IndexerDefinition indexer);
|
public abstract void AddIndexer(IndexerDefinition indexer);
|
||||||
public abstract void UpdateIndexer(IndexerDefinition indexer);
|
public abstract void UpdateIndexer(IndexerDefinition indexer);
|
||||||
public abstract void RemoveIndexer(int indexerId);
|
public abstract void RemoveIndexer(int indexerId);
|
||||||
public abstract void SyncIndexers();
|
|
||||||
|
|
||||||
public virtual object RequestAction(string action, IDictionary<string, string> query)
|
public virtual object RequestAction(string action, IDictionary<string, string> query)
|
||||||
{
|
{
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using NLog;
|
using NLog;
|
||||||
@@ -17,13 +18,17 @@ namespace NzbDrone.Core.Applications
|
|||||||
IExecute<ApplicationIndexerSyncCommand>
|
IExecute<ApplicationIndexerSyncCommand>
|
||||||
{
|
{
|
||||||
private readonly IApplicationFactory _applicationsFactory;
|
private readonly IApplicationFactory _applicationsFactory;
|
||||||
|
private readonly IAppIndexerMapService _appIndexerMapService;
|
||||||
|
private readonly IIndexerFactory _indexerFactory;
|
||||||
private readonly IApplicationStatusService _applicationStatusService;
|
private readonly IApplicationStatusService _applicationStatusService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public ApplicationService(IApplicationFactory applicationsFactory, IApplicationStatusService applicationStatusService, Logger logger)
|
public ApplicationService(IApplicationFactory applicationsFactory, IApplicationStatusService applicationStatusService, IAppIndexerMapService appIndexerMapService, IIndexerFactory indexerFactory, Logger logger)
|
||||||
{
|
{
|
||||||
_applicationsFactory = applicationsFactory;
|
_applicationsFactory = applicationsFactory;
|
||||||
_applicationStatusService = applicationStatusService;
|
_applicationStatusService = applicationStatusService;
|
||||||
|
_appIndexerMapService = appIndexerMapService;
|
||||||
|
_indexerFactory = indexerFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +41,7 @@ namespace NzbDrone.Core.Applications
|
|||||||
{
|
{
|
||||||
var app = _applicationsFactory.GetInstance(appDefinition);
|
var app = _applicationsFactory.GetInstance(appDefinition);
|
||||||
|
|
||||||
ExecuteAction(a => a.SyncIndexers(), app);
|
SyncIndexers(new List<IApplication> { app });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +81,28 @@ namespace NzbDrone.Core.Applications
|
|||||||
{
|
{
|
||||||
var enabledApps = _applicationsFactory.SyncEnabled();
|
var enabledApps = _applicationsFactory.SyncEnabled();
|
||||||
|
|
||||||
foreach (var app in enabledApps)
|
SyncIndexers(enabledApps);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SyncIndexers(List<IApplication> applications)
|
||||||
|
{
|
||||||
|
var indexers = _indexerFactory.Enabled();
|
||||||
|
|
||||||
|
foreach (var app in applications)
|
||||||
{
|
{
|
||||||
ExecuteAction(a => a.SyncIndexers(), app);
|
var indexerMappings = _appIndexerMapService.GetMappingsForApp(app.Definition.Id);
|
||||||
|
|
||||||
|
foreach (var indexer in indexers)
|
||||||
|
{
|
||||||
|
if (indexerMappings.Any(x => x.IndexerId == indexer.Definition.Id))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var definition = (IndexerDefinition)indexer.Definition;
|
||||||
|
|
||||||
|
ExecuteAction(a => a.AddIndexer(definition), app);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.ThingiProvider;
|
using NzbDrone.Core.ThingiProvider;
|
||||||
|
|
||||||
@@ -5,7 +6,6 @@ namespace NzbDrone.Core.Applications
|
|||||||
{
|
{
|
||||||
public interface IApplication : IProvider
|
public interface IApplication : IProvider
|
||||||
{
|
{
|
||||||
void SyncIndexers();
|
|
||||||
void AddIndexer(IndexerDefinition indexer);
|
void AddIndexer(IndexerDefinition indexer);
|
||||||
void UpdateIndexer(IndexerDefinition indexer);
|
void UpdateIndexer(IndexerDefinition indexer);
|
||||||
void RemoveIndexer(int indexerId);
|
void RemoveIndexer(int indexerId);
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
@@ -13,14 +14,12 @@ namespace NzbDrone.Core.Applications.Lidarr
|
|||||||
public override string Name => "Lidarr";
|
public override string Name => "Lidarr";
|
||||||
|
|
||||||
private readonly ILidarrV1Proxy _lidarrV1Proxy;
|
private readonly ILidarrV1Proxy _lidarrV1Proxy;
|
||||||
private readonly IIndexerFactory _indexerFactory;
|
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public Lidarr(ILidarrV1Proxy lidarrV1Proxy, IIndexerFactory indexerFactory, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
public Lidarr(ILidarrV1Proxy lidarrV1Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
||||||
: base(appIndexerMapService, logger)
|
: base(appIndexerMapService, logger)
|
||||||
{
|
{
|
||||||
_lidarrV1Proxy = lidarrV1Proxy;
|
_lidarrV1Proxy = lidarrV1Proxy;
|
||||||
_indexerFactory = indexerFactory;
|
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,42 +64,6 @@ namespace NzbDrone.Core.Applications.Lidarr
|
|||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SyncIndexers()
|
|
||||||
{
|
|
||||||
// Pull Schema so we get the field mapping right
|
|
||||||
var schema = _lidarrV1Proxy.GetIndexerSchema(Settings);
|
|
||||||
var newznab = schema.Where(i => i.Implementation == "Newznab").First();
|
|
||||||
var torznab = schema.Where(i => i.Implementation == "Torznab").First();
|
|
||||||
|
|
||||||
// Pull existing indexers from Lidarr
|
|
||||||
var indexers = _lidarrV1Proxy.GetIndexers(Settings);
|
|
||||||
|
|
||||||
//Pull all local indexers (TODO only those that support movie categories.)
|
|
||||||
var prowlarrIndexers = _indexerFactory.Enabled();
|
|
||||||
|
|
||||||
//Pull mapping so we can check the mapping to see what already exists.
|
|
||||||
var indexerMappings = _appIndexerMapService.GetMappingsForApp(Definition.Id);
|
|
||||||
|
|
||||||
//Add new Indexers
|
|
||||||
foreach (var indexer in prowlarrIndexers)
|
|
||||||
{
|
|
||||||
//Don't add if it already exists in our mappings for this app (TODO should we check that it exists remote?)
|
|
||||||
if (indexerMappings.Any(x => x.IndexerId == indexer.Definition.Id))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var definition = (IndexerDefinition)indexer.Definition;
|
|
||||||
|
|
||||||
var lidarrIndexer = BuildLidarrIndexer(definition, definition.Protocol == DownloadProtocol.Usenet ? newznab : torznab);
|
|
||||||
|
|
||||||
var remoteIndexer = _lidarrV1Proxy.AddIndexer(lidarrIndexer, Settings);
|
|
||||||
_appIndexerMapService.Insert(new AppIndexerMap { AppId = Definition.Id, IndexerId = definition.Id, RemoteIndexerId = remoteIndexer.Id });
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete Indexers that need Deleting.
|
|
||||||
}
|
|
||||||
|
|
||||||
private LidarrIndexer BuildLidarrIndexer(IndexerDefinition indexer, LidarrIndexer schema)
|
private LidarrIndexer BuildLidarrIndexer(IndexerDefinition indexer, LidarrIndexer schema)
|
||||||
{
|
{
|
||||||
var lidarrIndexer = new LidarrIndexer
|
var lidarrIndexer = new LidarrIndexer
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
@@ -13,14 +14,12 @@ namespace NzbDrone.Core.Applications.Radarr
|
|||||||
public override string Name => "Radarr";
|
public override string Name => "Radarr";
|
||||||
|
|
||||||
private readonly IRadarrV3Proxy _radarrV3Proxy;
|
private readonly IRadarrV3Proxy _radarrV3Proxy;
|
||||||
private readonly IIndexerFactory _indexerFactory;
|
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public Radarr(IRadarrV3Proxy radarrV3Proxy, IIndexerFactory indexerFactory, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
public Radarr(IRadarrV3Proxy radarrV3Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
||||||
: base(appIndexerMapService, logger)
|
: base(appIndexerMapService, logger)
|
||||||
{
|
{
|
||||||
_radarrV3Proxy = radarrV3Proxy;
|
_radarrV3Proxy = radarrV3Proxy;
|
||||||
_indexerFactory = indexerFactory;
|
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,42 +64,6 @@ namespace NzbDrone.Core.Applications.Radarr
|
|||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SyncIndexers()
|
|
||||||
{
|
|
||||||
// Pull Schema so we get the field mapping right
|
|
||||||
var schema = _radarrV3Proxy.GetIndexerSchema(Settings);
|
|
||||||
var newznab = schema.Where(i => i.Implementation == "Newznab").First();
|
|
||||||
var torznab = schema.Where(i => i.Implementation == "Torznab").First();
|
|
||||||
|
|
||||||
// Pull existing indexers from Radarr
|
|
||||||
var indexers = _radarrV3Proxy.GetIndexers(Settings);
|
|
||||||
|
|
||||||
//Pull all local indexers (TODO only those that support movie categories.)
|
|
||||||
var prowlarrIndexers = _indexerFactory.Enabled();
|
|
||||||
|
|
||||||
//Pull mapping so we can check the mapping to see what already exists.
|
|
||||||
var indexerMappings = _appIndexerMapService.GetMappingsForApp(Definition.Id);
|
|
||||||
|
|
||||||
//Add new Indexers
|
|
||||||
foreach (var indexer in prowlarrIndexers)
|
|
||||||
{
|
|
||||||
//Don't add if it already exists in our mappings for this app (TODO should we check that it exists remote?)
|
|
||||||
if (indexerMappings.Any(x => x.IndexerId == indexer.Definition.Id))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var definition = (IndexerDefinition)indexer.Definition;
|
|
||||||
|
|
||||||
var radarrIndexer = BuildRadarrIndexer(definition, definition.Protocol == DownloadProtocol.Usenet ? newznab : torznab);
|
|
||||||
|
|
||||||
var remoteIndexer = _radarrV3Proxy.AddIndexer(radarrIndexer, Settings);
|
|
||||||
_appIndexerMapService.Insert(new AppIndexerMap { AppId = Definition.Id, IndexerId = definition.Id, RemoteIndexerId = remoteIndexer.Id });
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete Indexers that need Deleting.
|
|
||||||
}
|
|
||||||
|
|
||||||
private RadarrIndexer BuildRadarrIndexer(IndexerDefinition indexer, RadarrIndexer schema)
|
private RadarrIndexer BuildRadarrIndexer(IndexerDefinition indexer, RadarrIndexer schema)
|
||||||
{
|
{
|
||||||
var radarrIndexer = new RadarrIndexer
|
var radarrIndexer = new RadarrIndexer
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
@@ -13,14 +14,12 @@ namespace NzbDrone.Core.Applications.Readarr
|
|||||||
public override string Name => "Readarr";
|
public override string Name => "Readarr";
|
||||||
|
|
||||||
private readonly IReadarrV1Proxy _readarrV1Proxy;
|
private readonly IReadarrV1Proxy _readarrV1Proxy;
|
||||||
private readonly IIndexerFactory _indexerFactory;
|
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public Readarr(IReadarrV1Proxy readarrV1Proxy, IIndexerFactory indexerFactory, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
public Readarr(IReadarrV1Proxy readarrV1Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
||||||
: base(appIndexerMapService, logger)
|
: base(appIndexerMapService, logger)
|
||||||
{
|
{
|
||||||
_readarrV1Proxy = readarrV1Proxy;
|
_readarrV1Proxy = readarrV1Proxy;
|
||||||
_indexerFactory = indexerFactory;
|
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,42 +64,6 @@ namespace NzbDrone.Core.Applications.Readarr
|
|||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SyncIndexers()
|
|
||||||
{
|
|
||||||
// Pull Schema so we get the field mapping right
|
|
||||||
var schema = _readarrV1Proxy.GetIndexerSchema(Settings);
|
|
||||||
var newznab = schema.Where(i => i.Implementation == "Newznab").First();
|
|
||||||
var torznab = schema.Where(i => i.Implementation == "Torznab").First();
|
|
||||||
|
|
||||||
// Pull existing indexers from Readarr
|
|
||||||
var indexers = _readarrV1Proxy.GetIndexers(Settings);
|
|
||||||
|
|
||||||
//Pull all local indexers (TODO only those that support movie categories.)
|
|
||||||
var prowlarrIndexers = _indexerFactory.Enabled();
|
|
||||||
|
|
||||||
//Pull mapping so we can check the mapping to see what already exists.
|
|
||||||
var indexerMappings = _appIndexerMapService.GetMappingsForApp(Definition.Id);
|
|
||||||
|
|
||||||
//Add new Indexers
|
|
||||||
foreach (var indexer in prowlarrIndexers)
|
|
||||||
{
|
|
||||||
//Don't add if it already exists in our mappings for this app (TODO should we check that it exists remote?)
|
|
||||||
if (indexerMappings.Any(x => x.IndexerId == indexer.Definition.Id))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var definition = (IndexerDefinition)indexer.Definition;
|
|
||||||
|
|
||||||
var readarrIndexer = BuildReadarrIndexer(definition, definition.Protocol == DownloadProtocol.Usenet ? newznab : torznab);
|
|
||||||
|
|
||||||
var remoteIndexer = _readarrV1Proxy.AddIndexer(readarrIndexer, Settings);
|
|
||||||
_appIndexerMapService.Insert(new AppIndexerMap { AppId = Definition.Id, IndexerId = definition.Id, RemoteIndexerId = remoteIndexer.Id });
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete Indexers that need Deleting.
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReadarrIndexer BuildReadarrIndexer(IndexerDefinition indexer, ReadarrIndexer schema)
|
private ReadarrIndexer BuildReadarrIndexer(IndexerDefinition indexer, ReadarrIndexer schema)
|
||||||
{
|
{
|
||||||
var readarrIndexer = new ReadarrIndexer
|
var readarrIndexer = new ReadarrIndexer
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
@@ -13,14 +14,12 @@ namespace NzbDrone.Core.Applications.Sonarr
|
|||||||
public override string Name => "Sonarr";
|
public override string Name => "Sonarr";
|
||||||
|
|
||||||
private readonly ISonarrV3Proxy _sonarrV3Proxy;
|
private readonly ISonarrV3Proxy _sonarrV3Proxy;
|
||||||
private readonly IIndexerFactory _indexerFactory;
|
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public Sonarr(ISonarrV3Proxy sonarrV3Proxy, IIndexerFactory indexerFactory, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
public Sonarr(ISonarrV3Proxy sonarrV3Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger)
|
||||||
: base(appIndexerMapService, logger)
|
: base(appIndexerMapService, logger)
|
||||||
{
|
{
|
||||||
_sonarrV3Proxy = sonarrV3Proxy;
|
_sonarrV3Proxy = sonarrV3Proxy;
|
||||||
_indexerFactory = indexerFactory;
|
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,42 +64,6 @@ namespace NzbDrone.Core.Applications.Sonarr
|
|||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SyncIndexers()
|
|
||||||
{
|
|
||||||
// Pull Schema so we get the field mapping right
|
|
||||||
var schema = _sonarrV3Proxy.GetIndexerSchema(Settings);
|
|
||||||
var newznab = schema.Where(i => i.Implementation == "Newznab").First();
|
|
||||||
var torznab = schema.Where(i => i.Implementation == "Torznab").First();
|
|
||||||
|
|
||||||
// Pull existing indexers from Sonarr
|
|
||||||
var indexers = _sonarrV3Proxy.GetIndexers(Settings);
|
|
||||||
|
|
||||||
//Pull all local indexers (TODO only those that support movie categories.)
|
|
||||||
var prowlarrIndexers = _indexerFactory.Enabled();
|
|
||||||
|
|
||||||
//Pull mapping so we can check the mapping to see what already exists.
|
|
||||||
var indexerMappings = _appIndexerMapService.GetMappingsForApp(Definition.Id);
|
|
||||||
|
|
||||||
//Add new Indexers
|
|
||||||
foreach (var indexer in prowlarrIndexers)
|
|
||||||
{
|
|
||||||
//Don't add if it already exists in our mappings for this app (TODO should we check that it exists remote?)
|
|
||||||
if (indexerMappings.Any(x => x.IndexerId == indexer.Definition.Id))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var definition = (IndexerDefinition)indexer.Definition;
|
|
||||||
|
|
||||||
var sonarrIndexer = BuildSonarrIndexer(definition, definition.Protocol == DownloadProtocol.Usenet ? newznab : torznab);
|
|
||||||
|
|
||||||
var remoteIndexer = _sonarrV3Proxy.AddIndexer(sonarrIndexer, Settings);
|
|
||||||
_appIndexerMapService.Insert(new AppIndexerMap { AppId = Definition.Id, IndexerId = definition.Id, RemoteIndexerId = remoteIndexer.Id });
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete Indexers that need Deleting.
|
|
||||||
}
|
|
||||||
|
|
||||||
private SonarrIndexer BuildSonarrIndexer(IndexerDefinition indexer, SonarrIndexer schema)
|
private SonarrIndexer BuildSonarrIndexer(IndexerDefinition indexer, SonarrIndexer schema)
|
||||||
{
|
{
|
||||||
var sonarrIndexer = new SonarrIndexer
|
var sonarrIndexer = new SonarrIndexer
|
||||||
|
Reference in New Issue
Block a user