1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-27 22:57:09 -04:00

New: Removing rtorrent downloads when seeding criteria have been met

(cherry picked from commit 411be4d0116f0739bb9c71235312d0c5a26dd3a2)

Fixes: #6320
Fixes: #5219
This commit is contained in:
leaty
2020-03-19 15:47:25 +01:00
committed by Qstick
parent dd80a64560
commit 1c0621af0a
5 changed files with 184 additions and 30 deletions
@@ -1,6 +1,8 @@
using System;
using NzbDrone.Common.Cache;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Indexers
@@ -8,15 +10,18 @@ namespace NzbDrone.Core.Indexers
public interface ISeedConfigProvider
{
TorrentSeedConfiguration GetSeedConfiguration(RemoteMovie release);
TorrentSeedConfiguration GetSeedConfiguration(int indexerId);
}
public class SeedConfigProvider : ISeedConfigProvider
public class SeedConfigProvider : ISeedConfigProvider, IHandle<IndexerSettingUpdatedEvent>
{
private readonly IIndexerFactory _indexerFactory;
private readonly ICached<SeedCriteriaSettings> _cache;
public SeedConfigProvider(IIndexerFactory indexerFactory)
public SeedConfigProvider(IIndexerFactory indexerFactory, ICacheManager cacheManager)
{
_indexerFactory = indexerFactory;
_cache = cacheManager.GetRollingCache<SeedCriteriaSettings>(GetType(), "criteriaByIndexer", TimeSpan.FromHours(1));
}
public TorrentSeedConfiguration GetSeedConfiguration(RemoteMovie remoteMovie)
@@ -31,33 +36,56 @@ namespace NzbDrone.Core.Indexers
return null;
}
return GetSeedConfiguration(remoteMovie.Release.IndexerId);
}
public TorrentSeedConfiguration GetSeedConfiguration(int indexerId)
{
if (indexerId == 0)
{
return null;
}
var seedCriteria = _cache.Get(indexerId.ToString(), () => FetchSeedCriteria(indexerId));
if (seedCriteria == null)
{
return null;
}
var seedConfig = new TorrentSeedConfiguration
{
Ratio = seedCriteria.SeedRatio
};
var seedTime = seedCriteria.SeedTime;
if (seedTime.HasValue)
{
seedConfig.SeedTime = TimeSpan.FromMinutes(seedTime.Value);
}
return seedConfig;
}
private SeedCriteriaSettings FetchSeedCriteria(int indexerId)
{
try
{
var indexer = _indexerFactory.Get(remoteMovie.Release.IndexerId);
var indexer = _indexerFactory.Get(indexerId);
var torrentIndexerSettings = indexer.Settings as ITorrentIndexerSettings;
if (torrentIndexerSettings != null && torrentIndexerSettings.SeedCriteria != null)
{
var seedConfig = new TorrentSeedConfiguration
{
Ratio = torrentIndexerSettings.SeedCriteria.SeedRatio
};
var seedTime = torrentIndexerSettings.SeedCriteria.SeedTime;
if (seedTime.HasValue)
{
seedConfig.SeedTime = TimeSpan.FromMinutes(seedTime.Value);
}
return seedConfig;
}
return torrentIndexerSettings?.SeedCriteria;
}
catch (ModelNotFoundException)
{
return null;
}
}
return null;
public void Handle(IndexerSettingUpdatedEvent message)
{
_cache.Clear();
}
}
}