New: Ability to push releases to Sonarr via API for processing

Closes #419
pull/4/head
Mark McDowall 9 years ago
parent 4f38454825
commit bb144a6df6

@ -9,8 +9,6 @@ using NzbDrone.Core.Exceptions;
using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using Omu.ValueInjecter;
using System.Linq;
using Nancy.ModelBinding; using Nancy.ModelBinding;
using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions;
using NzbDrone.Common.Cache; using NzbDrone.Common.Cache;
@ -18,7 +16,7 @@ using HttpStatusCode = System.Net.HttpStatusCode;
namespace NzbDrone.Api.Indexers namespace NzbDrone.Api.Indexers
{ {
public class ReleaseModule : NzbDroneRestModule<ReleaseResource> public class ReleaseModule : ReleaseModuleBase
{ {
private readonly IFetchAndParseRss _rssFetcherAndParser; private readonly IFetchAndParseRss _rssFetcherAndParser;
private readonly ISearchForNzb _nzbSearchService; private readonly ISearchForNzb _nzbSearchService;
@ -113,55 +111,10 @@ namespace NzbDrone.Api.Indexers
return MapDecisions(prioritizedDecisions); return MapDecisions(prioritizedDecisions);
} }
private List<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision> decisions) protected override ReleaseResource MapDecision(DownloadDecision decision, int initialWeight)
{ {
var result = new List<ReleaseResource>(); _remoteEpisodeCache.Set(decision.RemoteEpisode.Release.Guid, decision.RemoteEpisode, TimeSpan.FromMinutes(30));
return base.MapDecision(decision, initialWeight);
foreach (var downloadDecision in decisions)
{
_remoteEpisodeCache.Set(downloadDecision.RemoteEpisode.Release.Guid, downloadDecision.RemoteEpisode, TimeSpan.FromMinutes(30));
var release = new ReleaseResource();
release.InjectFrom(downloadDecision.RemoteEpisode.Release);
release.InjectFrom(downloadDecision.RemoteEpisode.ParsedEpisodeInfo);
release.InjectFrom(downloadDecision);
release.Rejections = downloadDecision.Rejections.Select(r => r.Reason).ToList();
release.DownloadAllowed = downloadDecision.RemoteEpisode.DownloadAllowed;
release.ReleaseWeight = result.Count;
if (downloadDecision.RemoteEpisode.Series != null)
{
release.QualityWeight = downloadDecision.RemoteEpisode
.Series
.Profile
.Value
.Items
.FindIndex(v => v.Quality == release.Quality.Quality) * 100;
}
release.QualityWeight += release.Quality.Revision.Real * 10;
release.QualityWeight += release.Quality.Revision.Version;
var torrentRelease = downloadDecision.RemoteEpisode.Release as TorrentInfo;
if (torrentRelease != null)
{
release.Protocol = DownloadProtocol.Torrent;
release.Seeders = torrentRelease.Seeders;
//TODO: move this up the chains
release.Leechers = torrentRelease.Peers - torrentRelease.Seeders;
}
else
{
release.Protocol = DownloadProtocol.Usenet;
}
result.Add(release);
}
return result;
} }
} }
} }

@ -0,0 +1,67 @@
using System.Collections.Generic;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model;
using Omu.ValueInjecter;
using System.Linq;
namespace NzbDrone.Api.Indexers
{
public abstract class ReleaseModuleBase : NzbDroneRestModule<ReleaseResource>
{
protected virtual List<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision> decisions)
{
var result = new List<ReleaseResource>();
foreach (var downloadDecision in decisions)
{
var release = MapDecision(downloadDecision, result.Count);
result.Add(release);
}
return result;
}
protected virtual ReleaseResource MapDecision(DownloadDecision decision, int initialWeight)
{
var release = new ReleaseResource();
release.InjectFrom(decision.RemoteEpisode.Release);
release.InjectFrom(decision.RemoteEpisode.ParsedEpisodeInfo);
release.InjectFrom(decision);
release.Rejections = decision.Rejections.Select(r => r.Reason).ToList();
release.DownloadAllowed = decision.RemoteEpisode.DownloadAllowed;
release.ReleaseWeight = initialWeight;
if (decision.RemoteEpisode.Series != null)
{
release.QualityWeight = decision.RemoteEpisode
.Series
.Profile
.Value
.Items
.FindIndex(v => v.Quality == release.Quality.Quality) * 100;
}
release.QualityWeight += release.Quality.Revision.Real * 10;
release.QualityWeight += release.Quality.Revision.Version;
var torrentRelease = decision.RemoteEpisode.Release as TorrentInfo;
if (torrentRelease != null)
{
release.Protocol = DownloadProtocol.Torrent;
release.Seeders = torrentRelease.Seeders;
//TODO: move this up the chains
release.Leechers = torrentRelease.Peers - torrentRelease.Seeders;
}
else
{
release.Protocol = DownloadProtocol.Usenet;
}
return release;
}
}
}

@ -3,11 +3,8 @@ using Nancy.ModelBinding;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Parser;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Api.Mapping; using NzbDrone.Api.Mapping;
using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions;
@ -15,7 +12,7 @@ using NLog;
namespace NzbDrone.Api.Indexers namespace NzbDrone.Api.Indexers
{ {
class ReleasePushModule : NzbDroneRestModule<ReleaseResource> class ReleasePushModule : ReleaseModuleBase
{ {
private readonly IMakeDownloadDecision _downloadDecisionMaker; private readonly IMakeDownloadDecision _downloadDecisionMaker;
private readonly IProcessDownloadDecisions _downloadDecisionProcessor; private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
@ -39,7 +36,7 @@ namespace NzbDrone.Api.Indexers
private Response ProcessRelease(ReleaseResource release) private Response ProcessRelease(ReleaseResource release)
{ {
_logger.Info("Release pushed: {0}", release.Title); _logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl);
var info = release.InjectTo<ReleaseInfo>(); var info = release.InjectTo<ReleaseInfo>();
info.Guid = "PUSH-" + info.DownloadUrl; info.Guid = "PUSH-" + info.DownloadUrl;
@ -47,12 +44,7 @@ namespace NzbDrone.Api.Indexers
var decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info }); var decisions = _downloadDecisionMaker.GetRssDecision(new List<ReleaseInfo> { info });
var processed = _downloadDecisionProcessor.ProcessDecisions(decisions); var processed = _downloadDecisionProcessor.ProcessDecisions(decisions);
var status = processed.Grabbed.Any() ? "grabbed" : return MapDecisions(decisions).First().AsResponse();
processed.Rejected.Any() ? "rejected" :
processed.Pending.Any() ? "pending" :
"error" ;
return status.AsResponse();
} }
} }
} }

@ -101,6 +101,7 @@
<Compile Include="Extensions\Pipelines\CorsPipeline.cs" /> <Compile Include="Extensions\Pipelines\CorsPipeline.cs" />
<Compile Include="Frontend\Mappers\LoginHtmlMapper.cs" /> <Compile Include="Frontend\Mappers\LoginHtmlMapper.cs" />
<Compile Include="Frontend\Mappers\RobotsTxtMapper.cs" /> <Compile Include="Frontend\Mappers\RobotsTxtMapper.cs" />
<Compile Include="Indexers\ReleaseModuleBase.cs" />
<Compile Include="Indexers\ReleasePushModule.cs" /> <Compile Include="Indexers\ReleasePushModule.cs" />
<Compile Include="Parse\ParseModule.cs" /> <Compile Include="Parse\ParseModule.cs" />
<Compile Include="Parse\ParseResource.cs" /> <Compile Include="Parse\ParseResource.cs" />

@ -2,10 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common;
using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download.Pending; using NzbDrone.Core.Download.Pending;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download namespace NzbDrone.Core.Download
{ {

Loading…
Cancel
Save