mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-23 22:25:09 -04:00
Able to create new Newznab indexers
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Indexers.Newznab;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
|
||||
@@ -15,6 +16,7 @@ namespace NzbDrone.Core.Indexers
|
||||
public bool Enable { get; set; }
|
||||
public IIndexerSetting Settings { get; set; }
|
||||
public IIndexer Instance { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
}
|
||||
|
||||
public interface IIndexerService
|
||||
@@ -23,6 +25,7 @@ namespace NzbDrone.Core.Indexers
|
||||
List<IIndexer> GetAvailableIndexers();
|
||||
Indexer Get(string name);
|
||||
List<Indexer> Schema();
|
||||
Indexer Create(Indexer indexer);
|
||||
}
|
||||
|
||||
public class IndexerService : IIndexerService, IHandle<ApplicationStartedEvent>
|
||||
@@ -63,12 +66,29 @@ namespace NzbDrone.Core.Indexers
|
||||
newznab.Id = 1;
|
||||
newznab.Name = "Newznab";
|
||||
newznab.Settings = new NewznabSettings();
|
||||
newznab.Implementation = "Newznab";
|
||||
|
||||
indexers.Add(newznab);
|
||||
|
||||
return indexers;
|
||||
}
|
||||
|
||||
public Indexer Create(Indexer indexer)
|
||||
{
|
||||
var definition = new IndexerDefinition
|
||||
{
|
||||
Name = indexer.Name,
|
||||
Enable = indexer.Enable,
|
||||
Implementation = indexer.Implementation,
|
||||
Settings = Json.Serialize(indexer.Settings)
|
||||
};
|
||||
|
||||
definition = _indexerRepository.Insert(definition);
|
||||
indexer.Id = definition.Id;
|
||||
|
||||
return indexer;
|
||||
}
|
||||
|
||||
private Indexer ToIndexer(IndexerDefinition definition)
|
||||
{
|
||||
var indexer = new Indexer();
|
||||
@@ -76,6 +96,7 @@ namespace NzbDrone.Core.Indexers
|
||||
indexer.Enable = definition.Enable;
|
||||
indexer.Instance = GetInstance(definition);
|
||||
indexer.Name = definition.Name;
|
||||
indexer.Implementation = definition.Implementation;
|
||||
|
||||
if (indexer.Instance.GetType().GetMethod("ImportSettingsFromJson") != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user