mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-29 11:05:44 +00:00
96990eabb3
so we can have multiple newznab definitions.
31 lines
No EOL
923 B
C#
31 lines
No EOL
923 B
C#
using Newtonsoft.Json;
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
{
|
|
public interface IProviderIndexerSetting
|
|
{
|
|
TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new();
|
|
}
|
|
|
|
public class IndexerSettingProvider : IProviderIndexerSetting
|
|
{
|
|
private readonly IIndexerRepository _indexerRepository;
|
|
|
|
public IndexerSettingProvider(IIndexerRepository indexerRepository)
|
|
{
|
|
_indexerRepository = indexerRepository;
|
|
}
|
|
|
|
public TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new()
|
|
{
|
|
var indexerDef = _indexerRepository.Find(indexer.Name);
|
|
|
|
if (indexerDef == null || string.IsNullOrWhiteSpace(indexerDef.Settings))
|
|
{
|
|
return new TSetting();
|
|
}
|
|
|
|
return JsonConvert.DeserializeObject<TSetting>(indexerDef.Settings);
|
|
}
|
|
}
|
|
} |