parent
8c67a3bdee
commit
776143cc81
@ -0,0 +1,50 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Core.Download.TrackedDownloads;
|
||||||
|
using NzbDrone.Core.Indexers;
|
||||||
|
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Download;
|
||||||
|
|
||||||
|
public interface IRejectedImportService
|
||||||
|
{
|
||||||
|
bool Process(TrackedDownload trackedDownload, ImportResult importResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RejectedImportService : IRejectedImportService
|
||||||
|
{
|
||||||
|
private readonly ICachedIndexerSettingsProvider _cachedIndexerSettingsProvider;
|
||||||
|
|
||||||
|
public RejectedImportService(ICachedIndexerSettingsProvider cachedIndexerSettingsProvider)
|
||||||
|
{
|
||||||
|
_cachedIndexerSettingsProvider = cachedIndexerSettingsProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Process(TrackedDownload trackedDownload, ImportResult importResult)
|
||||||
|
{
|
||||||
|
if (importResult.Result != ImportResultType.Rejected || importResult.ImportDecision.LocalEpisode != null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var indexerSettings = _cachedIndexerSettingsProvider.GetSettings(trackedDownload.RemoteEpisode.Release.IndexerId);
|
||||||
|
var rejectionReason = importResult.ImportDecision.Rejections.FirstOrDefault()?.Reason;
|
||||||
|
|
||||||
|
if (rejectionReason == ImportRejectionReason.DangerousFile &&
|
||||||
|
indexerSettings.FailDownloads.Contains(FailDownloads.PotentiallyDangerous))
|
||||||
|
{
|
||||||
|
trackedDownload.Fail();
|
||||||
|
}
|
||||||
|
else if (rejectionReason == ImportRejectionReason.ExecutableFile &&
|
||||||
|
indexerSettings.FailDownloads.Contains(FailDownloads.Executables))
|
||||||
|
{
|
||||||
|
trackedDownload.Fail();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
trackedDownload.Warn(new TrackedDownloadStatusMessage(importResult.Errors.First(), new List<string>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Common.Cache;
|
||||||
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
using NzbDrone.Core.ThingiProvider.Events;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Indexers;
|
||||||
|
|
||||||
|
public interface ICachedIndexerSettingsProvider
|
||||||
|
{
|
||||||
|
CachedIndexerSettings GetSettings(int indexerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHandle<ProviderUpdatedEvent<IIndexer>>
|
||||||
|
{
|
||||||
|
private readonly IIndexerFactory _indexerFactory;
|
||||||
|
private readonly ICached<CachedIndexerSettings> _cache;
|
||||||
|
|
||||||
|
public CachedIndexerSettingsProvider(IIndexerFactory indexerFactory, ICacheManager cacheManager)
|
||||||
|
{
|
||||||
|
_indexerFactory = indexerFactory;
|
||||||
|
_cache = cacheManager.GetRollingCache<CachedIndexerSettings>(GetType(), "settingsByIndexer", TimeSpan.FromHours(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CachedIndexerSettings GetSettings(int indexerId)
|
||||||
|
{
|
||||||
|
if (indexerId == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _cache.Get(indexerId.ToString(), () => FetchIndexerSettings(indexerId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private CachedIndexerSettings FetchIndexerSettings(int indexerId)
|
||||||
|
{
|
||||||
|
var indexer = _indexerFactory.Get(indexerId);
|
||||||
|
var indexerSettings = indexer.Settings as IIndexerSettings;
|
||||||
|
|
||||||
|
if (indexerSettings == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var settings = new CachedIndexerSettings
|
||||||
|
{
|
||||||
|
FailDownloads = indexerSettings.FailDownloads.Select(f => (FailDownloads)f).ToHashSet()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (indexer.Settings is ITorrentIndexerSettings torrentIndexerSettings)
|
||||||
|
{
|
||||||
|
settings.SeedCriteriaSettings = torrentIndexerSettings.SeedCriteria;
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Handle(ProviderUpdatedEvent<IIndexer> message)
|
||||||
|
{
|
||||||
|
_cache.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CachedIndexerSettings
|
||||||
|
{
|
||||||
|
public HashSet<FailDownloads> FailDownloads { get; set; }
|
||||||
|
public SeedCriteriaSettings SeedCriteriaSettings { get; set; }
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using NzbDrone.Core.Annotations;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Indexers;
|
||||||
|
|
||||||
|
public enum FailDownloads
|
||||||
|
{
|
||||||
|
[FieldOption(Label = "Executables")]
|
||||||
|
Executables = 0,
|
||||||
|
|
||||||
|
[FieldOption(Label = "Potentially Dangerous")]
|
||||||
|
PotentiallyDangerous = 1
|
||||||
|
}
|
Loading…
Reference in new issue