Use folder quality when it is better than file quality

Fixed: Better handling of downloads that don't have the quality in the filename
pull/2/head
Mark McDowall 11 years ago
parent 034f8e8dfd
commit 410bf0d846

@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.MediaFiles
imported.Add(new ImportDecision(localEpisode));
Mocker.GetMock<IMakeImportDecision>()
.Setup(s => s.GetImportDecisions(It.IsAny<IEnumerable<String>>(), It.IsAny<Series>(), true))
.Setup(s => s.GetImportDecisions(It.IsAny<IEnumerable<String>>(), It.IsAny<Series>(), true, null))
.Returns(imported);
Mocker.GetMock<IImportApprovedEpisodes>()

@ -9,6 +9,7 @@ using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
@ -21,6 +22,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
private List<string> _videoFiles;
private LocalEpisode _localEpisode;
private Series _series;
private QualityModel _quality;
private Mock<IImportDecisionEngineSpecification> _pass1;
private Mock<IImportDecisionEngineSpecification> _pass2;
@ -62,7 +64,13 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
_videoFiles = new List<string> { @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi" };
_series = new Series();
_localEpisode = new LocalEpisode { Series = _series, Path = @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi" };
_quality = new QualityModel(Quality.DVD);
_localEpisode = new LocalEpisode
{
Series = _series,
Quality = _quality,
Path = @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi"
};
Mocker.GetMock<IParsingService>()
.Setup(c => c.GetEpisodes(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
@ -161,5 +169,38 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
ExceptionVerification.ExpectedErrors(3);
}
[Test]
public void should_use_file_quality_if_folder_quality_is_null()
{
GivenSpecifications(_pass1, _pass2, _pass3);
var expectedQuality = QualityParser.ParseQuality(_videoFiles.Single());
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false, null);
result.Single().LocalEpisode.Quality.Should().Be(expectedQuality);
}
[Test]
public void should_use_file_quality_if_folder_quality_is_lower_than_file_quality()
{
GivenSpecifications(_pass1, _pass2, _pass3);
var expectedQuality = QualityParser.ParseQuality(_videoFiles.Single());
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false, new QualityModel(Quality.SDTV));
result.Single().LocalEpisode.Quality.Should().Be(expectedQuality);
}
[Test]
public void should_use_folder_quality_when_it_is_greater_than_file_quality()
{
GivenSpecifications(_pass1, _pass2, _pass3);
var expectedQuality = new QualityModel(Quality.Bluray1080p);
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false, expectedQuality);
result.Single().LocalEpisode.Quality.Should().Be(expectedQuality);
}
}
}

@ -99,6 +99,7 @@ namespace NzbDrone.Core.MediaFiles
{
var cleanedUpName = GetCleanedUpFolderName(subfolderInfo.Name);
var series = _parsingService.GetSeries(cleanedUpName);
var quality = QualityParser.ParseQuality(cleanedUpName);
if (series == null)
{
@ -108,7 +109,7 @@ namespace NzbDrone.Core.MediaFiles
var videoFiles = _diskScanService.GetVideoFiles(subfolderInfo.FullName);
return ProcessFiles(series, videoFiles);
return ProcessFiles(series, quality, videoFiles);
}
private void ProcessVideoFile(string videoFile)
@ -127,12 +128,12 @@ namespace NzbDrone.Core.MediaFiles
return;
}
ProcessFiles(series, videoFile);
ProcessFiles(series, null, videoFile);
}
private List<ImportDecision> ProcessFiles(Series series, params string[] videoFiles)
private List<ImportDecision> ProcessFiles(Series series, QualityModel quality, params string[] videoFiles)
{
var decisions = _importDecisionMaker.GetImportDecisions(videoFiles, series, true);
var decisions = _importDecisionMaker.GetImportDecisions(videoFiles, series, true, quality);
return _importApprovedEpisodes.Import(decisions, true);
}

@ -6,6 +6,7 @@ using NzbDrone.Common;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
@ -13,7 +14,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
{
public interface IMakeImportDecision
{
List<ImportDecision> GetImportDecisions(IEnumerable<String> videoFiles, Series series, bool sceneSource);
List<ImportDecision> GetImportDecisions(IEnumerable<String> videoFiles, Series series, bool sceneSource, QualityModel quality = null);
}
public class ImportDecisionMaker : IMakeImportDecision
@ -38,16 +39,16 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
_logger = logger;
}
public List<ImportDecision> GetImportDecisions(IEnumerable<string> videoFiles, Series series, bool sceneSource)
public List<ImportDecision> GetImportDecisions(IEnumerable<string> videoFiles, Series series, bool sceneSource, QualityModel quality = null)
{
var newFiles = _mediaFileService.FilterExistingFiles(videoFiles.ToList(), series.Id);
_logger.Debug("Analysing {0}/{1} files.", newFiles.Count, videoFiles.Count());
return GetDecisions(newFiles, series, sceneSource).ToList();
return GetDecisions(newFiles, series, sceneSource, quality).ToList();
}
private IEnumerable<ImportDecision> GetDecisions(IEnumerable<String> videoFiles, Series series, bool sceneSource)
private IEnumerable<ImportDecision> GetDecisions(IEnumerable<String> videoFiles, Series series, bool sceneSource, QualityModel quality = null)
{
foreach (var file in videoFiles)
{
@ -59,6 +60,11 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
if (parsedEpisode != null)
{
if (quality != null && quality > parsedEpisode.Quality)
{
parsedEpisode.Quality = quality;
}
parsedEpisode.Size = _diskProvider.GetFileSize(file);
decision = GetDecision(parsedEpisode);
}

Loading…
Cancel
Save