parent
0ff08dbe8d
commit
430af0401c
@ -0,0 +1,79 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.History;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport.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 LocalEpisode _localEpisode;
|
||||
private DownloadClientItem _downloadClientItem;
|
||||
private ParsedEpisodeInfo _hdtvParsedEpisodeInfo;
|
||||
private ParsedEpisodeInfo _webdlParsedEpisodeInfo;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_hdtvParsedEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew()
|
||||
.With(p => p.Quality =
|
||||
new QualityModel(Core.Qualities.Quality.HDTV720p))
|
||||
.Build();
|
||||
|
||||
_webdlParsedEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew()
|
||||
.With(p => p.Quality =
|
||||
new QualityModel(Core.Qualities.Quality.WEBDL720p))
|
||||
.Build();
|
||||
|
||||
_localEpisode = Builder<LocalEpisode>.CreateNew()
|
||||
.Build();
|
||||
|
||||
_downloadClientItem = Builder<DownloadClientItem>.CreateNew()
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_if_download_client_item_is_null()
|
||||
{
|
||||
Subject.AugmentQuality(_localEpisode, 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(_localEpisode, _downloadClientItem).Should().BeNull();
|
||||
}
|
||||
|
||||
[TestCase("Series.Title.S01E01.1080p.WEB.x264", QualitySource.Web, Confidence.Tag, 1080, Confidence.Tag)]
|
||||
[TestCase("Series.Title.S01E01.WEB.x264", QualitySource.Web, Confidence.Tag, 480, Confidence.Fallback)]
|
||||
[TestCase("Series.Title.S01E01.720p.x264", QualitySource.Television, Confidence.Fallback, 720, Confidence.Tag)]
|
||||
public void should_return_augmented_quality(string title, QualitySource 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(_localEpisode, _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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
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.EpisodeImport.Aggregation.Aggregators.Augmenters.Quality
|
||||
{
|
||||
public class AugmentQualityFromReleaseName : IAugmentQuality
|
||||
{
|
||||
public int Order => 5;
|
||||
|
||||
private readonly IDownloadHistoryService _downloadHistoryService;
|
||||
|
||||
public AugmentQualityFromReleaseName(IDownloadHistoryService downloadHistoryService)
|
||||
{
|
||||
_downloadHistoryService = downloadHistoryService;
|
||||
}
|
||||
|
||||
public AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, 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;
|
||||
|
||||
return new AugmentQualityResult(historyQuality.Quality.Source, sourceConfidence, historyQuality.Quality.Resolution, resolutionConfidence, historyQuality.Revision);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augmenters.Quality
|
||||
{
|
||||
public interface IAugmentQuality
|
||||
{
|
||||
AugmentQualityResult AugmentQuality(LocalEpisode localEpisode);
|
||||
int Order { get; }
|
||||
AugmentQualityResult AugmentQuality(LocalEpisode localEpisode, DownloadClientItem downloadClientItem);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators
|
||||
{
|
||||
public interface IAggregateLocalEpisode
|
||||
{
|
||||
LocalEpisode Aggregate(LocalEpisode localEpisode, bool otherFiles);
|
||||
LocalEpisode Aggregate(LocalEpisode localEpisode, DownloadClientItem downloadClientItem, bool otherFiles);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue