mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-25 22:36:59 -04:00
Fixed: Correctly handle Repack Releases
This commit is contained in:
@@ -17,6 +17,7 @@ using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
using NzbDrone.Core.Test.Languages;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
@@ -411,7 +412,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_put_higher_quality_before_lower_allways()
|
||||
public void should_put_higher_quality_before_lower_always()
|
||||
{
|
||||
var remoteAlbum1 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.MP3_256), Language.French);
|
||||
var remoteAlbum2 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.MP3_320), Language.German);
|
||||
@@ -423,5 +424,88 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteAlbum.ParsedAlbumInfo.Quality.Quality.Should().Be(Quality.MP3_320);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_prefer_higher_score_over_lower_score()
|
||||
{
|
||||
var remoteAlbum1 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC), Language.English);
|
||||
var remoteAlbum2 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC), Language.English);
|
||||
|
||||
remoteAlbum1.PreferredWordScore = 10;
|
||||
remoteAlbum2.PreferredWordScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteAlbum1));
|
||||
decisions.Add(new DownloadDecision(remoteAlbum2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteAlbum.PreferredWordScore.Should().Be(10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_proper_over_score_when_download_propers_is_prefer_and_upgrade()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.PreferAndUpgrade);
|
||||
|
||||
var remoteAlbum1 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC, new Revision(1)), Language.English);
|
||||
var remoteAlbum2 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC, new Revision(2)), Language.English);
|
||||
|
||||
remoteAlbum1.PreferredWordScore = 10;
|
||||
remoteAlbum2.PreferredWordScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteAlbum1));
|
||||
decisions.Add(new DownloadDecision(remoteAlbum2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteAlbum.ParsedAlbumInfo.Quality.Revision.Version.Should().Be(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_proper_over_score_when_download_propers_is_do_not_upgrade()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotUpgrade);
|
||||
|
||||
var remoteAlbum1 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC, new Revision(1)), Language.English);
|
||||
var remoteAlbum2 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC, new Revision(2)), Language.English);
|
||||
|
||||
remoteAlbum1.PreferredWordScore = 10;
|
||||
remoteAlbum2.PreferredWordScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteAlbum1));
|
||||
decisions.Add(new DownloadDecision(remoteAlbum2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteAlbum.ParsedAlbumInfo.Quality.Revision.Version.Should().Be(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_score_over_proper_when_download_propers_is_do_not_prefer()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
var remoteAlbum1 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC, new Revision(1)), Language.English);
|
||||
var remoteAlbum2 = GivenRemoteAlbum(new List<Album> { GivenAlbum(1) }, new QualityModel(Quality.FLAC, new Revision(2)), Language.English);
|
||||
|
||||
remoteAlbum1.PreferredWordScore = 10;
|
||||
remoteAlbum2.PreferredWordScore = 0;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteAlbum1));
|
||||
decisions.Add(new DownloadDecision(remoteAlbum2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteAlbum.ParsedAlbumInfo.Quality.Quality.Should().Be(Quality.FLAC);
|
||||
qualifiedReports.First().RemoteAlbum.ParsedAlbumInfo.Quality.Revision.Version.Should().Be(1);
|
||||
qualifiedReports.First().RemoteAlbum.PreferredWordScore.Should().Be(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Music;
|
||||
using Moq;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RepackSpecificationFixture : CoreTest<RepackSpecification>
|
||||
{
|
||||
private ParsedAlbumInfo _parsedAlbumInfo;
|
||||
private List<Album> _albums;
|
||||
private List<TrackFile> _trackFiles;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.Resolve<UpgradableSpecification>();
|
||||
|
||||
_parsedAlbumInfo = Builder<ParsedAlbumInfo>.CreateNew()
|
||||
.With(p => p.Quality = new QualityModel(Quality.FLAC,
|
||||
new Revision(2, 0, false)))
|
||||
.With(p => p.ReleaseGroup = "Lidarr")
|
||||
.Build();
|
||||
|
||||
_albums = Builder<Album>.CreateListOfSize(1)
|
||||
.All()
|
||||
.BuildList();
|
||||
|
||||
_trackFiles = Builder<TrackFile>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(t => t.AlbumId = _albums.First().Id)
|
||||
.BuildList();
|
||||
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetFilesByAlbum(It.IsAny<int>()))
|
||||
.Returns(_trackFiles);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_it_is_not_a_repack()
|
||||
{
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_there_are_is_no_track_files()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(c => c.GetFilesByAlbum(It.IsAny<int>()))
|
||||
.Returns(new List<TrackFile>());
|
||||
|
||||
_parsedAlbumInfo.Quality.Revision.IsRepack = true;
|
||||
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_is_a_repack_for_a_different_quality()
|
||||
{
|
||||
_parsedAlbumInfo.Quality.Revision.IsRepack = true;
|
||||
|
||||
_trackFiles.Select(c => { c.ReleaseGroup = "Lidarr"; return c; }).ToList();
|
||||
_trackFiles.Select(c => { c.Quality = new QualityModel(Quality.MP3_256); return c; }).ToList();
|
||||
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_is_a_repack_for_all_existing_files()
|
||||
{
|
||||
_parsedAlbumInfo.Quality.Revision.IsRepack = true;
|
||||
|
||||
_trackFiles.Select(c => { c.ReleaseGroup = "Lidarr"; return c; }).ToList();
|
||||
_trackFiles.Select(c => { c.Quality = new QualityModel(Quality.FLAC); return c; }).ToList();
|
||||
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_is_a_repack_for_some_but_not_all_trackfiles()
|
||||
{
|
||||
_parsedAlbumInfo.Quality.Revision.IsRepack = true;
|
||||
|
||||
_trackFiles.Select(c => { c.ReleaseGroup = "Lidarr"; return c; }).ToList();
|
||||
_trackFiles.Select(c => { c.Quality = new QualityModel(Quality.FLAC); return c; }).ToList();
|
||||
|
||||
_trackFiles.First().ReleaseGroup = "NotLidarr";
|
||||
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_is_a_repack_for_different_group()
|
||||
{
|
||||
_parsedAlbumInfo.Quality.Revision.IsRepack = true;
|
||||
|
||||
_trackFiles.Select(c => { c.ReleaseGroup = "NotLidarr"; return c; }).ToList();
|
||||
_trackFiles.Select(c => { c.Quality = new QualityModel(Quality.FLAC); return c; }).ToList();
|
||||
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_release_group_for_existing_file_is_unknown()
|
||||
{
|
||||
_parsedAlbumInfo.Quality.Revision.IsRepack = true;
|
||||
|
||||
_trackFiles.Select(c => { c.ReleaseGroup = ""; return c; }).ToList();
|
||||
_trackFiles.Select(c => { c.Quality = new QualityModel(Quality.FLAC); return c; }).ToList();
|
||||
|
||||
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_release_group_for_release_is_unknown()
|
||||
{
|
||||
_parsedAlbumInfo.Quality.Revision.IsRepack = true;
|
||||
_parsedAlbumInfo.ReleaseGroup = null;
|
||||
|
||||
_trackFiles.Select(c => { c.ReleaseGroup = "Lidarr"; return c; }).ToList();
|
||||
_trackFiles.Select(c => { c.Quality = new QualityModel(Quality.FLAC); return c; }).ToList();
|
||||
|
||||
|
||||
var remoteAlbum = Builder<RemoteAlbum>.CreateNew()
|
||||
.With(e => e.ParsedAlbumInfo = _parsedAlbumInfo)
|
||||
.With(e => e.Albums = _albums)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(remoteAlbum, null)
|
||||
.Accepted
|
||||
.Should()
|
||||
.BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
_firstFile = new TrackFile { Quality = new QualityModel(Quality.FLAC, new Revision(version: 1)), DateAdded = DateTime.Now };
|
||||
_secondFile = new TrackFile { Quality = new QualityModel(Quality.FLAC, new Revision(version: 1)), DateAdded = DateTime.Now };
|
||||
|
||||
var singleEpisodeList = new List<Album> { new Album {}, new Album {} };
|
||||
var doubleEpisodeList = new List<Album> { new Album {}, new Album {}, new Album {} };
|
||||
var singleAlbumList = new List<Album> { new Album {}, new Album {} };
|
||||
var doubleAlbumList = new List<Album> { new Album {}, new Album {}, new Album {} };
|
||||
|
||||
|
||||
var fakeArtist = Builder<Artist>.CreateNew()
|
||||
@@ -51,14 +51,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
{
|
||||
Artist = fakeArtist,
|
||||
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_256, new Revision(version: 2)) },
|
||||
Albums = doubleEpisodeList
|
||||
Albums = doubleAlbumList
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteAlbum
|
||||
{
|
||||
Artist = fakeArtist,
|
||||
ParsedAlbumInfo = new ParsedAlbumInfo { Quality = new QualityModel(Quality.MP3_256, new Revision(version: 2)) },
|
||||
Albums = singleEpisodeList
|
||||
Albums = singleAlbumList
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,13 +67,6 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
_firstFile.Quality = new QualityModel(Quality.MP3_192);
|
||||
}
|
||||
|
||||
private void GivenAutoDownloadPropers()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.AutoDownloadPropers)
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_trackFile_was_added_more_than_7_days_ago()
|
||||
{
|
||||
@@ -124,6 +117,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
[Test]
|
||||
public void should_return_false_when_proper_but_auto_download_propers_is_false()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotUpgrade);
|
||||
|
||||
_firstFile.Quality.Quality = Quality.MP3_256;
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today;
|
||||
@@ -133,7 +130,22 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
[Test]
|
||||
public void should_return_true_when_trackFile_was_added_today()
|
||||
{
|
||||
GivenAutoDownloadPropers();
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.PreferAndUpgrade);
|
||||
|
||||
_firstFile.Quality.Quality = Quality.MP3_256;
|
||||
|
||||
_firstFile.DateAdded = DateTime.Today;
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_propers_are_not_preferred()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.Setup(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
_firstFile.Quality.Quality = Quality.MP3_256;
|
||||
|
||||
|
||||
@@ -38,17 +38,17 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
private static readonly int NoPreferredWordScore = 0;
|
||||
|
||||
private void GivenAutoDownloadPropers(bool autoDownloadPropers)
|
||||
private void GivenAutoDownloadPropers(ProperDownloadTypes type)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(s => s.AutoDownloadPropers)
|
||||
.Returns(autoDownloadPropers);
|
||||
.SetupGet(s => s.DownloadPropersAndRepacks)
|
||||
.Returns(type);
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(nameof(IsUpgradeTestCases))]
|
||||
public void IsUpgradeTest(Quality current, int currentVersion, Quality newQuality, int newVersion, Quality cutoff, bool expected)
|
||||
{
|
||||
GivenAutoDownloadPropers(true);
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.PreferAndUpgrade);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
@@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
[Test, TestCaseSource(nameof(IsUpgradeTestCasesLanguages))]
|
||||
public void IsUpgradeTestLanguage(Quality current, int currentVersion, Language currentLanguage, Quality newQuality, int newVersion, Language newLanguage, Quality cutoff, Language languageCutoff, bool expected)
|
||||
{
|
||||
GivenAutoDownloadPropers(true);
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.PreferAndUpgrade);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
@@ -107,9 +107,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_proper_and_autoDownloadPropers_is_false()
|
||||
public void should_return_true_if_proper_and_download_propers_is_do_not_download()
|
||||
{
|
||||
GivenAutoDownloadPropers(false);
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.DoNotUpgrade);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
@@ -126,13 +126,41 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
langProfile,
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3_256, new Revision(version: 2)) },
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3_256, new Revision(version: 1)) },
|
||||
new List<Language> { Language.English },
|
||||
NoPreferredWordScore,
|
||||
new QualityModel(Quality.MP3_256, new Revision(version: 1)),
|
||||
new QualityModel(Quality.MP3_256, new Revision(version: 2)),
|
||||
Language.English,
|
||||
NoPreferredWordScore)
|
||||
.Should().BeFalse();
|
||||
.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_proper_and_autoDownloadPropers_is_do_not_prefer()
|
||||
{
|
||||
GivenAutoDownloadPropers(ProperDownloadTypes.DoNotPrefer);
|
||||
|
||||
var profile = new QualityProfile
|
||||
{
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(),
|
||||
};
|
||||
|
||||
var langProfile = new LanguageProfile
|
||||
{
|
||||
Languages = LanguageFixture.GetDefaultLanguages(),
|
||||
Cutoff = Language.English
|
||||
};
|
||||
|
||||
Subject.IsUpgradable(
|
||||
profile,
|
||||
langProfile,
|
||||
new List<QualityModel> { new QualityModel(Quality.MP3_256, new Revision(version: 1)) },
|
||||
new List<Language> { Language.English },
|
||||
NoPreferredWordScore,
|
||||
new QualityModel(Quality.MP3_256, new Revision(version: 2)),
|
||||
Language.English,
|
||||
NoPreferredWordScore)
|
||||
.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user