mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
cleaned up parsing logic and structure.
This commit is contained in:
parent
cd2761d07d
commit
6e88f55a54
120 changed files with 2149 additions and 3064 deletions
|
@ -1,5 +1,8 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
|
@ -23,7 +26,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
get { return "File size too big or small"; }
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
_logger.Trace("Beginning size check for: {0}", subject);
|
||||
|
||||
|
@ -47,24 +50,19 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
//Multiply maxSize by Series.Runtime
|
||||
maxSize = maxSize * series.Runtime;
|
||||
|
||||
//Multiply maxSize by the number of episodes parsed (if EpisodeNumbers is null it will be treated as a single episode)
|
||||
//TODO: is this check really necessary? shouldn't we blowup?
|
||||
if (subject.EpisodeNumbers != null)
|
||||
maxSize = maxSize * subject.EpisodeNumbers.Count;
|
||||
maxSize = maxSize * subject.Episodes.Count;
|
||||
|
||||
//Check if there was only one episode parsed
|
||||
//and it is the first or last episode of the season
|
||||
if (subject.EpisodeNumbers != null && subject.EpisodeNumbers.Count == 1 &&
|
||||
_episodeService.IsFirstOrLastEpisodeOfSeason(series.Id,
|
||||
subject.SeasonNumber, subject.EpisodeNumbers[0]))
|
||||
if (subject.Episodes.Count == 1 && _episodeService.IsFirstOrLastEpisodeOfSeason(subject.Episodes.Single().Id))
|
||||
{
|
||||
maxSize = maxSize * 2;
|
||||
}
|
||||
|
||||
//If the parsed size is greater than maxSize we don't want it
|
||||
if (subject.Size > maxSize)
|
||||
if (subject.Report.Size > maxSize)
|
||||
{
|
||||
_logger.Trace("Item: {0}, Size: {1} is greater than maximum allowed size ({2}), rejecting.", subject, subject.Size, maxSize);
|
||||
_logger.Trace("Item: {0}, Size: {1} is greater than maximum allowed size ({2}), rejecting.", subject, subject.Report.Size, maxSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ using System;
|
|||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -25,7 +27,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
_logger.Trace("Beginning release group check for: {0}", subject);
|
||||
|
||||
|
@ -37,16 +39,18 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
if (string.IsNullOrWhiteSpace(allowed))
|
||||
return true;
|
||||
|
||||
var releaseGroup = subject.Report.ReleaseGroup;
|
||||
|
||||
foreach (var group in allowed.Trim(',', ' ').Split(','))
|
||||
{
|
||||
if (subject.ReleaseGroup.Equals(group.Trim(' '), StringComparison.CurrentCultureIgnoreCase))
|
||||
if (releaseGroup.Equals(group.Trim(' '), StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
_logger.Trace("Item: {0}'s release group is wanted: {1}", subject, subject.ReleaseGroup);
|
||||
_logger.Trace("Item: {0}'s release group is wanted: {1}", subject, releaseGroup);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Trace("Item: {0}'s release group is not wanted: {1}", subject, subject.ReleaseGroup);
|
||||
_logger.Trace("Item: {0}'s release group is not wanted: {1}", subject, releaseGroup);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -22,7 +24,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
if (!subject.Series.CustomStartDate.HasValue)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -20,10 +22,10 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
_logger.Trace("Checking if report meets language requirements. {0}", subject.Language);
|
||||
if (subject.Language != LanguageType.English)
|
||||
if (subject.Language != Language.English)
|
||||
{
|
||||
_logger.Trace("Report Language: {0} rejected because it is not English", subject.Language);
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
|
@ -26,29 +28,16 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
var series = _seriesRepository.GetByTitle(subject.CleanTitle);
|
||||
|
||||
if (series == null)
|
||||
if (!subject.Series.Monitored)
|
||||
{
|
||||
_logger.Trace("{0} is not mapped to any series in DB. skipping", subject.CleanTitle);
|
||||
_logger.Debug("{0} is present in the DB but not tracked. skipping.", subject.Series.Title);
|
||||
return false;
|
||||
}
|
||||
|
||||
subject.Series = series;
|
||||
|
||||
if (!series.Monitored)
|
||||
{
|
||||
_logger.Debug("{0} is present in the DB but not tracked. skipping.", subject.CleanTitle);
|
||||
return false;
|
||||
}
|
||||
|
||||
var episodes = _episodeService.GetEpisodesByParseResult(subject);
|
||||
subject.Episodes = episodes;
|
||||
|
||||
//return monitored if any of the episodes are monitored
|
||||
if (episodes.Any(episode => !episode.Ignored))
|
||||
if (subject.Episodes.Any(episode => !episode.Ignored))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
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;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -21,9 +27,34 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
return !_downloadClientProvider.GetDownloadClient().IsInQueue(subject);
|
||||
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
||||
|
||||
var queue = downloadClient.GetQueue().Select(q => Parser.Parser.ParseTitle(q.Title));
|
||||
|
||||
return !IsInQueue(subject, queue);
|
||||
}
|
||||
|
||||
public virtual 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);
|
||||
|
||||
if (newEpisode.Series.SeriesType == SeriesTypes.Daily)
|
||||
{
|
||||
return matchingTitleWithQuality.Any(q => q.AirDate.Value.Date == newEpisode.AirDate.Value.Date);
|
||||
}
|
||||
|
||||
var matchingSeason = matchingTitleWithQuality.Where(q => q.SeasonNumber == newEpisode.SeasonNumber);
|
||||
|
||||
if (newEpisode.FullSeason)
|
||||
{
|
||||
return matchingSeason.Any();
|
||||
}
|
||||
|
||||
return matchingSeason.Any(q => q.EpisodeNumbers != null && q.EpisodeNumbers.Any(e => newEpisode.EpisodeNumbers.Contains(e)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -20,7 +22,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
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))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -24,12 +26,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
_logger.Trace("Checking if report meets retention requirements. {0}", subject.Age);
|
||||
if (_configService.Retention > 0 && subject.Age > _configService.Retention)
|
||||
var age = subject.Report.Age;
|
||||
|
||||
_logger.Trace("Checking if report meets retention requirements. {0}", age);
|
||||
if (_configService.Retention > 0 && age > _configService.Retention)
|
||||
{
|
||||
_logger.Trace("Report age: {0} rejected by user's retention limit", subject.Age);
|
||||
_logger.Trace("Report age: {0} rejected by user's retention limit", age);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
|
@ -23,7 +25,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|||
return "Episode doesn't match";
|
||||
}
|
||||
}
|
||||
public bool IsSatisfiedBy(IndexerParseResult indexerParseResult, SearchDefinitionBase searchDefinitionBase)
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
var dailySearchSpec = searchDefinitionBase as DailyEpisodeSearchDefinition;
|
||||
|
||||
|
@ -31,7 +33,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|||
|
||||
var episode = _episodeService.GetEpisode(dailySearchSpec.SeriesId, dailySearchSpec.Airtime);
|
||||
|
||||
if (!indexerParseResult.AirDate.HasValue || indexerParseResult.AirDate.Value != episode.AirDate.Value)
|
||||
if (!remoteEpisode.AirDate.HasValue || remoteEpisode.AirDate.Value != episode.AirDate.Value)
|
||||
{
|
||||
_logger.Trace("Episode AirDate does not match searched episode number, skipping.");
|
||||
return false;
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
{
|
||||
public interface IDecisionEngineSearchSpecification : IRejectWithReason
|
||||
{
|
||||
bool IsSatisfiedBy(IndexerParseResult indexerParseResult, SearchDefinitionBase searchDefinitionBase);
|
||||
bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
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
|
||||
{
|
||||
|
@ -21,17 +23,17 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(IndexerParseResult indexerParseResult, SearchDefinitionBase searchDefinitionBase)
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
var singleEpisodeSpec = searchDefinitionBase as SeasonSearchDefinition;
|
||||
if (singleEpisodeSpec == null) return true;
|
||||
|
||||
if (singleEpisodeSpec.SeasonNumber != indexerParseResult.SeasonNumber)
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.SeasonNumber)
|
||||
{
|
||||
_logger.Trace("Season number does not match searched season number, skipping.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
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
|
||||
{
|
||||
public class SingleEpisodeMatchSpecification : IDecisionEngineSearchSpecification
|
||||
public class SingleEpisodeSearchMatchSpecification : IDecisionEngineSearchSpecification
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public SingleEpisodeMatchSpecification(Logger logger)
|
||||
public SingleEpisodeSearchMatchSpecification(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
@ -21,18 +24,18 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(IndexerParseResult indexerParseResult, SearchDefinitionBase searchDefinitionBase)
|
||||
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase)
|
||||
{
|
||||
var singleEpisodeSpec = searchDefinitionBase as SingleEpisodeSearchDefinition;
|
||||
if (singleEpisodeSpec == null) return true;
|
||||
|
||||
if (singleEpisodeSpec.SeasonNumber != indexerParseResult.SeasonNumber)
|
||||
if (singleEpisodeSpec.SeasonNumber != remoteEpisode.SeasonNumber)
|
||||
{
|
||||
_logger.Trace("Season number does not match searched season number, skipping.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!indexerParseResult.EpisodeNumbers.Contains(singleEpisodeSpec.EpisodeNumber))
|
||||
if (!remoteEpisode.Episodes.Select(c => c.EpisodeNumber).Contains(singleEpisodeSpec.EpisodeNumber))
|
||||
{
|
||||
_logger.Trace("Episode number does not match searched episode number, skipping.");
|
||||
return false;
|
|
@ -1,8 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -25,13 +24,16 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
foreach (var file in subject.Episodes.Select(c => c.EpisodeFile).Where(c => c != null))
|
||||
{
|
||||
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
|
||||
|
||||
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.Quality))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (subject.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(IndexerParseResult subject)
|
||||
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
||||
{
|
||||
foreach (var episode in subject.Episodes)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue