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