|
|
@ -14,6 +14,8 @@ using Omu.ValueInjecter;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using Nancy.ModelBinding;
|
|
|
|
using Nancy.ModelBinding;
|
|
|
|
using NzbDrone.Api.Extensions;
|
|
|
|
using NzbDrone.Api.Extensions;
|
|
|
|
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Indexers
|
|
|
|
namespace NzbDrone.Api.Indexers
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -27,12 +29,15 @@ namespace NzbDrone.Api.Indexers
|
|
|
|
private readonly IParsingService _parsingService;
|
|
|
|
private readonly IParsingService _parsingService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ICached<RemoteEpisode> _remoteEpisodeCache;
|
|
|
|
|
|
|
|
|
|
|
|
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser,
|
|
|
|
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser,
|
|
|
|
ISearchForNzb nzbSearchService,
|
|
|
|
ISearchForNzb nzbSearchService,
|
|
|
|
IMakeDownloadDecision downloadDecisionMaker,
|
|
|
|
IMakeDownloadDecision downloadDecisionMaker,
|
|
|
|
IPrioritizeDownloadDecision prioritizeDownloadDecision,
|
|
|
|
IPrioritizeDownloadDecision prioritizeDownloadDecision,
|
|
|
|
IDownloadService downloadService,
|
|
|
|
IDownloadService downloadService,
|
|
|
|
IParsingService parsingService,
|
|
|
|
IParsingService parsingService,
|
|
|
|
|
|
|
|
ICacheManager cacheManager,
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_rssFetcherAndParser = rssFetcherAndParser;
|
|
|
|
_rssFetcherAndParser = rssFetcherAndParser;
|
|
|
@ -46,12 +51,21 @@ namespace NzbDrone.Api.Indexers
|
|
|
|
Post["/"] = x => DownloadRelease(this.Bind<ReleaseResource>());
|
|
|
|
Post["/"] = x => DownloadRelease(this.Bind<ReleaseResource>());
|
|
|
|
|
|
|
|
|
|
|
|
PostValidator.RuleFor(s => s.DownloadAllowed).Equal(true);
|
|
|
|
PostValidator.RuleFor(s => s.DownloadAllowed).Equal(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_remoteEpisodeCache = cacheManager.GetCache<RemoteEpisode>(GetType(), "remoteEpisodes");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Response DownloadRelease(ReleaseResource release)
|
|
|
|
private Response DownloadRelease(ReleaseResource release)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var remoteEpisode = _parsingService.Map(release.InjectTo<ParsedEpisodeInfo>(), release.TvRageId);
|
|
|
|
var remoteEpisode = _remoteEpisodeCache.Find(release.Guid);
|
|
|
|
remoteEpisode.Release = release.InjectTo<ReleaseInfo>();
|
|
|
|
|
|
|
|
|
|
|
|
if (remoteEpisode == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Debug("Couldn't find requested release in cache, cache timeout probably expired.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new NotFoundResponse();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_downloadService.DownloadReport(remoteEpisode);
|
|
|
|
_downloadService.DownloadReport(remoteEpisode);
|
|
|
|
|
|
|
|
|
|
|
|
return release.AsResponse();
|
|
|
|
return release.AsResponse();
|
|
|
@ -93,12 +107,14 @@ namespace NzbDrone.Api.Indexers
|
|
|
|
return MapDecisions(prioritizedDecisions);
|
|
|
|
return MapDecisions(prioritizedDecisions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static List<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision> decisions)
|
|
|
|
private List<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision> decisions)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = new List<ReleaseResource>();
|
|
|
|
var result = new List<ReleaseResource>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var downloadDecision in decisions)
|
|
|
|
foreach (var downloadDecision in decisions)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_remoteEpisodeCache.Set(downloadDecision.RemoteEpisode.Release.Guid, downloadDecision.RemoteEpisode, TimeSpan.FromMinutes(30));
|
|
|
|
|
|
|
|
|
|
|
|
var release = new ReleaseResource();
|
|
|
|
var release = new ReleaseResource();
|
|
|
|
|
|
|
|
|
|
|
|
release.InjectFrom(downloadDecision.RemoteEpisode.Release);
|
|
|
|
release.InjectFrom(downloadDecision.RemoteEpisode.Release);
|
|
|
|