2013-04-15 01:41:39 +00:00
|
|
|
using System.Linq;
|
2012-02-07 05:08:07 +00:00
|
|
|
using NLog;
|
2013-03-07 00:19:49 +00:00
|
|
|
using NzbDrone.Core.Model;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-02-27 03:19:22 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2013-02-19 06:01:03 +00:00
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2013-03-07 00:19:49 +00:00
|
|
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2013-04-07 07:30:37 +00:00
|
|
|
public class AcceptableSizeSpecification : IDecisionEngineSpecification
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2013-02-27 03:32:22 +00:00
|
|
|
private readonly IQualitySizeService _qualityTypeProvider;
|
2013-02-22 00:47:09 +00:00
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-03-07 00:19:49 +00:00
|
|
|
private readonly Logger _logger;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2013-03-07 00:19:49 +00:00
|
|
|
public AcceptableSizeSpecification(IQualitySizeService qualityTypeProvider, IEpisodeService episodeService, Logger logger)
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
|
|
|
_qualityTypeProvider = qualityTypeProvider;
|
2013-02-20 02:05:15 +00:00
|
|
|
_episodeService = episodeService;
|
2013-03-07 00:19:49 +00:00
|
|
|
_logger = logger;
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
2013-03-07 00:19:49 +00:00
|
|
|
public string RejectionReason
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2013-03-07 00:19:49 +00:00
|
|
|
get { return "File size too big or small"; }
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2013-03-07 00:19:49 +00:00
|
|
|
_logger.Trace("Beginning size check for: {0}", subject);
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2013-04-28 19:46:13 +00:00
|
|
|
if (subject.ParsedEpisodeInfo.Quality.Quality == Quality.RAWHD)
|
2013-01-09 08:15:06 +00:00
|
|
|
{
|
2013-03-07 00:19:49 +00:00
|
|
|
_logger.Trace("Raw-HD release found, skipping size check.");
|
2013-01-09 08:15:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-28 19:46:13 +00:00
|
|
|
var qualityType = _qualityTypeProvider.Get((int)subject.ParsedEpisodeInfo.Quality.Quality);
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
if (qualityType.MaxSize == 0)
|
2012-04-17 03:42:18 +00:00
|
|
|
{
|
2013-03-07 00:19:49 +00:00
|
|
|
_logger.Trace("Max size is 0 (unlimited) - skipping check.");
|
2012-02-07 05:08:07 +00:00
|
|
|
return true;
|
2012-04-17 03:42:18 +00:00
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
var maxSize = qualityType.MaxSize.Megabytes();
|
|
|
|
var series = subject.Series;
|
|
|
|
|
|
|
|
//Multiply maxSize by Series.Runtime
|
|
|
|
maxSize = maxSize * series.Runtime;
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
maxSize = maxSize * subject.Episodes.Count;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
//Check if there was only one episode parsed
|
|
|
|
//and it is the first or last episode of the season
|
2013-04-15 01:41:39 +00:00
|
|
|
if (subject.Episodes.Count == 1 && _episodeService.IsFirstOrLastEpisodeOfSeason(subject.Episodes.Single().Id))
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
|
|
|
maxSize = maxSize * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//If the parsed size is greater than maxSize we don't want it
|
2013-04-15 01:41:39 +00:00
|
|
|
if (subject.Report.Size > maxSize)
|
2012-04-17 03:42:18 +00:00
|
|
|
{
|
2013-04-15 01:41:39 +00:00
|
|
|
_logger.Trace("Item: {0}, Size: {1} is greater than maximum allowed size ({2}), rejecting.", subject, subject.Report.Size, maxSize);
|
2012-02-07 05:08:07 +00:00
|
|
|
return false;
|
2012-04-17 03:42:18 +00:00
|
|
|
}
|
2013-03-07 00:19:49 +00:00
|
|
|
|
|
|
|
_logger.Trace("Item: {0}, meets size constraints.", subject);
|
2012-02-07 05:08:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-03-07 00:19:49 +00:00
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
}
|