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