Fixed: Importing of preferred release over a proper/repack
This commit is contained in:
parent
30a512c880
commit
6a6d6f9e0d
|
@ -3,6 +3,7 @@ using FizzWare.NBuilder;
|
|||
using FluentAssertions;
|
||||
using Marr.Data;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
@ -126,7 +127,6 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
|||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_upgrade_for_existing_episodeFile_for_multi_episodes()
|
||||
{
|
||||
|
@ -180,7 +180,6 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
|||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile()
|
||||
{
|
||||
|
@ -238,5 +237,47 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
|||
|
||||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_a_revision_upgrade_and_prefers_propers()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.PreferAndUpgrade);
|
||||
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.HDTV720p, new Revision(version: 2))
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_not_a_revision_upgrade_and_does_not_prefer_propers()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
_localEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.EpisodeFileId = 1)
|
||||
.With(e => e.EpisodeFile = new LazyLoaded<EpisodeFile>(
|
||||
new EpisodeFile
|
||||
{
|
||||
Quality = new QualityModel(Quality.HDTV720p, new Revision(version: 2))
|
||||
}))
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
@ -10,31 +11,45 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|||
{
|
||||
public class UpgradeSpecification : IImportDecisionEngineSpecification
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public UpgradeSpecification(Logger logger)
|
||||
public UpgradeSpecification(IConfigService configService, Logger logger)
|
||||
{
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem downloadClientItem)
|
||||
{
|
||||
var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
|
||||
var qualityComparer = new QualityModelComparer(localEpisode.Series.QualityProfile);
|
||||
var languageComparer = new LanguageComparer(localEpisode.Series.LanguageProfile);
|
||||
|
||||
if (localEpisode.Episodes.Any(e => e.EpisodeFileId != 0 && qualityComparer.Compare(e.EpisodeFile.Value.Quality, localEpisode.Quality) > 0))
|
||||
foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0))
|
||||
{
|
||||
var episodeFile = episode.EpisodeFile.Value;
|
||||
var qualityCompare = qualityComparer.Compare(localEpisode.Quality.Quality, episodeFile.Quality.Quality);
|
||||
|
||||
if (qualityCompare < 0)
|
||||
{
|
||||
_logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
||||
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
||||
}
|
||||
|
||||
if (localEpisode.Episodes.Any(e => e.EpisodeFileId != 0 &&
|
||||
languageComparer.Compare(e.EpisodeFile.Value.Language, localEpisode.Language) > 0 &&
|
||||
qualityComparer.Compare(e.EpisodeFile.Value.Quality, localEpisode.Quality) == 0))
|
||||
if (downloadPropersAndRepacks != ProperDownloadTypes.DoNotPrefer &&
|
||||
localEpisode.Quality.Revision.CompareTo(episodeFile.Quality.Revision) < 0)
|
||||
{
|
||||
_logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
||||
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
||||
}
|
||||
|
||||
if (languageComparer.Compare(localEpisode.Language, episodeFile.Language) < 0 && qualityCompare == 0)
|
||||
{
|
||||
_logger.Debug("This file isn't a language upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
||||
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
||||
}
|
||||
}
|
||||
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue