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