Do not import same quality episode

Fixed: Do not delete episode files to import the same quality file
This commit is contained in:
Mark McDowall 2013-03-26 23:56:34 -07:00
parent d6ad5ebb36
commit a48cef49f5
2 changed files with 63 additions and 4 deletions

View File

@ -24,6 +24,10 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
new object[] { QualityTypes.SDTV, false }, new object[] { QualityTypes.SDTV, false },
new object[] { QualityTypes.DVD, true }, new object[] { QualityTypes.DVD, true },
};
public static object[] SkipImportTestCases =
{
new object[] { QualityTypes.HDTV720p, false } new object[] { QualityTypes.HDTV720p, false }
}; };
@ -78,7 +82,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
} }
[Test, TestCaseSource("ImportTestCases")] [Test, TestCaseSource("ImportTestCases")]
public void import_new_file_with_better_same_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper) public void import_new_file_with_better_quality_should_succeed(QualityTypes currentFileQuality, bool currentFileProper)
{ {
const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv"; const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv";
@ -103,6 +107,33 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
VerifyFileImport(result, Mocker, fakeEpisode, SIZE); VerifyFileImport(result, Mocker, fakeEpisode, SIZE);
} }
[Test, TestCaseSource("SkipImportTestCases")]
public void import_new_file_with_same_quality_should_not_import(QualityTypes currentFileQuality, bool currentFileProper)
{
const string newFile = @"WEEDS.S03E01.DUAL.1080p.HELLYWOOD.mkv";
//Fakes
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
.With(g => g.Quality = (QualityTypes)currentFileQuality)
.And(g => g.Proper = currentFileProper).Build()
).Build();
With80MBFile();
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
//Act
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, newFile);
//Assert
VerifySkipImport(result, Mocker);
}
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
[TestCase("WEEDS.S03E01.DUAL.SDTV.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.SDTV.XviD.AC3.-HELLYWOOD.avi")]
public void import_new_file_episode_has_same_or_better_quality_should_skip(string fileName) public void import_new_file_episode_has_same_or_better_quality_should_skip(string fileName)
@ -235,10 +266,9 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once()); Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
} }
[TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")]
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
[TestCase("WEEDS.S03E01.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv")] [TestCase("WEEDS.S03E01.DUAL.bluray.x264.AC3.-HELLYWOOD.mkv")]
public void import_new_multi_part_file_episode_has_equal_or_better_quality_than_existing(string fileName) public void import_new_multi_part_file_episode_has_better_quality_than_existing(string fileName)
{ {
//Fakes //Fakes
var fakeSeries = Builder<Series>.CreateNew().Build(); var fakeSeries = Builder<Series>.CreateNew().Build();
@ -267,6 +297,35 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once()); Mocker.GetMock<RecycleBinProvider>().Verify(p => p.DeleteFile(It.IsAny<string>()), Times.Once());
} }
[TestCase("WEEDS.S03E01.DUAL.hdtv.XviD.AC3.-HELLYWOOD.avi")]
public void skip_import_new_multi_part_file_episode_has_same_quality_as_existing(string fileName)
{
//Fakes
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
.With(f => f.Quality = QualityTypes.SDTV)
.Build())
.Build();
With80MBFile();
Mocker.GetMock<MediaFileProvider>()
.Setup(p => p.Exists(It.IsAny<String>()))
.Returns(false);
Mocker.GetMock<EpisodeProvider>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(fakeEpisodes);
//Act
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);
//Assert
VerifySkipImport(result, Mocker);
}
[TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.DVD.XviD.AC3.-HELLYWOOD.avi")]
[TestCase("WEEDS.S03E01.DUAL.HDTV.XviD.AC3.-HELLYWOOD.avi")] [TestCase("WEEDS.S03E01.DUAL.HDTV.XviD.AC3.-HELLYWOOD.avi")]
public void skip_import_new_multi_part_file_episode_existing_has_better_quality(string fileName) public void skip_import_new_multi_part_file_episode_existing_has_better_quality(string fileName)

View File

@ -143,7 +143,7 @@ namespace NzbDrone.Core.Providers
} }
//Make sure this file is an upgrade for ALL episodes already on disk //Make sure this file is an upgrade for ALL episodes already on disk
if (episodes.All(e => e.EpisodeFile == null || e.EpisodeFile.QualityWrapper <= parseResult.Quality)) if (episodes.All(e => e.EpisodeFile == null || e.EpisodeFile.QualityWrapper < parseResult.Quality))
{ {
Logger.Debug("Deleting the existing file(s) on disk to upgrade to: {0}", filePath); Logger.Debug("Deleting the existing file(s) on disk to upgrade to: {0}", filePath);
//Do the delete for files where there is already an episode on disk //Do the delete for files where there is already an episode on disk