Fixed SeedConfigProvider failing on ReleasePush.
This commit is contained in:
parent
59e69c1839
commit
5d674a07f7
|
@ -1,13 +1,16 @@
|
||||||
using Nancy;
|
using System.Collections.Generic;
|
||||||
using Nancy.ModelBinding;
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
using Nancy;
|
||||||
|
using Nancy.ModelBinding;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Api.Extensions;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.DecisionEngine;
|
using NzbDrone.Core.DecisionEngine;
|
||||||
using NzbDrone.Core.Download;
|
using NzbDrone.Core.Download;
|
||||||
using System.Collections.Generic;
|
using NzbDrone.Core.Indexers;
|
||||||
using System.Linq;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Api.Extensions;
|
|
||||||
using NLog;
|
|
||||||
|
|
||||||
namespace NzbDrone.Api.Indexers
|
namespace NzbDrone.Api.Indexers
|
||||||
{
|
{
|
||||||
|
@ -15,14 +18,17 @@ namespace NzbDrone.Api.Indexers
|
||||||
{
|
{
|
||||||
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
||||||
private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
|
private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
|
||||||
|
private readonly IIndexerFactory _indexerFactory;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public ReleasePushModule(IMakeDownloadDecision downloadDecisionMaker,
|
public ReleasePushModule(IMakeDownloadDecision downloadDecisionMaker,
|
||||||
IProcessDownloadDecisions downloadDecisionProcessor,
|
IProcessDownloadDecisions downloadDecisionProcessor,
|
||||||
|
IIndexerFactory indexerFactory,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_downloadDecisionMaker = downloadDecisionMaker;
|
_downloadDecisionMaker = downloadDecisionMaker;
|
||||||
_downloadDecisionProcessor = downloadDecisionProcessor;
|
_downloadDecisionProcessor = downloadDecisionProcessor;
|
||||||
|
_indexerFactory = indexerFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
Post["/push"] = x => ProcessRelease(this.Bind<ReleaseResource>());
|
Post["/push"] = x => ProcessRelease(this.Bind<ReleaseResource>());
|
||||||
|
@ -41,10 +47,47 @@ namespace NzbDrone.Api.Indexers
|
||||||
|
|
||||||
info.Guid = "PUSH-" + info.DownloadUrl;
|
info.Guid = "PUSH-" + info.DownloadUrl;
|
||||||
|
|
||||||
|
ResolveIndexer(info);
|
||||||
|
|
||||||
var decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info });
|
var decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info });
|
||||||
_downloadDecisionProcessor.ProcessDecisions(decisions);
|
_downloadDecisionProcessor.ProcessDecisions(decisions);
|
||||||
|
|
||||||
return MapDecisions(decisions).First().AsResponse();
|
return MapDecisions(decisions).First().AsResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResolveIndexer(ReleaseInfo release)
|
||||||
|
{
|
||||||
|
if (release.IndexerId == 0 && release.Indexer.IsNotNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
var indexer = _indexerFactory.All().FirstOrDefault(v => v.Name == release.Indexer);
|
||||||
|
if (indexer != null)
|
||||||
|
{
|
||||||
|
release.IndexerId = indexer.Id;
|
||||||
|
_logger.Debug("Push Release {0} associated with indexer {1} - {2}.", release.Title, release.IndexerId, release.Indexer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Debug("Push Release {0} not associated with unknown indexer {1}.", release.Title, release.Indexer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (release.IndexerId != 0 && release.Indexer.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var indexer = _indexerFactory.Get(release.IndexerId);
|
||||||
|
release.Indexer = indexer.Name;
|
||||||
|
_logger.Debug("Push Release {0} associated with indexer {1} - {2}.", release.Title, release.IndexerId, release.Indexer);
|
||||||
|
}
|
||||||
|
catch (ModelNotFoundException)
|
||||||
|
{
|
||||||
|
_logger.Debug("Push Release {0} not associated with unknown indexer {0}.", release.Title, release.IndexerId);
|
||||||
|
release.IndexerId = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Debug("Push Release {0} not associated with an indexer.", release.Title);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 RemoteEpisode
|
||||||
|
{
|
||||||
|
Release = new ReleaseInfo()
|
||||||
|
{
|
||||||
|
DownloadProtocol = DownloadProtocol.Torrent,
|
||||||
|
IndexerId = 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
result.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_season_time_for_season_packs()
|
||||||
|
{
|
||||||
|
var settings = new TorznabSettings();
|
||||||
|
settings.SeedCriteria.SeasonPackSeedTime = 10;
|
||||||
|
|
||||||
|
Mocker.GetMock<IIndexerFactory>()
|
||||||
|
.Setup(v => v.Get(It.IsAny<int>()))
|
||||||
|
.Returns(new IndexerDefinition
|
||||||
|
{
|
||||||
|
Settings = settings
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = Subject.GetSeedConfiguration(new RemoteEpisode
|
||||||
|
{
|
||||||
|
Release = new ReleaseInfo()
|
||||||
|
{
|
||||||
|
DownloadProtocol = DownloadProtocol.Torrent,
|
||||||
|
IndexerId = 1
|
||||||
|
},
|
||||||
|
ParsedEpisodeInfo = new ParsedEpisodeInfo
|
||||||
|
{
|
||||||
|
FullSeason = true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
result.SeedTime.Should().Be(TimeSpan.FromMinutes(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -279,6 +279,7 @@
|
||||||
<Compile Include="IndexerTests\IntegrationTests\IndexerIntegrationTests.cs" />
|
<Compile Include="IndexerTests\IntegrationTests\IndexerIntegrationTests.cs" />
|
||||||
<Compile Include="IndexerTests\NewznabTests\NewznabCapabilitiesProviderFixture.cs" />
|
<Compile Include="IndexerTests\NewznabTests\NewznabCapabilitiesProviderFixture.cs" />
|
||||||
<Compile Include="IndexerTests\RarbgTests\RarbgFixture.cs" />
|
<Compile Include="IndexerTests\RarbgTests\RarbgFixture.cs" />
|
||||||
|
<Compile Include="IndexerTests\SeedConfigProviderFixture.cs" />
|
||||||
<Compile Include="IndexerTests\TorrentRssIndexerTests\TorrentRssParserFactoryFixture.cs" />
|
<Compile Include="IndexerTests\TorrentRssIndexerTests\TorrentRssParserFactoryFixture.cs" />
|
||||||
<Compile Include="IndexerTests\TorrentRssIndexerTests\TorrentRssSettingsDetectorFixture.cs" />
|
<Compile Include="IndexerTests\TorrentRssIndexerTests\TorrentRssSettingsDetectorFixture.cs" />
|
||||||
<Compile Include="IndexerTests\TorznabTests\TorznabFixture.cs" />
|
<Compile Include="IndexerTests\TorznabTests\TorznabFixture.cs" />
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
using System;
|
|
||||||
using NzbDrone.Core.Download.Clients;
|
|
||||||
using NzbDrone.Core.Indexers;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Configuration
|
|
||||||
{
|
|
||||||
public interface ISeedConfigProvider
|
|
||||||
{
|
|
||||||
TorrentSeedConfiguration GetSeedConfiguration(RemoteEpisode release);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SeedConfigProvider: ISeedConfigProvider
|
|
||||||
{
|
|
||||||
private readonly IIndexerFactory _indexerFactory;
|
|
||||||
|
|
||||||
public SeedConfigProvider(IIndexerFactory indexerFactory)
|
|
||||||
{
|
|
||||||
_indexerFactory = indexerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TorrentSeedConfiguration GetSeedConfiguration(RemoteEpisode remoteEpisode)
|
|
||||||
{
|
|
||||||
if (remoteEpisode.Release.DownloadProtocol != DownloadProtocol.Torrent) return null;
|
|
||||||
|
|
||||||
var indexer = _indexerFactory.Get(remoteEpisode.Release.IndexerId);
|
|
||||||
var torrentIndexerSettings = indexer?.Settings as ITorrentIndexerSettings;
|
|
||||||
|
|
||||||
if (torrentIndexerSettings != null)
|
|
||||||
{
|
|
||||||
var seedConfig = new TorrentSeedConfiguration
|
|
||||||
{
|
|
||||||
Ratio = torrentIndexerSettings.SeedCriteria.SeedRatio
|
|
||||||
};
|
|
||||||
|
|
||||||
var seedTime = remoteEpisode.ParsedEpisodeInfo.FullSeason ? torrentIndexerSettings.SeedCriteria.SeasonPackSeedTime : torrentIndexerSettings.SeedCriteria.SeedTime;
|
|
||||||
if (seedTime.HasValue)
|
|
||||||
{
|
|
||||||
seedConfig.SeedTime = TimeSpan.FromMinutes(seedTime.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return seedConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
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(RemoteEpisode release);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SeedConfigProvider : ISeedConfigProvider
|
||||||
|
{
|
||||||
|
private readonly IIndexerFactory _indexerFactory;
|
||||||
|
|
||||||
|
public SeedConfigProvider(IIndexerFactory indexerFactory)
|
||||||
|
{
|
||||||
|
_indexerFactory = indexerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TorrentSeedConfiguration GetSeedConfiguration(RemoteEpisode remoteEpisode)
|
||||||
|
{
|
||||||
|
if (remoteEpisode.Release.DownloadProtocol != DownloadProtocol.Torrent) return null;
|
||||||
|
if (remoteEpisode.Release.IndexerId == 0) return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var indexer = _indexerFactory.Get(remoteEpisode.Release.IndexerId);
|
||||||
|
var torrentIndexerSettings = indexer.Settings as ITorrentIndexerSettings;
|
||||||
|
|
||||||
|
if (torrentIndexerSettings != null && torrentIndexerSettings.SeedCriteria != null)
|
||||||
|
{
|
||||||
|
var seedConfig = new TorrentSeedConfiguration
|
||||||
|
{
|
||||||
|
Ratio = torrentIndexerSettings.SeedCriteria.SeedRatio
|
||||||
|
};
|
||||||
|
|
||||||
|
var seedTime = remoteEpisode.ParsedEpisodeInfo.FullSeason ? torrentIndexerSettings.SeedCriteria.SeasonPackSeedTime : torrentIndexerSettings.SeedCriteria.SeedTime;
|
||||||
|
if (seedTime.HasValue)
|
||||||
|
{
|
||||||
|
seedConfig.SeedTime = TimeSpan.FromMinutes(seedTime.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return seedConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ModelNotFoundException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -143,7 +143,7 @@
|
||||||
<Compile Include="Configuration\IConfigService.cs" />
|
<Compile Include="Configuration\IConfigService.cs" />
|
||||||
<Compile Include="Configuration\InvalidConfigFileException.cs" />
|
<Compile Include="Configuration\InvalidConfigFileException.cs" />
|
||||||
<Compile Include="Configuration\ResetApiKeyCommand.cs" />
|
<Compile Include="Configuration\ResetApiKeyCommand.cs" />
|
||||||
<Compile Include="Configuration\SeedConfigProvider.cs" />
|
<Compile Include="Indexers\SeedConfigProvider.cs" />
|
||||||
<Compile Include="DataAugmentation\DailySeries\DailySeries.cs" />
|
<Compile Include="DataAugmentation\DailySeries\DailySeries.cs" />
|
||||||
<Compile Include="DataAugmentation\DailySeries\DailySeriesDataProxy.cs" />
|
<Compile Include="DataAugmentation\DailySeries\DailySeriesDataProxy.cs" />
|
||||||
<Compile Include="DataAugmentation\DailySeries\DailySeriesService.cs" />
|
<Compile Include="DataAugmentation\DailySeries\DailySeriesService.cs" />
|
||||||
|
|
Loading…
Reference in New Issue