2013-04-15 01:41:39 +00:00
|
|
|
using System.Linq;
|
2012-02-07 05:08:07 +00:00
|
|
|
using NLog;
|
2013-08-07 03:18:05 +00:00
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2013-04-15 01:41:39 +00:00
|
|
|
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-08-08 03:30:20 +00:00
|
|
|
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2013-06-06 23:05:06 +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-06-06 23:05:06 +00:00
|
|
|
var quality = subject.ParsedEpisodeInfo.Quality.Quality;
|
|
|
|
|
|
|
|
if (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-06-06 23:05:06 +00:00
|
|
|
if (quality == Quality.Unknown)
|
|
|
|
{
|
|
|
|
_logger.Trace("Unknown quality. skipping size check.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var qualityType = _qualityTypeProvider.Get(quality.Id);
|
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();
|
|
|
|
|
|
|
|
//Multiply maxSize by Series.Runtime
|
2013-06-06 23:05:06 +00:00
|
|
|
maxSize = maxSize * subject.Series.Runtime * 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-09-13 23:17:58 +00:00
|
|
|
if (subject.Release.Size > maxSize)
|
2012-04-17 03:42:18 +00:00
|
|
|
{
|
2013-09-13 23:17:58 +00:00
|
|
|
_logger.Trace("Item: {0}, Size: {1} is greater than maximum allowed size ({2}), rejecting.", subject, subject.Release.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
|
|
|
}
|
|
|
|
}
|