mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed: Files with lower preferred word scores are imported
Closes #4212
This commit is contained in:
parent
8047e5aa67
commit
21fafb895f
@ -2,6 +2,7 @@
|
|||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Marr.Data;
|
using Marr.Data;
|
||||||
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
@ -13,6 +14,7 @@
|
|||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
using NzbDrone.Core.Languages;
|
using NzbDrone.Core.Languages;
|
||||||
using NzbDrone.Core.Profiles.Languages;
|
using NzbDrone.Core.Profiles.Languages;
|
||||||
|
using NzbDrone.Core.Profiles.Releases;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||||
{
|
{
|
||||||
@ -278,6 +280,39 @@ public void should_return_false_if_not_a_revision_upgrade_and_prefers_propers()
|
|||||||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_false_if_it_is_not_a_preferred_word_upgrade()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>()
|
||||||
|
.Setup(s => s.DownloadPropersAndRepacks)
|
||||||
|
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||||
|
|
||||||
|
Mocker.GetMock<IPreferredWordService>()
|
||||||
|
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<string>(), 0))
|
||||||
|
.Returns(5);
|
||||||
|
|
||||||
|
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||||
|
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||||
|
.Returns(10);
|
||||||
|
|
||||||
|
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
|
||||||
|
|
||||||
|
_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.Bluray1080p)
|
||||||
|
}))
|
||||||
|
.Build()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_localEpisode.FileEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew().Build();
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_return_true_if_not_a_revision_upgrade_and_does_not_prefer_propers()
|
public void should_return_true_if_not_a_revision_upgrade_and_does_not_prefer_propers()
|
||||||
{
|
{
|
||||||
@ -322,6 +357,72 @@ public void should_return_true_when_comparing_to_a_lower_quality_proper()
|
|||||||
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_if_it_is_a_preferred_word_upgrade()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>()
|
||||||
|
.Setup(s => s.DownloadPropersAndRepacks)
|
||||||
|
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||||
|
|
||||||
|
Mocker.GetMock<IPreferredWordService>()
|
||||||
|
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<string>(), 0))
|
||||||
|
.Returns(5);
|
||||||
|
|
||||||
|
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||||
|
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||||
|
.Returns(1);
|
||||||
|
|
||||||
|
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
|
||||||
|
|
||||||
|
_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.Bluray1080p)
|
||||||
|
}))
|
||||||
|
.Build()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_localEpisode.FileEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew().Build();
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_true_if_it_has_an_equal_preferred_word_score()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>()
|
||||||
|
.Setup(s => s.DownloadPropersAndRepacks)
|
||||||
|
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||||
|
|
||||||
|
Mocker.GetMock<IPreferredWordService>()
|
||||||
|
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<string>(), 0))
|
||||||
|
.Returns(5);
|
||||||
|
|
||||||
|
Mocker.GetMock<IEpisodeFilePreferredWordCalculator>()
|
||||||
|
.Setup(s => s.Calculate(It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
|
||||||
|
.Returns(5);
|
||||||
|
|
||||||
|
_localEpisode.Quality = new QualityModel(Quality.Bluray1080p);
|
||||||
|
|
||||||
|
_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.Bluray1080p)
|
||||||
|
}))
|
||||||
|
.Build()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
_localEpisode.FileEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew().Build();
|
||||||
|
|
||||||
|
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_return_true_if_episode_file_is_null()
|
public void should_return_true_if_episode_file_is_null()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.DecisionEngine;
|
using NzbDrone.Core.DecisionEngine;
|
||||||
@ -6,17 +7,25 @@
|
|||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Core.Qualities;
|
using NzbDrone.Core.Qualities;
|
||||||
using NzbDrone.Core.Languages;
|
using NzbDrone.Core.Languages;
|
||||||
|
using NzbDrone.Core.Profiles.Releases;
|
||||||
|
|
||||||
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
||||||
{
|
{
|
||||||
public class UpgradeSpecification : IImportDecisionEngineSpecification
|
public class UpgradeSpecification : IImportDecisionEngineSpecification
|
||||||
{
|
{
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
|
private readonly IPreferredWordService _preferredWordService;
|
||||||
|
private readonly IEpisodeFilePreferredWordCalculator _episodeFilePreferredWordCalculator;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public UpgradeSpecification(IConfigService configService, Logger logger)
|
public UpgradeSpecification(IConfigService configService,
|
||||||
|
IPreferredWordService preferredWordService,
|
||||||
|
IEpisodeFilePreferredWordCalculator episodeFilePreferredWordCalculator,
|
||||||
|
Logger logger)
|
||||||
{
|
{
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
|
_preferredWordService = preferredWordService;
|
||||||
|
_episodeFilePreferredWordCalculator = episodeFilePreferredWordCalculator;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +34,7 @@ public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem down
|
|||||||
var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
|
var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
|
||||||
var qualityComparer = new QualityModelComparer(localEpisode.Series.QualityProfile);
|
var qualityComparer = new QualityModelComparer(localEpisode.Series.QualityProfile);
|
||||||
var languageComparer = new LanguageComparer(localEpisode.Series.LanguageProfile);
|
var languageComparer = new LanguageComparer(localEpisode.Series.LanguageProfile);
|
||||||
|
var preferredWordScore = GetPreferredWordScore(localEpisode);
|
||||||
|
|
||||||
foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0))
|
foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0))
|
||||||
{
|
{
|
||||||
@ -45,7 +55,6 @@ public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem down
|
|||||||
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Same quality, is not a language upgrade, propers/repacks are preferred and it is not a revision update
|
// Same quality, is not a language upgrade, propers/repacks are preferred and it is not a revision update
|
||||||
// This will allow language upgrades of a lower revision to be imported, which are allowed to be grabbed,
|
// This will allow language upgrades of a lower revision to be imported, which are allowed to be grabbed,
|
||||||
// they just don't import automatically.
|
// they just don't import automatically.
|
||||||
@ -56,17 +65,48 @@ public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem down
|
|||||||
localEpisode.Quality.Revision.CompareTo(episodeFile.Quality.Revision) < 0)
|
localEpisode.Quality.Revision.CompareTo(episodeFile.Quality.Revision) < 0)
|
||||||
{
|
{
|
||||||
_logger.Debug("This file isn't a quality revision upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
_logger.Debug("This file isn't a quality revision upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
||||||
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
return Decision.Reject("Not a quality revision upgrade for existing episode file(s)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (languageCompare < 0 && qualityCompare == 0)
|
if (languageCompare < 0 && qualityCompare == 0)
|
||||||
{
|
{
|
||||||
_logger.Debug("This file isn't a language upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
_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.Reject("Not a language upgrade for existing episode file(s)");
|
||||||
|
}
|
||||||
|
|
||||||
|
var episodeFilePreferredWordScore = _episodeFilePreferredWordCalculator.Calculate(localEpisode.Series, episodeFile);
|
||||||
|
|
||||||
|
if (qualityCompare == 0 && preferredWordScore < episodeFilePreferredWordScore)
|
||||||
|
{
|
||||||
|
_logger.Debug("This file isn't a preferred word upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
||||||
|
return Decision.Reject("Not a preferred word upgrade for existing episode file(s)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Decision.Accept();
|
return Decision.Accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetPreferredWordScore(LocalEpisode localEpisode)
|
||||||
|
{
|
||||||
|
var series = localEpisode.Series;
|
||||||
|
var scores = new List<int>();
|
||||||
|
|
||||||
|
if (localEpisode.FileEpisodeInfo != null)
|
||||||
|
{
|
||||||
|
scores.Add(_preferredWordService.Calculate(series, localEpisode.FileEpisodeInfo.ReleaseTitle, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localEpisode.FolderEpisodeInfo != null)
|
||||||
|
{
|
||||||
|
scores.Add(_preferredWordService.Calculate(series, localEpisode.FolderEpisodeInfo.ReleaseTitle, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localEpisode.DownloadClientEpisodeInfo != null)
|
||||||
|
{
|
||||||
|
scores.Add(_preferredWordService.Calculate(series, localEpisode.DownloadClientEpisodeInfo.ReleaseTitle, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return scores.MaxOrDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user