mirror of https://github.com/Radarr/Radarr
82 lines
3.1 KiB
C#
82 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NLog;
|
|
using NzbDrone.Core.Messaging.Events;
|
|
using NzbDrone.Core.ThingiProvider;
|
|
|
|
namespace NzbDrone.Core.ImportLists
|
|
{
|
|
public interface IImportListFactory : IProviderFactory<IImportList, ImportListDefinition>
|
|
{
|
|
List<IImportList> Enabled(bool filterBlockedImportLists = true);
|
|
List<IImportList> Discoverable();
|
|
}
|
|
|
|
public class ImportListFactory : ProviderFactory<IImportList, ImportListDefinition>, IImportListFactory
|
|
{
|
|
private readonly IImportListStatusService _importListStatusService;
|
|
private readonly Logger _logger;
|
|
|
|
public ImportListFactory(IImportListStatusService importListStatusService,
|
|
IImportListRepository providerRepository,
|
|
IEnumerable<IImportList> providers,
|
|
IServiceProvider container,
|
|
IEventAggregator eventAggregator,
|
|
Logger logger)
|
|
: base(providerRepository, providers, container, eventAggregator, logger)
|
|
{
|
|
_importListStatusService = importListStatusService;
|
|
_logger = logger;
|
|
}
|
|
|
|
protected override List<ImportListDefinition> Active()
|
|
{
|
|
return base.Active().Where(c => c.Enabled).ToList();
|
|
}
|
|
|
|
public override void SetProviderCharacteristics(IImportList provider, ImportListDefinition definition)
|
|
{
|
|
base.SetProviderCharacteristics(provider, definition);
|
|
|
|
definition.ListType = provider.ListType;
|
|
definition.MinRefreshInterval = provider.MinRefreshInterval;
|
|
}
|
|
|
|
public List<IImportList> Enabled(bool filterBlockedImportLists = true)
|
|
{
|
|
var enabledImportLists = GetAvailableProviders().Where(n => ((ImportListDefinition)n.Definition).Enabled);
|
|
|
|
if (filterBlockedImportLists)
|
|
{
|
|
return FilterBlockedImportLists(enabledImportLists).ToList();
|
|
}
|
|
|
|
return enabledImportLists.ToList();
|
|
}
|
|
|
|
public List<IImportList> Discoverable()
|
|
{
|
|
var enabledImportLists = GetAvailableProviders().Where(n => n.GetType() == typeof(RadarrList.RadarrListImport) || n.GetType() == typeof(TMDb.Popular.TMDbPopularImport));
|
|
|
|
return enabledImportLists.ToList();
|
|
}
|
|
|
|
private IEnumerable<IImportList> FilterBlockedImportLists(IEnumerable<IImportList> importLists)
|
|
{
|
|
var blockedImportLists = _importListStatusService.GetBlockedProviders().ToDictionary(v => v.ProviderId, v => v);
|
|
|
|
foreach (var importList in importLists)
|
|
{
|
|
if (blockedImportLists.TryGetValue(importList.Definition.Id, out var blockedImportListStatus))
|
|
{
|
|
_logger.Debug("Temporarily ignoring import list {0} till {1} due to recent failures.", importList.Definition.Name, blockedImportListStatus.DisabledTill.Value.ToLocalTime());
|
|
continue;
|
|
}
|
|
|
|
yield return importList;
|
|
}
|
|
}
|
|
}
|
|
}
|