mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-26 20:11:49 +02:00
New: XBMC Metadata (Frodo+)
This commit is contained in:
58
src/NzbDrone.Core/MetaData/MetadataFactory.cs
Normal file
58
src/NzbDrone.Core/MetaData/MetadataFactory.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Metadata.Consumers.Fake;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Metadata
|
||||
{
|
||||
public interface IMetadataFactory : IProviderFactory<IMetadata, MetadataDefinition>
|
||||
{
|
||||
List<IMetadata> Enabled();
|
||||
}
|
||||
|
||||
public class MetadataFactory : ProviderFactory<IMetadata, MetadataDefinition>, IMetadataFactory
|
||||
{
|
||||
private readonly IMetadataRepository _providerRepository;
|
||||
|
||||
public MetadataFactory(IMetadataRepository providerRepository, IEnumerable<IMetadata> providers, IContainer container, Logger logger)
|
||||
: base(providerRepository, providers, container, logger)
|
||||
{
|
||||
_providerRepository = providerRepository;
|
||||
}
|
||||
|
||||
protected override void InitializeProviders()
|
||||
{
|
||||
var definitions = new List<MetadataDefinition>();
|
||||
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
if (provider.GetType() == typeof(FakeMetadata)) continue;;
|
||||
|
||||
definitions.Add(new MetadataDefinition
|
||||
{
|
||||
Enable = false,
|
||||
Name = provider.GetType().Name,
|
||||
Implementation = provider.GetType().Name,
|
||||
Settings = (IProviderConfig)Activator.CreateInstance(provider.ConfigContract)
|
||||
});
|
||||
}
|
||||
|
||||
var currentProviders = All();
|
||||
|
||||
var newProviders = definitions.Where(def => currentProviders.All(c => c.Implementation != def.Implementation)).ToList();
|
||||
|
||||
if (newProviders.Any())
|
||||
{
|
||||
_providerRepository.InsertMany(newProviders.Cast<MetadataDefinition>().ToList());
|
||||
}
|
||||
}
|
||||
|
||||
public List<IMetadata> Enabled()
|
||||
{
|
||||
return GetAvailableProviders().Where(n => ((MetadataDefinition)n.Definition).Enable).ToList();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user