Co-Authored-By: taloth <taloth@users.noreply.github.com> Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>pull/4873/head
parent
a6d509c871
commit
28177eb042
@ -0,0 +1,78 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.History;
|
||||
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augmenters.Quality
|
||||
{
|
||||
[TestFixture]
|
||||
public class AugmentQualityFromReleaseNameFixture : CoreTest<AugmentQualityFromReleaseName>
|
||||
{
|
||||
private LocalMovie _localMovie;
|
||||
private DownloadClientItem _downloadClientItem;
|
||||
private ParsedMovieInfo _hdtvParsedEpisodeInfo;
|
||||
private ParsedMovieInfo _webdlParsedEpisodeInfo;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_hdtvParsedEpisodeInfo = Builder<ParsedMovieInfo>.CreateNew()
|
||||
.With(p => p.Quality =
|
||||
new QualityModel(Core.Qualities.Quality.HDTV720p))
|
||||
.Build();
|
||||
|
||||
_webdlParsedEpisodeInfo = Builder<ParsedMovieInfo>.CreateNew()
|
||||
.With(p => p.Quality =
|
||||
new QualityModel(Core.Qualities.Quality.WEBDL720p))
|
||||
.Build();
|
||||
|
||||
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||
.Build();
|
||||
|
||||
_downloadClientItem = Builder<DownloadClientItem>.CreateNew()
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_if_download_client_item_is_null()
|
||||
{
|
||||
Subject.AugmentQuality(_localMovie, null).Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_if_no_grabbed_history()
|
||||
{
|
||||
Mocker.GetMock<IDownloadHistoryService>()
|
||||
.Setup(s => s.GetLatestGrab(It.IsAny<string>()))
|
||||
.Returns((DownloadHistory)null);
|
||||
|
||||
Subject.AugmentQuality(_localMovie, _downloadClientItem).Should().BeNull();
|
||||
}
|
||||
|
||||
[TestCase("Series.Title.S01E01.1080p.WEB.x264", Source.WEBDL, Confidence.Tag, 1080, Confidence.Tag)]
|
||||
[TestCase("Series.Title.S01E01.WEB.x264", Source.WEBDL, Confidence.Tag, 480, Confidence.Fallback)]
|
||||
[TestCase("Series.Title.S01E01.720p.x264", Source.TV, Confidence.Fallback, 720, Confidence.Tag)]
|
||||
public void should_return_augmented_quality(string title, Source source, Confidence sourceConfidence, int resolution, Confidence resolutionConfidence)
|
||||
{
|
||||
Mocker.GetMock<IDownloadHistoryService>()
|
||||
.Setup(s => s.GetLatestGrab(It.IsAny<string>()))
|
||||
.Returns(Builder<DownloadHistory>.CreateNew()
|
||||
.With(h => h.SourceTitle = title)
|
||||
.Build());
|
||||
|
||||
var result = Subject.AugmentQuality(_localMovie, _downloadClientItem);
|
||||
|
||||
result.Should().NotBe(null);
|
||||
result.Source.Should().Be(source);
|
||||
result.SourceConfidence.Should().Be(sourceConfidence);
|
||||
result.Resolution.Should().Be(resolution);
|
||||
result.ResolutionConfidence.Should().Be(resolutionConfidence);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.MediaFiles.MovieImport.Specifications;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Specifications
|
||||
{
|
||||
[TestFixture]
|
||||
public class DifferentQualitySpecificationFixture : CoreTest<DifferentQualitySpecification>
|
||||
{
|
||||
private LocalMovie _localMovie;
|
||||
private DownloadClientItem _downloadClientItem;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var qualityProfile = new Profile
|
||||
{
|
||||
Cutoff = Quality.Bluray1080p.Id,
|
||||
Items = Qualities.QualityFixture.GetDefaultQualities(Quality.DVD, Quality.HDTV720p, Quality.Bluray1080p)
|
||||
};
|
||||
|
||||
var fakeMovie = Builder<Movie>.CreateNew()
|
||||
.With(c => c.Profile = qualityProfile)
|
||||
.Build();
|
||||
|
||||
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||
.With(l => l.Quality = new QualityModel(Quality.Bluray1080p))
|
||||
.With(l => l.DownloadClientMovieInfo = new ParsedMovieInfo())
|
||||
.With(l => l.Movie = fakeMovie)
|
||||
.Build();
|
||||
|
||||
_downloadClientItem = Builder<DownloadClientItem>.CreateNew()
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void GivenGrabbedMovieHistory(QualityModel quality)
|
||||
{
|
||||
var history = Builder<MovieHistory>.CreateListOfSize(1)
|
||||
.TheFirst(1)
|
||||
.With(h => h.Quality = quality)
|
||||
.With(h => h.EventType = MovieHistoryEventType.Grabbed)
|
||||
.BuildList();
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
.Returns(history);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_accepted_if_no_download_client_item()
|
||||
{
|
||||
Subject.IsSatisfiedBy(_localMovie, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_accepted_if_no_grabbed_movie_history()
|
||||
{
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
.Returns(new List<MovieHistory>());
|
||||
|
||||
_localMovie.Movie = Builder<Movie>.CreateNew()
|
||||
.With(e => e.MovieFileId = 0)
|
||||
.Build();
|
||||
|
||||
Subject.IsSatisfiedBy(_localMovie, _downloadClientItem).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_accepted_if_quality_matches()
|
||||
{
|
||||
GivenGrabbedMovieHistory(_localMovie.Quality);
|
||||
|
||||
Subject.IsSatisfiedBy(_localMovie, _downloadClientItem).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_rejected_if_quality_does_not_match()
|
||||
{
|
||||
GivenGrabbedMovieHistory(new QualityModel(Quality.SDTV));
|
||||
|
||||
Subject.IsSatisfiedBy(_localMovie, _downloadClientItem).Accepted.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language
|
||||
{
|
||||
public interface IAugmentLanguage
|
||||
{
|
||||
AugmentLanguageResult AugmentLanguage(LocalMovie localMovie);
|
||||
int Order { get; }
|
||||
string Name { get; }
|
||||
AugmentLanguageResult AugmentLanguage(LocalMovie localMovie, DownloadClientItem downloadClientItem);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.History;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality
|
||||
{
|
||||
public class AugmentQualityFromReleaseName : IAugmentQuality
|
||||
{
|
||||
public int Order => 5;
|
||||
public string Name => "ReleaseName";
|
||||
|
||||
private readonly IDownloadHistoryService _downloadHistoryService;
|
||||
|
||||
public AugmentQualityFromReleaseName(IDownloadHistoryService downloadHistoryService)
|
||||
{
|
||||
_downloadHistoryService = downloadHistoryService;
|
||||
}
|
||||
|
||||
public AugmentQualityResult AugmentQuality(LocalMovie localMovie, DownloadClientItem downloadClientItem)
|
||||
{
|
||||
// Don't try to augment if we can't lookup the grabbed history by downloadId
|
||||
if (downloadClientItem == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var history = _downloadHistoryService.GetLatestGrab(downloadClientItem.DownloadId);
|
||||
if (history == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var historyQuality = QualityParser.ParseQuality(history.SourceTitle);
|
||||
var sourceConfidence = historyQuality.SourceDetectionSource == QualityDetectionSource.Name
|
||||
? Confidence.Tag
|
||||
: Confidence.Fallback;
|
||||
var resolutionConfidence = historyQuality.ResolutionDetectionSource == QualityDetectionSource.Name
|
||||
? Confidence.Tag
|
||||
: Confidence.Fallback;
|
||||
var modifierConfidence = historyQuality.ModifierDetectionSource == QualityDetectionSource.Name
|
||||
? Confidence.Tag
|
||||
: Confidence.Fallback;
|
||||
|
||||
return new AugmentQualityResult(historyQuality.Quality.Source, sourceConfidence, historyQuality.Quality.Resolution, resolutionConfidence, historyQuality.Quality.Modifier, modifierConfidence, historyQuality.Revision);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality
|
||||
{
|
||||
public interface IAugmentQuality
|
||||
{
|
||||
AugmentQualityResult AugmentQuality(LocalMovie localMovie);
|
||||
int Order { get; }
|
||||
string Name { get; }
|
||||
|
||||
AugmentQualityResult AugmentQuality(LocalMovie localMovie, DownloadClientItem downloadClientItem);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
|
||||
{
|
||||
public interface IAggregateLocalMovie
|
||||
{
|
||||
LocalMovie Aggregate(LocalMovie localMovie, bool otherFiles);
|
||||
LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles);
|
||||
}
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.MovieImport.Specifications
|
||||
{
|
||||
public class DifferentQualitySpecification : IImportDecisionEngineSpecification
|
||||
{
|
||||
private readonly IHistoryService _historyService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public DifferentQualitySpecification(IHistoryService historyService, Logger logger)
|
||||
{
|
||||
_historyService = historyService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Decision IsSatisfiedBy(LocalMovie localMovie, DownloadClientItem downloadClientItem)
|
||||
{
|
||||
if (downloadClientItem == null)
|
||||
{
|
||||
_logger.Debug("No download client item, skipping");
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
var grabbedMovieHistory = _historyService.FindByDownloadId(downloadClientItem.DownloadId)
|
||||
.OrderByDescending(h => h.Date)
|
||||
.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
|
||||
|
||||
if (grabbedMovieHistory == null)
|
||||
{
|
||||
_logger.Debug("No grabbed history for this download item, skipping");
|
||||
return Decision.Accept();
|
||||
}
|
||||
|
||||
var qualityComparer = new QualityModelComparer(localMovie.Movie.Profile);
|
||||
var qualityCompare = qualityComparer.Compare(localMovie.Quality, grabbedMovieHistory.Quality);
|
||||
|
||||
if (qualityCompare != 0)
|
||||
{
|
||||
_logger.Debug("Quality of file ({0}) does not match quality of grabbed history ({1})", localMovie.Quality, grabbedMovieHistory.Quality);
|
||||
return Decision.Reject("Quality of file ({0}) does not match quality of grabbed release ({1})", localMovie.Quality, grabbedMovieHistory.Quality);
|
||||
}
|
||||
|
||||
return Decision.Accept();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue