mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
New: Rewrite of download decision engine.
This commit is contained in:
parent
a168bdfa00
commit
5717b7f596
60 changed files with 2013 additions and 1745 deletions
|
@ -0,0 +1,66 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using Ninject;
|
||||
using NzbDrone.Core.Model;
|
||||
|
||||
namespace NzbDrone.Core.Providers.DecisionEngine
|
||||
{
|
||||
public class AcceptableSizeSpecification
|
||||
{
|
||||
private readonly QualityTypeProvider _qualityTypeProvider;
|
||||
private readonly EpisodeProvider _episodeProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[Inject]
|
||||
public AcceptableSizeSpecification(QualityTypeProvider qualityTypeProvider, EpisodeProvider episodeProvider)
|
||||
{
|
||||
_qualityTypeProvider = qualityTypeProvider;
|
||||
_episodeProvider = episodeProvider;
|
||||
}
|
||||
|
||||
public AcceptableSizeSpecification()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
|
||||
{
|
||||
var qualityType = _qualityTypeProvider.Get((int)subject.Quality.QualityType);
|
||||
|
||||
//Need to determine if this is a 30 or 60 minute episode
|
||||
//Is it a multi-episode release?
|
||||
//Is it the first or last series of a season?
|
||||
|
||||
//0 will be treated as unlimited
|
||||
if (qualityType.MaxSize == 0)
|
||||
return true;
|
||||
|
||||
var maxSize = qualityType.MaxSize.Megabytes();
|
||||
var series = subject.Series;
|
||||
|
||||
//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;
|
||||
|
||||
//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 &&
|
||||
_episodeProvider.IsFirstOrLastEpisodeOfSeason(series.SeriesId,
|
||||
subject.SeasonNumber, subject.EpisodeNumbers[0]))
|
||||
{
|
||||
maxSize = maxSize * 2;
|
||||
}
|
||||
|
||||
//If the parsed size is greater than maxSize we don't want it
|
||||
if (subject.Size > maxSize)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue