Repack/propers for older episodes are no more

#ND-53
Fixed: Do not download Propers/Repacks for episodes older than 7 days
pull/2/head
Mark McDowall 12 years ago
parent 02e21c7d7e
commit b7229dea06

@ -1,5 +1,6 @@
// ReSharper disable RedundantUsingDirective // ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
@ -31,8 +32,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
Mocker.Resolve<QualityUpgradeSpecification>(); Mocker.Resolve<QualityUpgradeSpecification>();
_upgradeDisk = Mocker.Resolve<UpgradeDiskSpecification>(); _upgradeDisk = Mocker.Resolve<UpgradeDiskSpecification>();
firstFile = new EpisodeFile { Quality = QualityTypes.Bluray1080p, Proper = true }; firstFile = new EpisodeFile { Quality = QualityTypes.Bluray1080p, Proper = true, DateAdded = DateTime.Now };
secondFile = new EpisodeFile { Quality = QualityTypes.Bluray1080p, Proper = true }; secondFile = new EpisodeFile { Quality = QualityTypes.Bluray1080p, Proper = true, DateAdded = DateTime.Now };
var singleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = null } }; var singleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = null } };
var doubleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = secondFile }, new Episode { EpisodeFile = null } }; var doubleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = secondFile }, new Episode { EpisodeFile = null } };
@ -121,5 +122,26 @@ namespace NzbDrone.Core.Test.ProviderTests.DecisionEngineTests
parseResultSingle.Quality = new QualityModel(QualityTypes.WEBDL1080p, false); parseResultSingle.Quality = new QualityModel(QualityTypes.WEBDL1080p, false);
_upgradeDisk.IsSatisfiedBy(parseResultSingle).Should().BeFalse(); _upgradeDisk.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
} }
[Test]
public void should_return_false_when_episodeFile_was_added_more_than_7_days_ago()
{
firstFile.DateAdded = DateTime.Today.AddDays(-30);
_upgradeDisk.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
}
[Test]
public void should_return_false_when_first_episodeFile_was_added_more_than_7_days_ago()
{
firstFile.DateAdded = DateTime.Today.AddDays(-30);
_upgradeDisk.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
[Test]
public void should_return_false_when_second_episodeFile_was_added_more_than_7_days_ago()
{
secondFile.DateAdded = DateTime.Today.AddDays(-30);
_upgradeDisk.IsSatisfiedBy(parseResultMulti).Should().BeFalse();
}
} }
} }

@ -1,4 +1,5 @@
using System.Linq; using System;
using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
@ -6,13 +7,11 @@ namespace NzbDrone.Core.Providers.DecisionEngine
{ {
public class UpgradeDiskSpecification public class UpgradeDiskSpecification
{ {
private readonly EpisodeProvider _episodeProvider;
private readonly QualityUpgradeSpecification _qualityUpgradeSpecification; private readonly QualityUpgradeSpecification _qualityUpgradeSpecification;
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public UpgradeDiskSpecification(EpisodeProvider episodeProvider, QualityUpgradeSpecification qualityUpgradeSpecification) public UpgradeDiskSpecification(QualityUpgradeSpecification qualityUpgradeSpecification)
{ {
_episodeProvider = episodeProvider;
_qualityUpgradeSpecification = qualityUpgradeSpecification; _qualityUpgradeSpecification = qualityUpgradeSpecification;
} }
@ -27,6 +26,12 @@ namespace NzbDrone.Core.Providers.DecisionEngine
logger.Trace("Comparing file quality with report. Existing file is {0} proper:{1}", file.Quality, file.Proper); logger.Trace("Comparing file quality with report. Existing file is {0} proper:{1}", file.Quality, file.Proper);
if (!_qualityUpgradeSpecification.IsSatisfiedBy(new QualityModel { Quality = file.Quality, Proper = file.Proper }, subject.Quality, subject.Series.QualityProfile.Cutoff)) if (!_qualityUpgradeSpecification.IsSatisfiedBy(new QualityModel { Quality = file.Quality, Proper = file.Proper }, subject.Quality, subject.Series.QualityProfile.Cutoff))
return false; return false;
if(subject.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))
{
logger.Trace("Proper for old file, skipping: {0}", subject);
return false;
}
} }
return true; return true;

Loading…
Cancel
Save