Consolidate sync code to ApplicationService

This commit is contained in:
Qstick
2021-02-21 18:03:07 -05:00
parent 11a5d8c1f5
commit 10a999e270
7 changed files with 37 additions and 162 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
@@ -13,14 +14,12 @@ namespace NzbDrone.Core.Applications.Sonarr
public override string Name => "Sonarr";
private readonly ISonarrV3Proxy _sonarrV3Proxy;
private readonly IIndexerFactory _indexerFactory;
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)
{
_sonarrV3Proxy = sonarrV3Proxy;
_indexerFactory = indexerFactory;
_configFileProvider = configFileProvider;
}
@@ -65,42 +64,6 @@ namespace NzbDrone.Core.Applications.Sonarr
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)
{
var sonarrIndexer = new SonarrIndexer