New: Nested Settings and Seed Ratio Setting (#379)
* New: Nested Settings and Seed Ratio Setting * Fixed: Sonarr related variable namingpull/387/head
parent
dabb9bc18a
commit
089d213816
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Lidarr.Http.ClientSchema
|
||||||
|
{
|
||||||
|
public class FieldMapping
|
||||||
|
{
|
||||||
|
public Field Field { get; set; }
|
||||||
|
public Type PropertyType { get; set; }
|
||||||
|
public Func<object, object> GetterFunc { get; set; }
|
||||||
|
public Action<object, object> SetterFunc { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
|
using NzbDrone.Core.Indexers;
|
||||||
|
using NzbDrone.Core.Indexers.Torznab;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.IndexerTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class SeedConfigProviderFixture : CoreTest<SeedConfigProvider>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_not_return_config_for_non_existent_indexer()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IIndexerFactory>()
|
||||||
|
.Setup(v => v.Get(It.IsAny<int>()))
|
||||||
|
.Throws(new ModelNotFoundException(typeof(IndexerDefinition), 0));
|
||||||
|
|
||||||
|
var result = Subject.GetSeedConfiguration(new RemoteAlbum
|
||||||
|
{
|
||||||
|
Release = new ReleaseInfo
|
||||||
|
{
|
||||||
|
DownloadProtocol = DownloadProtocol.Torrent,
|
||||||
|
IndexerId = 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
result.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_discography_time_for_discography_packs()
|
||||||
|
{
|
||||||
|
var settings = new TorznabSettings();
|
||||||
|
settings.SeedCriteria.DiscographySeedTime = 10;
|
||||||
|
|
||||||
|
Mocker.GetMock<IIndexerFactory>()
|
||||||
|
.Setup(v => v.Get(It.IsAny<int>()))
|
||||||
|
.Returns(new IndexerDefinition
|
||||||
|
{
|
||||||
|
Settings = settings
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = Subject.GetSeedConfiguration(new RemoteAlbum
|
||||||
|
{
|
||||||
|
Release = new ReleaseInfo()
|
||||||
|
{
|
||||||
|
DownloadProtocol = DownloadProtocol.Torrent,
|
||||||
|
IndexerId = 1
|
||||||
|
},
|
||||||
|
ParsedAlbumInfo = new ParsedAlbumInfo
|
||||||
|
{
|
||||||
|
Discography = true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.SeedTime.Should().Be(TimeSpan.FromMinutes(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
|
using NzbDrone.Core.Download.Clients;
|
||||||
|
using NzbDrone.Core.Indexers;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Indexers
|
||||||
|
{
|
||||||
|
public interface ISeedConfigProvider
|
||||||
|
{
|
||||||
|
TorrentSeedConfiguration GetSeedConfiguration(RemoteAlbum release);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SeedConfigProvider : ISeedConfigProvider
|
||||||
|
{
|
||||||
|
private readonly IIndexerFactory _indexerFactory;
|
||||||
|
|
||||||
|
public SeedConfigProvider(IIndexerFactory indexerFactory)
|
||||||
|
{
|
||||||
|
_indexerFactory = indexerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TorrentSeedConfiguration GetSeedConfiguration(RemoteAlbum remoteAlbum)
|
||||||
|
{
|
||||||
|
if (remoteAlbum.Release.DownloadProtocol != DownloadProtocol.Torrent)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remoteAlbum.Release.IndexerId == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var indexer = _indexerFactory.Get(remoteAlbum.Release.IndexerId);
|
||||||
|
var torrentIndexerSettings = indexer.Settings as ITorrentIndexerSettings;
|
||||||
|
|
||||||
|
if (torrentIndexerSettings != null && torrentIndexerSettings.SeedCriteria != null)
|
||||||
|
{
|
||||||
|
var seedConfig = new TorrentSeedConfiguration
|
||||||
|
{
|
||||||
|
Ratio = torrentIndexerSettings.SeedCriteria.SeedRatio
|
||||||
|
};
|
||||||
|
|
||||||
|
var seedTime = remoteAlbum.ParsedAlbumInfo.Discography ? torrentIndexerSettings.SeedCriteria.DiscographySeedTime : torrentIndexerSettings.SeedCriteria.SeedTime;
|
||||||
|
if (seedTime.HasValue)
|
||||||
|
{
|
||||||
|
seedConfig.SeedTime = TimeSpan.FromMinutes(seedTime.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return seedConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ModelNotFoundException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using FluentValidation;
|
||||||
|
using NzbDrone.Core.Annotations;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Indexers
|
||||||
|
{
|
||||||
|
public class SeedCriteriaSettingsValidator : AbstractValidator<SeedCriteriaSettings>
|
||||||
|
{
|
||||||
|
public SeedCriteriaSettingsValidator(double seedRatioMinimum = 0.0, int seedTimeMinimum = 0, int discographySeedTimeMinimum = 0)
|
||||||
|
{
|
||||||
|
RuleFor(c => c.SeedRatio).GreaterThan(0.0)
|
||||||
|
.When(c => c.SeedRatio.HasValue)
|
||||||
|
.AsWarning().WithMessage("Should be greater than zero");
|
||||||
|
|
||||||
|
RuleFor(c => c.SeedTime).GreaterThan(0)
|
||||||
|
.When(c => c.SeedTime.HasValue)
|
||||||
|
.AsWarning().WithMessage("Should be greater than zero");
|
||||||
|
|
||||||
|
RuleFor(c => c.DiscographySeedTime).GreaterThan(0)
|
||||||
|
.When(c => c.DiscographySeedTime.HasValue)
|
||||||
|
.AsWarning().WithMessage("Should be greater than zero");
|
||||||
|
|
||||||
|
if (seedRatioMinimum != 0.0)
|
||||||
|
{
|
||||||
|
RuleFor(c => c.SeedRatio).GreaterThanOrEqualTo(seedRatioMinimum)
|
||||||
|
.When(c => c.SeedRatio > 0.0)
|
||||||
|
.AsWarning()
|
||||||
|
.WithMessage($"Under {seedRatioMinimum} leads to H&R");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seedTimeMinimum != 0)
|
||||||
|
{
|
||||||
|
RuleFor(c => c.SeedTime).GreaterThanOrEqualTo(seedTimeMinimum)
|
||||||
|
.When(c => c.SeedTime > 0)
|
||||||
|
.AsWarning()
|
||||||
|
.WithMessage($"Under {seedTimeMinimum} leads to H&R");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discographySeedTimeMinimum != 0)
|
||||||
|
{
|
||||||
|
RuleFor(c => c.DiscographySeedTime).GreaterThanOrEqualTo(discographySeedTimeMinimum)
|
||||||
|
.When(c => c.DiscographySeedTime > 0)
|
||||||
|
.AsWarning()
|
||||||
|
.WithMessage($"Under {discographySeedTimeMinimum} leads to H&R");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SeedCriteriaSettings
|
||||||
|
{
|
||||||
|
private static readonly SeedCriteriaSettingsValidator Validator = new SeedCriteriaSettingsValidator();
|
||||||
|
|
||||||
|
[FieldDefinition(0, Type = FieldType.Textbox, Label = "Seed Ratio", HelpText = "The ratio a torrent should reach before stopping, empty is download client's default", Advanced = true)]
|
||||||
|
public double? SeedRatio { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(1, Type = FieldType.Textbox, Label = "Seed Time", Unit = "minutes", HelpText = "The time a torrent should be seeded before stopping, empty is download client's default", Advanced = true)]
|
||||||
|
public int? SeedTime { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(2, Type = FieldType.Textbox, Label = "Discography Seed Time", Unit = "minutes", HelpText = "The time a torrent should be seeded before stopping, empty is download client's default", Advanced = true)]
|
||||||
|
public int? DiscographySeedTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue