mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Fixed: Importing of preferred release over a proper/repack
This commit is contained in:
parent
30a512c880
commit
6a6d6f9e0d
@ -3,6 +3,7 @@
|
||||
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 @@ public void should_return_false_if_language_upgrade_for_existing_episodeFile_and
|
||||
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 @@ public void should_return_false_if_language_upgrade_for_existing_episodeFile_for
|
||||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_not_an_upgrade_for_existing_episodeFile()
|
||||
{
|
||||
@ -238,5 +237,47 @@ public void should_return_false_if_not_an_upgrade_for_one_existing_episodeFile_f
|
||||
|
||||
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,30 +11,44 @@ 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))
|
||||
{
|
||||
_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))
|
||||
|
||||
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 (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
Block a user