1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/DecisionEngine/AcceptableSizeSpecification.cs

79 lines
2.7 KiB
C#
Raw Normal View History

using System.Linq;
using NLog;
2013-02-24 22:57:33 +03:00
using NzbDrone.Core.Datastore;
2013-02-27 06:19:22 +03:00
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
2013-02-19 05:19:38 +03:00
using NzbDrone.Core.Providers;
2013-02-19 05:19:38 +03:00
namespace NzbDrone.Core.DecisionEngine
{
public class AcceptableSizeSpecification
{
2013-02-27 06:19:22 +03:00
private readonly QualitySizeService _qualityTypeProvider;
private readonly IEpisodeService _episodeService;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
2013-02-27 06:19:22 +03:00
public AcceptableSizeSpecification(QualitySizeService qualityTypeProvider, IEpisodeService episodeService)
{
_qualityTypeProvider = qualityTypeProvider;
_episodeService = episodeService;
}
public AcceptableSizeSpecification()
{
}
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
{
logger.Trace("Beginning size check for: {0}", subject);
2013-02-27 06:19:22 +03:00
if(subject.Quality.Quality == Quality.RAWHD)
{
logger.Trace("Raw-HD release found, skipping size check.");
return true;
}
var qualityType = _qualityTypeProvider.Get((int)subject.Quality.Quality);
if (qualityType.MaxSize == 0)
{
logger.Trace("Max size is 0 (unlimited) - skipping check.");
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 &&
_episodeService.IsFirstOrLastEpisodeOfSeason(series.Id,
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)
{
2013-01-23 05:10:34 +03:00
logger.Trace("Item: {0}, Size: {1} is greater than maximum allowed size ({2}), rejecting.", subject, subject.Size, maxSize);
return false;
}
logger.Trace("Item: {0}, meets size contraints.", subject);
return true;
}
}
}