mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
release endpoint now returns fully parsed rss info with decisions.
This commit is contained in:
parent
7e473ca78d
commit
ca8eba9cf1
43 changed files with 458 additions and 336 deletions
|
@ -1,14 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public class DownloadDecision
|
||||
{
|
||||
public RemoteEpisode Episode { get; private set; }
|
||||
public RemoteEpisode RemoteEpisode { get; private set; }
|
||||
public IEnumerable<string> Rejections { get; private set; }
|
||||
|
||||
public bool Approved
|
||||
|
@ -21,7 +19,7 @@ namespace NzbDrone.Core.DecisionEngine
|
|||
|
||||
public DownloadDecision(RemoteEpisode episode, params string[] rejections)
|
||||
{
|
||||
Episode = episode;
|
||||
RemoteEpisode = episode;
|
||||
Rejections = rejections.ToList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.Search;
|
||||
|
@ -9,8 +10,8 @@ namespace NzbDrone.Core.DecisionEngine
|
|||
{
|
||||
public interface IMakeDownloadDecision
|
||||
{
|
||||
IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports);
|
||||
IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase);
|
||||
List<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports);
|
||||
List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase);
|
||||
}
|
||||
|
||||
public class DownloadDecisionMaker : IMakeDownloadDecision
|
||||
|
@ -24,29 +25,19 @@ namespace NzbDrone.Core.DecisionEngine
|
|||
_parsingService = parsingService;
|
||||
}
|
||||
|
||||
public IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports)
|
||||
public List<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports)
|
||||
{
|
||||
foreach (var report in reports)
|
||||
{
|
||||
var parseResult = _parsingService.Map(report);
|
||||
if (parseResult != null)
|
||||
{
|
||||
|
||||
yield return new DownloadDecision(parseResult, GetGeneralRejectionReasons(parseResult).ToArray());
|
||||
}
|
||||
}
|
||||
return GetDecisions(reports, GetGeneralRejectionReasons).ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase)
|
||||
public List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
foreach (var report in reports)
|
||||
{
|
||||
var remoteEpisode = _parsingService.Map(report);
|
||||
var generalReasons = GetGeneralRejectionReasons(remoteEpisode);
|
||||
var searchReasons = GetSearchRejectionReasons(remoteEpisode, searchDefinitionBase);
|
||||
|
||||
yield return new DownloadDecision(remoteEpisode, generalReasons.Union(searchReasons).ToArray());
|
||||
}
|
||||
return GetDecisions(reports, remoteEpisode =>
|
||||
{
|
||||
var generalReasons = GetGeneralRejectionReasons(remoteEpisode);
|
||||
var searchReasons = GetSearchRejectionReasons(remoteEpisode, searchDefinitionBase);
|
||||
return generalReasons.Union(searchReasons);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,6 +49,29 @@ namespace NzbDrone.Core.DecisionEngine
|
|||
.Select(spec => spec.RejectionReason);
|
||||
}
|
||||
|
||||
private IEnumerable<DownloadDecision> GetDecisions(IEnumerable<ReportInfo> reports, Func<RemoteEpisode, IEnumerable<string>> decisionCallback)
|
||||
{
|
||||
foreach (var report in reports)
|
||||
{
|
||||
var parsedEpisodeInfo = Parser.Parser.ParseTitle(report.Title);
|
||||
|
||||
if (parsedEpisodeInfo != null)
|
||||
{
|
||||
var remoteEpisode = _parsingService.Map(parsedEpisodeInfo);
|
||||
remoteEpisode.Report = report;
|
||||
|
||||
if (remoteEpisode.Series != null)
|
||||
{
|
||||
yield return new DownloadDecision(remoteEpisode, decisionCallback(remoteEpisode).ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new DownloadDecision(remoteEpisode, "Unknown Series");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetSearchRejectionReasons(RemoteEpisode report, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
return _specifications
|
||||
|
|
|
@ -30,13 +30,13 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
{
|
||||
_logger.Trace("Beginning size check for: {0}", subject);
|
||||
|
||||
if (subject.Quality.Quality == Quality.RAWHD)
|
||||
if (subject.ParsedEpisodeInfo.Quality.Quality == Quality.RAWHD)
|
||||
{
|
||||
_logger.Trace("Raw-HD release found, skipping size check.");
|
||||
return true;
|
||||
}
|
||||
|
||||
var qualityType = _qualityTypeProvider.Get((int)subject.Quality.Quality);
|
||||
var qualityType = _qualityTypeProvider.Get((int)subject.ParsedEpisodeInfo.Quality.Quality);
|
||||
|
||||
if (qualityType.MaxSize == 0)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
|
@ -24,10 +23,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
_logger.Trace("Checking if report meets language requirements. {0}", subject.Language);
|
||||
if (subject.Language != Language.English)
|
||||
_logger.Trace("Checking if report meets language requirements. {0}", subject.ParsedEpisodeInfo.Language);
|
||||
if (subject.ParsedEpisodeInfo.Language != Language.English)
|
||||
{
|
||||
_logger.Trace("Report Language: {0} rejected because it is not English", subject.Language);
|
||||
_logger.Trace("Report Language: {0} rejected because it is not English", subject.ParsedEpisodeInfo.Language);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
|
@ -27,7 +24,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
public bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
||||
|
||||
|
@ -36,25 +33,25 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
return !IsInQueue(subject, queue);
|
||||
}
|
||||
|
||||
public virtual bool IsInQueue(RemoteEpisode newEpisode, IEnumerable<ParsedEpisodeInfo> queue)
|
||||
private bool IsInQueue(RemoteEpisode newEpisode, IEnumerable<ParsedEpisodeInfo> queue)
|
||||
{
|
||||
var matchingTitle = queue.Where(q => String.Equals(q.SeriesTitle, newEpisode.Series.CleanTitle, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
var matchingTitleWithQuality = matchingTitle.Where(q => q.Quality >= newEpisode.Quality);
|
||||
var matchingTitleWithQuality = matchingTitle.Where(q => q.Quality >= newEpisode.ParsedEpisodeInfo.Quality);
|
||||
|
||||
if (newEpisode.Series.SeriesType == SeriesTypes.Daily)
|
||||
{
|
||||
return matchingTitleWithQuality.Any(q => q.AirDate.Value.Date == newEpisode.AirDate.Value.Date);
|
||||
return matchingTitleWithQuality.Any(q => q.AirDate.Value.Date == newEpisode.ParsedEpisodeInfo.AirDate.Value.Date);
|
||||
}
|
||||
|
||||
var matchingSeason = matchingTitleWithQuality.Where(q => q.SeasonNumber == newEpisode.SeasonNumber);
|
||||
var matchingSeason = matchingTitleWithQuality.Where(q => q.SeasonNumber == newEpisode.ParsedEpisodeInfo.SeasonNumber);
|
||||
|
||||
if (newEpisode.FullSeason)
|
||||
if (newEpisode.ParsedEpisodeInfo.FullSeason)
|
||||
{
|
||||
return matchingSeason.Any();
|
||||
}
|
||||
|
||||
return matchingSeason.Any(q => q.EpisodeNumbers != null && q.EpisodeNumbers.Any(e => newEpisode.EpisodeNumbers.Contains(e)));
|
||||
return matchingSeason.Any(q => q.EpisodeNumbers != null && q.EpisodeNumbers.Any(e => newEpisode.ParsedEpisodeInfo.EpisodeNumbers.Contains(e)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
_logger.Trace("Checking if report meets quality requirements. {0}", subject.Quality);
|
||||
if (!subject.Series.QualityProfile.Allowed.Contains(subject.Quality.Quality))
|
||||
_logger.Trace("Checking if report meets quality requirements. {0}", subject.ParsedEpisodeInfo.Quality);
|
||||
if (!subject.Series.QualityProfile.Allowed.Contains(subject.ParsedEpisodeInfo.Quality.Quality))
|
||||
{
|
||||
_logger.Trace("Quality {0} rejected by Series' quality profile", subject.Quality);
|
||||
_logger.Trace("Quality {0} rejected by Series' quality profile", subject.ParsedEpisodeInfo.Quality);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|||
|
||||
var episode = _episodeService.GetEpisode(dailySearchSpec.SeriesId, dailySearchSpec.Airtime);
|
||||
|
||||
if (!remoteEpisode.AirDate.HasValue || remoteEpisode.AirDate.Value != episode.AirDate.Value)
|
||||
if (!remoteEpisode.ParsedEpisodeInfo.AirDate.HasValue || remoteEpisode.ParsedEpisodeInfo.AirDate.Value.Date != episode.AirDate.Value.Date)
|
||||
{
|
||||
_logger.Trace("Episode AirDate does not match searched episode number, skipping.");
|
||||
return false;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
|
@ -28,7 +26,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|||
var singleEpisodeSpec = searchDefinitionBase as SeasonSearchDefinition;
|
||||
if (singleEpisodeSpec == null) return true;
|
||||
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.SeasonNumber)
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber)
|
||||
{
|
||||
_logger.Trace("Season number does not match searched season number, skipping.");
|
||||
return false;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
|
@ -29,7 +27,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|||
var singleEpisodeSpec = searchDefinitionBase as SingleEpisodeSearchDefinition;
|
||||
if (singleEpisodeSpec == null) return true;
|
||||
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.SeasonNumber)
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.ParsedEpisodeInfo.SeasonNumber)
|
||||
{
|
||||
_logger.Trace("Season number does not match searched season number, skipping.");
|
||||
return false;
|
||||
|
|
|
@ -30,12 +30,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
{
|
||||
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
|
||||
|
||||
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.Quality))
|
||||
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.ParsedEpisodeInfo.Quality))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (subject.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))
|
||||
if (subject.ParsedEpisodeInfo.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))
|
||||
{
|
||||
_logger.Trace("Proper for old file, skipping: {0}", subject);
|
||||
return false;
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
if (bestQualityInHistory != null)
|
||||
{
|
||||
_logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
|
||||
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, bestQualityInHistory, subject.Quality))
|
||||
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue