New: Use release quality source if not in downloaded file and resolution matches

Co-Authored-By: taloth <taloth@users.noreply.github.com>
Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/4873/head
Qstick 4 years ago
parent a6d509c871
commit 28177eb042

@ -62,6 +62,17 @@ namespace NzbDrone.Common.Extensions
return string.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), comparison.Value); return string.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), comparison.Value);
} }
public static string GetPathExtension(this string path)
{
var idx = path.LastIndexOf('.');
if (idx == -1 || idx == path.Length - 1)
{
return string.Empty;
}
return path.Substring(idx);
}
public static string GetRelativePath(this string parentPath, string childPath) public static string GetRelativePath(this string parentPath, string childPath)
{ {
if (!parentPath.IsParentPath(childPath)) if (!parentPath.IsParentPath(childPath))

@ -4,6 +4,7 @@ using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators; using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language; using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language;
@ -41,16 +42,16 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
var clientInfoAugmenter = new Mock<IAugmentLanguage>(); var clientInfoAugmenter = new Mock<IAugmentLanguage>();
var mediaInfoAugmenter = new Mock<IAugmentLanguage>(); var mediaInfoAugmenter = new Mock<IAugmentLanguage>();
fileNameAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>())) fileNameAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns(new AugmentLanguageResult(fileNameLanguages, Confidence.Filename)); .Returns(new AugmentLanguageResult(fileNameLanguages, Confidence.Filename));
folderNameAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>())) folderNameAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns(new AugmentLanguageResult(folderNameLanguages, Confidence.Foldername)); .Returns(new AugmentLanguageResult(folderNameLanguages, Confidence.Foldername));
clientInfoAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>())) clientInfoAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns(new AugmentLanguageResult(clientLanguages, Confidence.DownloadClientItem)); .Returns(new AugmentLanguageResult(clientLanguages, Confidence.DownloadClientItem));
mediaInfoAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>())) mediaInfoAugmenter.Setup(s => s.AugmentLanguage(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns(new AugmentLanguageResult(mediaInfoLanguages, Confidence.MediaInfo)); .Returns(new AugmentLanguageResult(mediaInfoLanguages, Confidence.MediaInfo));
var mocks = new List<Mock<IAugmentLanguage>> { fileNameAugmenter, folderNameAugmenter, clientInfoAugmenter, mediaInfoAugmenter }; var mocks = new List<Mock<IAugmentLanguage>> { fileNameAugmenter, folderNameAugmenter, clientInfoAugmenter, mediaInfoAugmenter };
@ -69,7 +70,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
[Test] [Test]
public void should_return_default_if_no_info_is_known() public void should_return_default_if_no_info_is_known()
{ {
var result = Subject.Aggregate(_localMovie, false); var result = Subject.Aggregate(_localMovie, null, false);
result.Languages.Should().Contain(_movie.OriginalLanguage); result.Languages.Should().Contain(_movie.OriginalLanguage);
} }
@ -82,7 +83,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
null, null,
null); null);
Subject.Aggregate(_localMovie, false).Languages.Should().Equal(new List<Language> { Language.French }); Subject.Aggregate(_localMovie, null, false).Languages.Should().Equal(new List<Language> { Language.French });
} }
[Test] [Test]
@ -93,7 +94,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
null, null,
null); null);
var aggregation = Subject.Aggregate(_localMovie, false); var aggregation = Subject.Aggregate(_localMovie, null, false);
aggregation.Languages.Should().Equal(new List<Language> { Language.German }); aggregation.Languages.Should().Equal(new List<Language> { Language.German });
} }
@ -106,7 +107,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
new List<Language> { Language.Spanish }, new List<Language> { Language.Spanish },
null); null);
Subject.Aggregate(_localMovie, false).Languages.Should().Equal(new List<Language> { Language.Spanish }); Subject.Aggregate(_localMovie, null, false).Languages.Should().Equal(new List<Language> { Language.Spanish });
} }
[Test] [Test]
@ -117,7 +118,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
new List<Language> { Language.Unknown }, new List<Language> { Language.Unknown },
null); null);
Subject.Aggregate(_localMovie, false).Languages.Should().Equal(new List<Language> { Language.French, Language.German }); Subject.Aggregate(_localMovie, null, false).Languages.Should().Equal(new List<Language> { Language.French, Language.German });
} }
[Test] [Test]
@ -128,7 +129,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
new List<Language> { Language.Unknown }, new List<Language> { Language.Unknown },
new List<Language> { Language.Japanese, Language.English }); new List<Language> { Language.Japanese, Language.English });
Subject.Aggregate(_localMovie, false).Languages.Should().Equal(new List<Language> { Language.Japanese, Language.English }); Subject.Aggregate(_localMovie, null, false).Languages.Should().Equal(new List<Language> { Language.Japanese, Language.English });
} }
[Test] [Test]
@ -139,7 +140,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
new List<Language> { Language.Unknown }, new List<Language> { Language.Unknown },
new List<Language> { Language.Unknown }); new List<Language> { Language.Unknown });
Subject.Aggregate(_localMovie, false).Languages.Should().Equal(new List<Language> { Language.French, Language.German }); Subject.Aggregate(_localMovie, null, false).Languages.Should().Equal(new List<Language> { Language.French, Language.German });
} }
} }
} }

@ -3,6 +3,7 @@ using System.Linq;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators; using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality; using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
@ -13,11 +14,12 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
[TestFixture] [TestFixture]
public class AugmentQualityFixture : CoreTest<AggregateQuality> public class AggregateQualityFixture : CoreTest<AggregateQuality>
{ {
private Mock<IAugmentQuality> _mediaInfoAugmenter; private Mock<IAugmentQuality> _mediaInfoAugmenter;
private Mock<IAugmentQuality> _fileExtensionAugmenter; private Mock<IAugmentQuality> _fileExtensionAugmenter;
private Mock<IAugmentQuality> _nameAugmenter; private Mock<IAugmentQuality> _nameAugmenter;
private Mock<IAugmentQuality> _releaseNameAugmenter;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -25,15 +27,23 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
_mediaInfoAugmenter = new Mock<IAugmentQuality>(); _mediaInfoAugmenter = new Mock<IAugmentQuality>();
_fileExtensionAugmenter = new Mock<IAugmentQuality>(); _fileExtensionAugmenter = new Mock<IAugmentQuality>();
_nameAugmenter = new Mock<IAugmentQuality>(); _nameAugmenter = new Mock<IAugmentQuality>();
_releaseNameAugmenter = new Mock<IAugmentQuality>();
_mediaInfoAugmenter.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>())) _fileExtensionAugmenter.SetupGet(s => s.Order).Returns(1);
.Returns(AugmentQualityResult.ResolutionOnly((int)Resolution.R1080p, Confidence.MediaInfo)); _nameAugmenter.SetupGet(s => s.Order).Returns(2);
_mediaInfoAugmenter.SetupGet(s => s.Order).Returns(4);
_releaseNameAugmenter.SetupGet(s => s.Order).Returns(5);
_fileExtensionAugmenter.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>())) _mediaInfoAugmenter.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>())).Returns(AugmentQualityResult.ResolutionOnly((int)Resolution.R1080p, Confidence.MediaInfo));
_fileExtensionAugmenter.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns(new AugmentQualityResult(Source.TV, Confidence.Fallback, (int)Resolution.R720p, Confidence.Fallback, Modifier.NONE, Confidence.Fallback, new Revision())); .Returns(new AugmentQualityResult(Source.TV, Confidence.Fallback, (int)Resolution.R720p, Confidence.Fallback, Modifier.NONE, Confidence.Fallback, new Revision()));
_nameAugmenter.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>())) _nameAugmenter.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns(new AugmentQualityResult(Source.TV, Confidence.Default, (int)Resolution.R480p, Confidence.Default, Modifier.NONE, Confidence.Default, new Revision())); .Returns(new AugmentQualityResult(Source.TV, Confidence.Default, 480, Confidence.Default, Modifier.NONE, Confidence.Fallback, new Revision()));
_releaseNameAugmenter.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns(AugmentQualityResult.SourceOnly(Source.WEBDL, Confidence.MediaInfo));
} }
private void GivenAugmenters(params Mock<IAugmentQuality>[] mocks) private void GivenAugmenters(params Mock<IAugmentQuality>[] mocks)
@ -45,14 +55,15 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
public void should_return_HDTV720_from_extension_when_other_augments_are_null() public void should_return_HDTV720_from_extension_when_other_augments_are_null()
{ {
var nullMock = new Mock<IAugmentQuality>(); var nullMock = new Mock<IAugmentQuality>();
nullMock.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>())) nullMock.Setup(s => s.AugmentQuality(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>()))
.Returns<LocalMovie>(l => null); .Returns<LocalMovie, DownloadClientItem>((l, d) => null);
GivenAugmenters(_fileExtensionAugmenter, nullMock); GivenAugmenters(_fileExtensionAugmenter, nullMock);
var result = Subject.Aggregate(new LocalMovie(), false); var result = Subject.Aggregate(new LocalMovie(), null, false);
result.Quality.QualityDetectionSource.Should().Be(QualityDetectionSource.Extension); result.Quality.SourceDetectionSource.Should().Be(QualityDetectionSource.Extension);
result.Quality.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Extension);
result.Quality.Quality.Should().Be(Quality.HDTV720p); result.Quality.Quality.Should().Be(Quality.HDTV720p);
} }
@ -61,9 +72,10 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
GivenAugmenters(_fileExtensionAugmenter, _nameAugmenter); GivenAugmenters(_fileExtensionAugmenter, _nameAugmenter);
var result = Subject.Aggregate(new LocalMovie(), false); var result = Subject.Aggregate(new LocalMovie(), null, false);
result.Quality.QualityDetectionSource.Should().Be(QualityDetectionSource.Name); result.Quality.SourceDetectionSource.Should().Be(QualityDetectionSource.Name);
result.Quality.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Name);
result.Quality.Quality.Should().Be(Quality.SDTV); result.Quality.Quality.Should().Be(Quality.SDTV);
} }
@ -72,9 +84,10 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
GivenAugmenters(_fileExtensionAugmenter, _mediaInfoAugmenter); GivenAugmenters(_fileExtensionAugmenter, _mediaInfoAugmenter);
var result = Subject.Aggregate(new LocalMovie(), false); var result = Subject.Aggregate(new LocalMovie(), null, false);
result.Quality.QualityDetectionSource.Should().Be(QualityDetectionSource.MediaInfo); result.Quality.SourceDetectionSource.Should().Be(QualityDetectionSource.Extension);
result.Quality.ResolutionDetectionSource.Should().Be(QualityDetectionSource.MediaInfo);
result.Quality.Quality.Should().Be(Quality.HDTV1080p); result.Quality.Quality.Should().Be(Quality.HDTV1080p);
} }
@ -83,10 +96,23 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
GivenAugmenters(_nameAugmenter, _mediaInfoAugmenter); GivenAugmenters(_nameAugmenter, _mediaInfoAugmenter);
var result = Subject.Aggregate(new LocalMovie(), false); var result = Subject.Aggregate(new LocalMovie(), null, false);
result.Quality.QualityDetectionSource.Should().Be(QualityDetectionSource.MediaInfo); result.Quality.SourceDetectionSource.Should().Be(QualityDetectionSource.Name);
result.Quality.ResolutionDetectionSource.Should().Be(QualityDetectionSource.MediaInfo);
result.Quality.Quality.Should().Be(Quality.HDTV1080p); result.Quality.Quality.Should().Be(Quality.HDTV1080p);
} }
[Test]
public void should_return_WEBDL480p_when_file_name_has_HDTV480p_but_release_name_indicates_webdl_source()
{
GivenAugmenters(_nameAugmenter, _releaseNameAugmenter);
var result = Subject.Aggregate(new LocalMovie(), new DownloadClientItem(), false);
result.Quality.SourceDetectionSource.Should().Be(QualityDetectionSource.Name);
result.Quality.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Name);
result.Quality.Quality.Should().Be(Quality.WEBDL480p);
}
} }
} }

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
Movie = _movie Movie = _movie
}; };
Subject.Aggregate(localMovie, false); Subject.Aggregate(localMovie, null, false);
localMovie.ReleaseGroup.Should().Be("Viva"); localMovie.ReleaseGroup.Should().Be("Viva");
} }
@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
Movie = _movie Movie = _movie
}; };
Subject.Aggregate(localMovie, false); Subject.Aggregate(localMovie, null, false);
localMovie.ReleaseGroup.Should().Be("Drone"); localMovie.ReleaseGroup.Should().Be("Drone");
} }
@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
Movie = _movie Movie = _movie
}; };
Subject.Aggregate(localMovie, false); Subject.Aggregate(localMovie, null, false);
localMovie.ReleaseGroup.Should().Be("Wizzy"); localMovie.ReleaseGroup.Should().Be("Wizzy");
} }

@ -20,7 +20,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = null) .With(l => l.MediaInfo = null)
.Build(); .Build();
Subject.AugmentLanguage(localMovie).Should().Be(null); Subject.AugmentLanguage(localMovie, null).Should().Be(null);
} }
[Test] [Test]
@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = mediaInfo) .With(l => l.MediaInfo = mediaInfo)
.Build(); .Build();
var result = Subject.AugmentLanguage(localMovie); var result = Subject.AugmentLanguage(localMovie, null);
result.Languages.Count.Should().Be(1); result.Languages.Count.Should().Be(1);
result.Languages.Should().Contain(Core.Languages.Language.English); result.Languages.Should().Contain(Core.Languages.Language.English);
@ -51,7 +51,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = mediaInfo) .With(l => l.MediaInfo = mediaInfo)
.Build(); .Build();
var result = Subject.AugmentLanguage(localMovie); var result = Subject.AugmentLanguage(localMovie, null);
result.Languages.Count.Should().Be(1); result.Languages.Count.Should().Be(1);
result.Languages.Should().Contain(Core.Languages.Language.English); result.Languages.Should().Contain(Core.Languages.Language.English);
@ -68,7 +68,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = mediaInfo) .With(l => l.MediaInfo = mediaInfo)
.Build(); .Build();
var result = Subject.AugmentLanguage(localMovie); var result = Subject.AugmentLanguage(localMovie, null);
result.Should().BeNull(); result.Should().BeNull();
} }
@ -84,7 +84,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = mediaInfo) .With(l => l.MediaInfo = mediaInfo)
.Build(); .Build();
var result = Subject.AugmentLanguage(localMovie); var result = Subject.AugmentLanguage(localMovie, null);
result.Languages.Count.Should().Be(1); result.Languages.Count.Should().Be(1);
result.Languages.Should().Contain(Core.Languages.Language.English); result.Languages.Should().Contain(Core.Languages.Language.English);
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = mediaInfo) .With(l => l.MediaInfo = mediaInfo)
.Build(); .Build();
var result = Subject.AugmentLanguage(localMovie); var result = Subject.AugmentLanguage(localMovie, null);
result.Languages.Count.Should().Be(2); result.Languages.Count.Should().Be(2);
result.Languages.Should().Contain(Core.Languages.Language.English); result.Languages.Should().Contain(Core.Languages.Language.English);

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = null) .With(l => l.MediaInfo = null)
.Build(); .Build();
Subject.AugmentQuality(localMovie).Should().Be(null); Subject.AugmentQuality(localMovie, null).Should().Be(null);
} }
[Test] [Test]
@ -33,34 +33,36 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augm
.With(l => l.MediaInfo = mediaInfo) .With(l => l.MediaInfo = mediaInfo)
.Build(); .Build();
Subject.AugmentQuality(localMovie).Should().Be(null); Subject.AugmentQuality(localMovie, null).Should().Be(null);
} }
[TestCase(4096, Resolution.R2160p)] // True 4K [TestCase(4096, 1, Resolution.R2160p)] // True 4K
[TestCase(4000, Resolution.R2160p)] [TestCase(4000, 1, Resolution.R2160p)]
[TestCase(3840, Resolution.R2160p)] // 4K UHD [TestCase(3840, 1, Resolution.R2160p)] // 4K UHD
[TestCase(3200, Resolution.R2160p)] [TestCase(3200, 1, Resolution.R2160p)]
[TestCase(2000, Resolution.R1080p)] [TestCase(2000, 1, Resolution.R1080p)]
[TestCase(1920, Resolution.R1080p)] // Full HD [TestCase(1920, 1, Resolution.R1080p)] // Full HD
[TestCase(1800, Resolution.R1080p)] [TestCase(1440, 1080, Resolution.R1080p)] // 4:3 FullHD
[TestCase(1490, Resolution.R720p)] [TestCase(1800, 1, Resolution.R1080p)]
[TestCase(1280, Resolution.R720p)] // HD [TestCase(1490, 1, Resolution.R720p)]
[TestCase(1200, Resolution.R720p)] [TestCase(1280, 1, Resolution.R720p)] // HD
[TestCase(800, Resolution.R480p)] [TestCase(1200, 1, Resolution.R720p)]
[TestCase(720, Resolution.R480p)] // SDTV [TestCase(800, 1, Resolution.R480p)]
[TestCase(600, Resolution.R480p)] [TestCase(720, 1, Resolution.R480p)] // SDTV
[TestCase(100, Resolution.R480p)] [TestCase(600, 1, Resolution.R480p)]
public void should_return_closest_resolution(int mediaInfoWidth, Resolution expectedResolution) [TestCase(100, 1, Resolution.R480p)]
public void should_return_closest_resolution(int mediaInfoWidth, int mediaInfoHeight, Resolution expectedResolution)
{ {
var mediaInfo = Builder<MediaInfoModel>.CreateNew() var mediaInfo = Builder<MediaInfoModel>.CreateNew()
.With(m => m.Width = mediaInfoWidth) .With(m => m.Width = mediaInfoWidth)
.With(m => m.Height = mediaInfoHeight)
.Build(); .Build();
var localMovie = Builder<LocalMovie>.CreateNew() var localMovie = Builder<LocalMovie>.CreateNew()
.With(l => l.MediaInfo = mediaInfo) .With(l => l.MediaInfo = mediaInfo)
.Build(); .Build();
var result = Subject.AugmentQuality(localMovie); var result = Subject.AugmentQuality(localMovie, null);
result.Should().NotBe(null); result.Should().NotBe(null);
result.Resolution.Should().Be((int)expectedResolution); result.Resolution.Should().Be((int)expectedResolution);

@ -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);
}
}
}

@ -102,8 +102,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
private void GivenAugmentationSuccess() private void GivenAugmentationSuccess()
{ {
Mocker.GetMock<IAggregationService>() Mocker.GetMock<IAggregationService>()
.Setup(s => s.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>())) .Setup(s => s.Augment(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>(), It.IsAny<bool>()))
.Callback<LocalMovie, bool>((localMovie, otherFiles) => .Callback<LocalMovie, DownloadClientItem, bool>((localMovie, downloadClientItem, otherFiles) =>
{ {
localMovie.Movie = _localMovie.Movie; localMovie.Movie = _localMovie.Movie;
}); });
@ -173,7 +173,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
GivenSpecifications(_pass1); GivenSpecifications(_pass1);
Mocker.GetMock<IAggregationService>() Mocker.GetMock<IAggregationService>()
.Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>())) .Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>(), It.IsAny<bool>()))
.Throws<TestException>(); .Throws<TestException>();
_videoFiles = new List<string> _videoFiles = new List<string>
@ -188,7 +188,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
Subject.GetImportDecisions(_videoFiles, _movie); Subject.GetImportDecisions(_videoFiles, _movie);
Mocker.GetMock<IAggregationService>() Mocker.GetMock<IAggregationService>()
.Verify(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>()), Times.Exactly(_videoFiles.Count)); .Verify(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>(), It.IsAny<bool>()), Times.Exactly(_videoFiles.Count));
ExceptionVerification.ExpectedErrors(3); ExceptionVerification.ExpectedErrors(3);
} }
@ -209,7 +209,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
var fileNames = _videoFiles.Select(System.IO.Path.GetFileName); var fileNames = _videoFiles.Select(System.IO.Path.GetFileName);
Mocker.GetMock<IAggregationService>() Mocker.GetMock<IAggregationService>()
.Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>())) .Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>(), It.IsAny<bool>()))
.Throws<TestException>(); .Throws<TestException>();
} }
@ -217,7 +217,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport
public void should_return_a_decision_when_exception_is_caught() public void should_return_a_decision_when_exception_is_caught()
{ {
Mocker.GetMock<IAggregationService>() Mocker.GetMock<IAggregationService>()
.Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>())) .Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>(), It.IsAny<bool>()))
.Throws<TestException>(); .Throws<TestException>();
_videoFiles = new List<string> _videoFiles = new List<string>

@ -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();
}
}
}

@ -326,23 +326,66 @@ namespace NzbDrone.Core.Test.ParserTests
} }
} }
[TestCase("Movie - 2018 [HDTV-1080p]")]
[TestCase("Saturday.Night.Live.Vintage.S10E09.Eddie.Murphy.The.Honeydrippers.1080i.UPSCALE.HDTV.DD5.1.MPEG2-zebra")] [TestCase("Saturday.Night.Live.Vintage.S10E09.Eddie.Murphy.The.Honeydrippers.1080i.UPSCALE.HDTV.DD5.1.MPEG2-zebra")]
[TestCase("Dexter - S01E01 - Title [HDTV-1080p]")] [TestCase("Movie.Title.2018.Bluray720p")]
[TestCase("[CR] Sailor Moon - 004 [480p][48CE2D0F]")] [TestCase("Movie.Title.2018.Bluray1080p")]
[TestCase("Movie.Title.2018.Bluray2160p")]
[TestCase("Movie.Title.2018.848x480.dvd")]
[TestCase("Movie.Title.2018.848x480.Bluray")]
[TestCase("Movie.Title.2018.1280x720.Bluray")]
[TestCase("Movie.Title.2018.1920x1080.Bluray")]
public void should_parse_full_quality_from_name(string title)
{
var result = QualityParser.ParseQuality(title);
result.SourceDetectionSource.Should().Be(QualityDetectionSource.Name);
result.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Name);
}
[TestCase("Movie.Title.2018.848x480")]
[TestCase("Movie.Title.2018.1280x720")]
[TestCase("Movie.Title.2018.1920x1080")]
public void should_parse_resolution_from_name(string title)
{
var result = QualityParser.ParseQuality(title);
result.SourceDetectionSource.Should().Be(QualityDetectionSource.Unknown);
result.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Name);
}
[TestCase("White.Van.Man.2011.S02E01.WS.PDTV.x264-REPACK-TLA")] [TestCase("White.Van.Man.2011.S02E01.WS.PDTV.x264-REPACK-TLA")]
public void should_parse_quality_from_name(string title) [TestCase("Series.Title.S01E01.Bluray")]
[TestCase("Series.Title.S01E01.HD.TV")]
[TestCase("Series.Title.S01E01.SD.TV")]
public void should_parse_source_from_name(string title)
{ {
QualityParser.ParseQuality(title).QualityDetectionSource.Should().Be(QualityDetectionSource.Name); var result = QualityParser.ParseQuality(title);
result.SourceDetectionSource.Should().Be(QualityDetectionSource.Name);
result.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Unknown);
} }
[TestCase("Revolution.S01E02.Chained.Heat.mkv")] [TestCase("Revolution.S01E02.Chained.Heat.mkv")]
[TestCase("Star.Wars.Episode.VII.The.Force.Awakens.mk3d")]
[TestCase("Dexter - S01E01 - Title.avi")] [TestCase("Dexter - S01E01 - Title.avi")]
[TestCase("the_x-files.9x18.sunshine_days.avi")] [TestCase("the_x-files.9x18.sunshine_days.avi")]
[TestCase("[CR] Sailor Moon - 004 [48CE2D0F].avi")] [TestCase("[CR] Sailor Moon - 004 [48CE2D0F].avi")]
public void should_parse_quality_from_extension(string title) public void should_parse_quality_from_extension(string title)
{ {
QualityParser.ParseQuality(title).QualityDetectionSource.Should().Be(QualityDetectionSource.Extension); var result = QualityParser.ParseQuality(title);
result.SourceDetectionSource.Should().Be(QualityDetectionSource.Extension);
result.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Extension);
}
[TestCase("Revolution.S01E02.Chained.Heat.1080p.mkv")]
[TestCase("Dexter - S01E01 - Title.720p.avi")]
public void should_parse_resolution_from_name_and_source_from_extension(string title)
{
var result = QualityParser.ParseQuality(title);
result.SourceDetectionSource.Should().Be(QualityDetectionSource.Extension);
result.ResolutionDetectionSource.Should().Be(QualityDetectionSource.Name);
} }
[TestCase("Movie.Title.2016.1080p.KORSUB.WEBRip.x264.AAC2.0-RADARR", "KORSUB")] [TestCase("Movie.Title.2016.1080p.KORSUB.WEBRip.x264.AAC2.0-RADARR", "KORSUB")]

@ -12,6 +12,7 @@ namespace NzbDrone.Core.Download.History
{ {
bool DownloadAlreadyImported(string downloadId); bool DownloadAlreadyImported(string downloadId);
DownloadHistory GetLatestDownloadHistoryItem(string downloadId); DownloadHistory GetLatestDownloadHistoryItem(string downloadId);
DownloadHistory GetLatestGrab(string downloadId);
} }
public class DownloadHistoryService : IDownloadHistoryService, public class DownloadHistoryService : IDownloadHistoryService,
@ -84,6 +85,12 @@ namespace NzbDrone.Core.Download.History
return null; return null;
} }
public DownloadHistory GetLatestGrab(string downloadId)
{
return _repository.FindByDownloadId(downloadId)
.FirstOrDefault(d => d.EventType == DownloadHistoryEventType.DownloadGrabbed);
}
public void Handle(MovieGrabbedEvent message) public void Handle(MovieGrabbedEvent message)
{ {
// Don't store grabbed events for clients that don't download IDs // Don't store grabbed events for clients that don't download IDs

@ -4,6 +4,7 @@ using System.IO;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators; using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -12,7 +13,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation
{ {
public interface IAggregationService public interface IAggregationService
{ {
LocalMovie Augment(LocalMovie localMovie, bool otherFiles); LocalMovie Augment(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles);
} }
public class AggregationService : IAggregationService public class AggregationService : IAggregationService
@ -36,7 +37,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation
_logger = logger; _logger = logger;
} }
public LocalMovie Augment(LocalMovie localMovie, bool otherFiles) public LocalMovie Augment(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles)
{ {
var isMediaFile = MediaFileExtensions.Extensions.Contains(Path.GetExtension(localMovie.Path)); var isMediaFile = MediaFileExtensions.Extensions.Contains(Path.GetExtension(localMovie.Path));
@ -61,7 +62,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation
{ {
try try
{ {
augmenter.Aggregate(localMovie, otherFiles); augmenter.Aggregate(localMovie, downloadClientItem, otherFiles);
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -1,11 +1,12 @@
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
public class AggregateEdition : IAggregateLocalMovie public class AggregateEdition : IAggregateLocalMovie
{ {
public LocalMovie Aggregate(LocalMovie localMovie, bool otherFiles) public LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles)
{ {
var movieEdition = localMovie.DownloadClientMovieInfo?.Edition; var movieEdition = localMovie.DownloadClientMovieInfo?.Edition;

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.Download;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language; using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -9,27 +10,31 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
public class AggregateLanguage : IAggregateLocalMovie public class AggregateLanguage : IAggregateLocalMovie
{ {
private readonly IEnumerable<IAugmentLanguage> _augmentQualities; private readonly List<IAugmentLanguage> _augmentLanguages;
private readonly Logger _logger; private readonly Logger _logger;
public AggregateLanguage(IEnumerable<IAugmentLanguage> augmentQualities, public AggregateLanguage(IEnumerable<IAugmentLanguage> augmentLanguages,
Logger logger) Logger logger)
{ {
_augmentQualities = augmentQualities; _augmentLanguages = augmentLanguages.OrderBy(a => a.Order).ToList();
_logger = logger; _logger = logger;
} }
public LocalMovie Aggregate(LocalMovie localMovie, bool otherFiles) public LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles)
{ {
var augmentedLanguages = _augmentQualities.Select(a => a.AugmentLanguage(localMovie))
.Where(a => a != null)
.OrderBy(a => a.Confidence);
var languages = new List<Language> { localMovie.Movie.OriginalLanguage ?? Language.Unknown }; var languages = new List<Language> { localMovie.Movie.OriginalLanguage ?? Language.Unknown };
var languagesConfidence = Confidence.Default; var languagesConfidence = Confidence.Default;
foreach (var augmentedLanguage in augmentedLanguages) foreach (var augmentLanguage in _augmentLanguages)
{ {
var augmentedLanguage = augmentLanguage.AugmentLanguage(localMovie, downloadClientItem);
if (augmentedLanguage == null)
{
continue;
}
_logger.Trace("Considering Languages {0} ({1}) from {2}", string.Join(", ", augmentedLanguage.Languages ?? new List<Language>()), augmentedLanguage.Confidence, augmentLanguage.Name);
if (augmentedLanguage?.Languages != null && augmentedLanguage.Languages.Count > 0 && !(augmentedLanguage.Languages.Count == 1 && augmentedLanguage.Languages.Contains(Language.Unknown))) if (augmentedLanguage?.Languages != null && augmentedLanguage.Languages.Count > 0 && !(augmentedLanguage.Languages.Count == 1 && augmentedLanguage.Languages.Contains(Language.Unknown)))
{ {
languages = augmentedLanguage.Languages; languages = augmentedLanguage.Languages;
@ -37,7 +42,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
} }
} }
_logger.Debug("Using languages: {0}", string.Join(", ", languages.ToList())); _logger.Debug("Selected languages: {0}", string.Join(", ", languages.ToList()));
localMovie.Languages = languages; localMovie.Languages = languages;

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality; using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
@ -9,40 +10,44 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
public class AggregateQuality : IAggregateLocalMovie public class AggregateQuality : IAggregateLocalMovie
{ {
private readonly IEnumerable<IAugmentQuality> _augmentQualities; private readonly List<IAugmentQuality> _augmentQualities;
private readonly Logger _logger; private readonly Logger _logger;
public AggregateQuality(IEnumerable<IAugmentQuality> augmentQualities, public AggregateQuality(IEnumerable<IAugmentQuality> augmentQualities,
Logger logger) Logger logger)
{ {
_augmentQualities = augmentQualities; _augmentQualities = augmentQualities.OrderBy(a => a.Order).ToList();
_logger = logger; _logger = logger;
} }
public LocalMovie Aggregate(LocalMovie localMovie, bool otherFiles) public LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles)
{ {
var augmentedQualities = _augmentQualities.Select(a => a.AugmentQuality(localMovie))
.Where(a => a != null)
.OrderBy(a => a.SourceConfidence);
var source = Source.UNKNOWN; var source = Source.UNKNOWN;
var sourceConfidence = Confidence.Default; var sourceConfidence = Confidence.Default;
var resolution = 0; var resolution = 0;
var resolutionConfidence = Confidence.Default; var resolutionConfidence = Confidence.Default;
var modifier = Modifier.NONE; var modifier = Modifier.NONE;
var modifierConfidence = Confidence.Default; var modifierConfidence = Confidence.Default;
var revison = new Revision(); var revision = new Revision();
foreach (var augmentedQuality in augmentedQualities) foreach (var augmentQuality in _augmentQualities)
{ {
if (augmentedQuality.Source > source || var augmentedQuality = augmentQuality.AugmentQuality(localMovie, downloadClientItem);
if (augmentedQuality == null)
{
continue;
}
_logger.Trace("Considering Source {0} ({1}) Resolution {2} ({3}) Revision {4} from {5}", augmentedQuality.Source, augmentedQuality.SourceConfidence, augmentedQuality.Resolution, augmentedQuality.ResolutionConfidence, augmentedQuality.Revision, augmentQuality.Name);
if (source == Source.UNKNOWN ||
(augmentedQuality.SourceConfidence > sourceConfidence && augmentedQuality.Source != Source.UNKNOWN)) (augmentedQuality.SourceConfidence > sourceConfidence && augmentedQuality.Source != Source.UNKNOWN))
{ {
source = augmentedQuality.Source; source = augmentedQuality.Source;
sourceConfidence = augmentedQuality.SourceConfidence; sourceConfidence = augmentedQuality.SourceConfidence;
} }
if (augmentedQuality.Resolution > resolution || if (resolution == 0 ||
(augmentedQuality.ResolutionConfidence > resolutionConfidence && augmentedQuality.Resolution > 0)) (augmentedQuality.ResolutionConfidence > resolutionConfidence && augmentedQuality.Resolution > 0))
{ {
resolution = augmentedQuality.Resolution; resolution = augmentedQuality.Resolution;
@ -56,27 +61,36 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
modifierConfidence = augmentedQuality.ModifierConfidence; modifierConfidence = augmentedQuality.ModifierConfidence;
} }
if (augmentedQuality.Revision != null && augmentedQuality.Revision > revison) if (augmentedQuality.Revision != null && augmentedQuality.Revision > revision)
{ {
revison = augmentedQuality.Revision; revision = augmentedQuality.Revision;
} }
} }
_logger.Trace("Finding quality. Source: {0}. Resolution: {1}. Modifier {2}", source, resolution, modifier); _logger.Trace("Selected Source {0} ({1}) Resolution {2} ({3}) Revision {4}", source, sourceConfidence, resolution, resolutionConfidence, revision);
var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution, modifier), revison); var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution, modifier), revision);
if (resolutionConfidence == Confidence.MediaInfo) if (resolutionConfidence == Confidence.MediaInfo)
{ {
quality.QualityDetectionSource = QualityDetectionSource.MediaInfo; quality.ResolutionDetectionSource = QualityDetectionSource.MediaInfo;
} }
else if (sourceConfidence == Confidence.Fallback || resolutionConfidence == Confidence.Fallback) else if (resolutionConfidence == Confidence.Fallback)
{
quality.ResolutionDetectionSource = QualityDetectionSource.Extension;
}
else
{
quality.ResolutionDetectionSource = QualityDetectionSource.Name;
}
if (sourceConfidence == Confidence.Fallback)
{ {
quality.QualityDetectionSource = QualityDetectionSource.Extension; quality.SourceDetectionSource = QualityDetectionSource.Extension;
} }
else else
{ {
quality.QualityDetectionSource = QualityDetectionSource.Name; quality.SourceDetectionSource = QualityDetectionSource.Name;
} }
_logger.Debug("Using quality: {0}", quality); _logger.Debug("Using quality: {0}", quality);

@ -1,11 +1,12 @@
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
public class AggregateReleaseGroup : IAggregateLocalMovie public class AggregateReleaseGroup : IAggregateLocalMovie
{ {
public LocalMovie Aggregate(LocalMovie localMovie, bool otherFiles) public LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles)
{ {
var releaseGroup = localMovie.DownloadClientMovieInfo?.ReleaseGroup; var releaseGroup = localMovie.DownloadClientMovieInfo?.ReleaseGroup;

@ -1,10 +1,14 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language
{ {
public class AugmentLanguageFromDownloadClientItem : IAugmentLanguage public class AugmentLanguageFromDownloadClientItem : IAugmentLanguage
{ {
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie) public int Order => 3;
public string Name => "DownloadClientItem";
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
var languages = localMovie.DownloadClientMovieInfo?.Languages; var languages = localMovie.DownloadClientMovieInfo?.Languages;

@ -1,10 +1,14 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language
{ {
public class AugmentLanguageFromFileName : IAugmentLanguage public class AugmentLanguageFromFileName : IAugmentLanguage
{ {
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie) public int Order => 1;
public string Name => "FileName";
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
var languages = localMovie.FileMovieInfo?.Languages; var languages = localMovie.FileMovieInfo?.Languages;

@ -1,10 +1,14 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language
{ {
public class AugmentLanguageFromFolder : IAugmentLanguage public class AugmentLanguageFromFolder : IAugmentLanguage
{ {
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie) public int Order => 2;
public string Name => "FolderName";
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
var languages = localMovie.FolderMovieInfo?.Languages; var languages = localMovie.FolderMovieInfo?.Languages;

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -8,7 +9,10 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
{ {
public class AugmentLanguageFromMediaInfo : IAugmentLanguage public class AugmentLanguageFromMediaInfo : IAugmentLanguage
{ {
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie) public int Order => 4;
public string Name => "MediaInfo";
public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
if (localMovie.MediaInfo == null) if (localMovie.MediaInfo == null)
{ {

@ -4,6 +4,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
{ {
public class AugmentLanguageResult public class AugmentLanguageResult
{ {
public string Name { get; set; }
public List<Languages.Language> Languages { get; set; } public List<Languages.Language> Languages { get; set; }
public Confidence Confidence { get; set; } public Confidence Confidence { get; set; }

@ -1,9 +1,12 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language
{ {
public interface IAugmentLanguage public interface IAugmentLanguage
{ {
AugmentLanguageResult AugmentLanguage(LocalMovie localMovie); int Order { get; }
string Name { get; }
AugmentLanguageResult AugmentLanguage(LocalMovie localMovie, DownloadClientItem downloadClientItem);
} }
} }

@ -1,10 +1,15 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality
{ {
public class AugmentQualityFromDownloadClientItem : IAugmentQuality public class AugmentQualityFromDownloadClientItem : IAugmentQuality
{ {
public AugmentQualityResult AugmentQuality(LocalMovie localMovie) public int Order => 3;
public string Name => "DownloadClientItem";
public AugmentQualityResult AugmentQuality(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
var quality = localMovie.DownloadClientMovieInfo?.Quality; var quality = localMovie.DownloadClientMovieInfo?.Quality;
@ -13,12 +18,24 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
return null; return null;
} }
var sourceConfidence = quality.SourceDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
var resolutionConfidence = quality.ResolutionDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
var modifierConfidence = quality.ModifierDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
return new AugmentQualityResult(quality.Quality.Source, return new AugmentQualityResult(quality.Quality.Source,
Confidence.Tag, sourceConfidence,
quality.Quality.Resolution, quality.Quality.Resolution,
Confidence.Tag, resolutionConfidence,
quality.Quality.Modifier, quality.Quality.Modifier,
Confidence.Tag, modifierConfidence,
quality.Revision); quality.Revision);
} }
} }

@ -1,3 +1,4 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
@ -5,7 +6,10 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
{ {
public class AugmentQualityFromFileName : IAugmentQuality public class AugmentQualityFromFileName : IAugmentQuality
{ {
public AugmentQualityResult AugmentQuality(LocalMovie localMovie) public int Order => 1;
public string Name => "FileName";
public AugmentQualityResult AugmentQuality(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
var quality = localMovie.FileMovieInfo?.Quality; var quality = localMovie.FileMovieInfo?.Quality;
@ -14,16 +18,24 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
return null; return null;
} }
var confidence = quality.QualityDetectionSource == QualityDetectionSource.Extension var sourceConfidence = quality.SourceDetectionSource == QualityDetectionSource.Name
? Confidence.Fallback ? Confidence.Tag
: Confidence.Tag; : Confidence.Fallback;
var resolutionConfidence = quality.ResolutionDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
var modifierConfidence = quality.ModifierDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
return new AugmentQualityResult(quality.Quality.Source, return new AugmentQualityResult(quality.Quality.Source,
confidence, sourceConfidence,
quality.Quality.Resolution, quality.Quality.Resolution,
confidence, resolutionConfidence,
quality.Quality.Modifier, quality.Quality.Modifier,
confidence, modifierConfidence,
quality.Revision); quality.Revision);
} }
} }

@ -1,10 +1,15 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality
{ {
public class AugmentQualityFromFolder : IAugmentQuality public class AugmentQualityFromFolder : IAugmentQuality
{ {
public AugmentQualityResult AugmentQuality(LocalMovie localMovie) public int Order => 2;
public string Name => "FolderName";
public AugmentQualityResult AugmentQuality(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
var quality = localMovie.FolderMovieInfo?.Quality; var quality = localMovie.FolderMovieInfo?.Quality;
@ -13,12 +18,24 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
return null; return null;
} }
var sourceConfidence = quality.SourceDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
var resolutionConfidence = quality.ResolutionDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
var modifierConfidence = quality.ModifierDetectionSource == QualityDetectionSource.Name
? Confidence.Tag
: Confidence.Fallback;
return new AugmentQualityResult(quality.Quality.Source, return new AugmentQualityResult(quality.Quality.Source,
Confidence.Tag, sourceConfidence,
quality.Quality.Resolution, quality.Quality.Resolution,
Confidence.Tag, resolutionConfidence,
quality.Quality.Modifier, quality.Quality.Modifier,
Confidence.Tag, modifierConfidence,
quality.Revision); quality.Revision);
} }
} }

@ -1,3 +1,5 @@
using NLog;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -5,7 +7,17 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
{ {
public class AugmentQualityFromMediaInfo : IAugmentQuality public class AugmentQualityFromMediaInfo : IAugmentQuality
{ {
public AugmentQualityResult AugmentQuality(LocalMovie localMovie) private readonly Logger _logger;
public int Order => 4;
public string Name => "MediaInfo";
public AugmentQualityFromMediaInfo(Logger logger)
{
_logger = logger;
}
public AugmentQualityResult AugmentQuality(LocalMovie localMovie, DownloadClientItem downloadClientItem)
{ {
if (localMovie.MediaInfo == null) if (localMovie.MediaInfo == null)
{ {
@ -13,27 +25,34 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
} }
var width = localMovie.MediaInfo.Width; var width = localMovie.MediaInfo.Width;
var height = localMovie.MediaInfo.Height;
if (width >= 3200) if (width >= 3200 || height >= 2100)
{ {
_logger.Trace("Resolution {0}x{1} considered 2160p", width, height);
return AugmentQualityResult.ResolutionOnly((int)Resolution.R2160p, Confidence.MediaInfo); return AugmentQualityResult.ResolutionOnly((int)Resolution.R2160p, Confidence.MediaInfo);
} }
if (width >= 1800) if (width >= 1800 || height >= 1000)
{ {
_logger.Trace("Resolution {0}x{1} considered 1080p", width, height);
return AugmentQualityResult.ResolutionOnly((int)Resolution.R1080p, Confidence.MediaInfo); return AugmentQualityResult.ResolutionOnly((int)Resolution.R1080p, Confidence.MediaInfo);
} }
if (width >= 1200) if (width >= 1200 || height >= 700)
{ {
_logger.Trace("Resolution {0}x{1} considered 720p", width, height);
return AugmentQualityResult.ResolutionOnly((int)Resolution.R720p, Confidence.MediaInfo); return AugmentQualityResult.ResolutionOnly((int)Resolution.R720p, Confidence.MediaInfo);
} }
if (width > 0) if (width > 0 && height > 0)
{ {
_logger.Trace("Resolution {0}x{1} considered 480p", width, height);
return AugmentQualityResult.ResolutionOnly((int)Resolution.R480p, Confidence.MediaInfo); return AugmentQualityResult.ResolutionOnly((int)Resolution.R480p, Confidence.MediaInfo);
} }
_logger.Trace("Resolution {0}x{1}", width, height);
return null; return null;
} }
} }

@ -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);
}
}
}

@ -4,6 +4,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenter
{ {
public class AugmentQualityResult public class AugmentQualityResult
{ {
public string Name { get; set; }
public Source Source { get; set; } public Source Source { get; set; }
public Confidence SourceConfidence { get; set; } public Confidence SourceConfidence { get; set; }
public int Resolution { get; set; } public int Resolution { get; set; }

@ -1,9 +1,13 @@
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Quality
{ {
public interface IAugmentQuality 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; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators
{ {
public interface IAggregateLocalMovie public interface IAggregateLocalMovie
{ {
LocalMovie Aggregate(LocalMovie localMovie, bool otherFiles); LocalMovie Aggregate(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles);
} }
} }

@ -109,7 +109,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport
try try
{ {
_aggregationService.Augment(localMovie, otherFiles); _aggregationService.Augment(localMovie, downloadClientItem, otherFiles);
if (localMovie.Movie == null) if (localMovie.Movie == null)
{ {

@ -266,7 +266,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Manual
localMovie.FolderMovieInfo = Parser.Parser.ParseMovieTitle(file.FolderName); localMovie.FolderMovieInfo = Parser.Parser.ParseMovieTitle(file.FolderName);
} }
localMovie = _aggregationService.Augment(localMovie, false); localMovie = _aggregationService.Augment(localMovie, trackedDownload?.DownloadItem, false);
// Apply the user-chosen values. // Apply the user-chosen values.
localMovie.Movie = movie; localMovie.Movie = movie;

@ -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();
}
}
}

@ -1,4 +1,4 @@
using System; using System;
using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
@ -46,7 +46,7 @@ namespace NzbDrone.Core.Parser.Augmenters
if (existing != quality.Quality.Resolution) if (existing != quality.Quality.Resolution)
{ {
//_logger.Debug("Overwriting resolution info {0} with info from media info {1}", existing, quality.Resolution); //_logger.Debug("Overwriting resolution info {0} with info from media info {1}", existing, quality.Resolution);
quality.QualityDetectionSource = QualityDetectionSource.MediaInfo; quality.ResolutionDetectionSource = QualityDetectionSource.MediaInfo;
movieInfo.Quality = quality; movieInfo.Quality = quality;
} }
} }

@ -62,7 +62,7 @@ namespace NzbDrone.Core.Parser
private static readonly Regex OtherSourceRegex = new Regex(@"(?<hdtv>HD[-_. ]TV)|(?<sdtv>SD[-_. ]TV)", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex OtherSourceRegex = new Regex(@"(?<hdtv>HD[-_. ]TV)|(?<sdtv>SD[-_. ]TV)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex AnimeBlurayRegex = new Regex(@"bd(?:720|1080)|(?<=[-_. (\[])bd(?=[-_. )\]])", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex AnimeBlurayRegex = new Regex(@"bd(?:720|1080|2160)|(?<=[-_. (\[])bd(?=[-_. )\]])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex HighDefPdtvRegex = new Regex(@"hr[-_. ]ws", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex HighDefPdtvRegex = new Regex(@"hr[-_. ]ws", RegexOptions.Compiled | RegexOptions.IgnoreCase);
@ -87,7 +87,9 @@ namespace NzbDrone.Core.Parser
try try
{ {
result.Quality = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name)); result.Quality = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name));
result.QualityDetectionSource = QualityDetectionSource.Extension; result.SourceDetectionSource = QualityDetectionSource.Extension;
result.ResolutionDetectionSource = QualityDetectionSource.Extension;
result.ModifierDetectionSource = QualityDetectionSource.Extension;
} }
catch (ArgumentException) catch (ArgumentException)
{ {
@ -124,8 +126,15 @@ namespace NzbDrone.Core.Parser
var remuxMatch = RemuxRegex.IsMatch(normalizedName); var remuxMatch = RemuxRegex.IsMatch(normalizedName);
var brDiskMatch = BRDISKRegex.IsMatch(normalizedName); var brDiskMatch = BRDISKRegex.IsMatch(normalizedName);
if (resolution != Resolution.Unknown)
{
result.ResolutionDetectionSource = QualityDetectionSource.Name;
}
if (sourceMatch != null && sourceMatch.Success) if (sourceMatch != null && sourceMatch.Success)
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
if (sourceMatch.Groups["bluray"].Success) if (sourceMatch.Groups["bluray"].Success)
{ {
if (brDiskMatch) if (brDiskMatch)
@ -348,6 +357,7 @@ namespace NzbDrone.Core.Parser
if (HighDefPdtvRegex.IsMatch(normalizedName)) if (HighDefPdtvRegex.IsMatch(normalizedName))
{ {
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.HDTV720p; result.Quality = Quality.HDTV720p;
return result; return result;
} }
@ -360,20 +370,25 @@ namespace NzbDrone.Core.Parser
// Anime Bluray matching // Anime Bluray matching
if (AnimeBlurayRegex.Match(normalizedName).Success) if (AnimeBlurayRegex.Match(normalizedName).Success)
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
if (resolution == Resolution.R360p || resolution == Resolution.R480p || resolution == Resolution.R576p || normalizedName.ContainsIgnoreCase("480p")) if (resolution == Resolution.R360p || resolution == Resolution.R480p || resolution == Resolution.R576p || normalizedName.ContainsIgnoreCase("480p"))
{ {
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.DVD; result.Quality = Quality.DVD;
return result; return result;
} }
if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p")) if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p"))
{ {
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = remuxMatch ? Quality.Remux1080p : Quality.Bluray1080p; result.Quality = remuxMatch ? Quality.Remux1080p : Quality.Bluray1080p;
return result; return result;
} }
if (resolution == Resolution.R2160p || normalizedName.ContainsIgnoreCase("2160p")) if (resolution == Resolution.R2160p || normalizedName.ContainsIgnoreCase("2160p"))
{ {
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = remuxMatch ? Quality.Remux2160p : Quality.Bluray2160p; result.Quality = remuxMatch ? Quality.Remux2160p : Quality.Bluray2160p;
return result; return result;
} }
@ -389,28 +404,78 @@ namespace NzbDrone.Core.Parser
return result; return result;
} }
if (resolution == Resolution.R2160p) if (resolution != Resolution.Unknown)
{ {
result.Quality = remuxMatch ? Quality.Remux2160p : Quality.HDTV2160p; var source = Source.UNKNOWN;
return result; var modifier = Modifier.NONE;
}
if (resolution == Resolution.R1080p) if (remuxMatch)
{ {
result.Quality = remuxMatch ? Quality.Remux1080p : Quality.HDTV1080p; result.SourceDetectionSource = QualityDetectionSource.Name;
return result; source = Source.BLURAY;
} modifier = Modifier.REMUX;
}
else
{
try
{
var quality = MediaFileExtensions.GetQualityForExtension(name.GetPathExtension());
if (resolution == Resolution.R720p) if (quality != Quality.Unknown)
{ {
result.Quality = Quality.HDTV720p; result.SourceDetectionSource = QualityDetectionSource.Extension;
return result; source = quality.Source;
} }
}
catch (ArgumentException ex)
{
Logger.Debug(ex, "Unable to parse quality from extension");
}
}
if (resolution == Resolution.R360p || resolution == Resolution.R480p) if (resolution == Resolution.R2160p)
{ {
result.Quality = Quality.SDTV; result.ResolutionDetectionSource = QualityDetectionSource.Name;
return result;
result.Quality = source == Source.UNKNOWN
? Quality.HDTV2160p
: QualityFinder.FindBySourceAndResolution(source, 2160, modifier);
return result;
}
if (resolution == Resolution.R1080p)
{
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = source == Source.UNKNOWN
? Quality.HDTV1080p
: QualityFinder.FindBySourceAndResolution(source, 1080, modifier);
return result;
}
if (resolution == Resolution.R720p)
{
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = source == Source.UNKNOWN
? Quality.HDTV720p
: QualityFinder.FindBySourceAndResolution(source, 720, modifier);
return result;
}
if (resolution == Resolution.R360p || resolution == Resolution.R480p)
{
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = source == Source.UNKNOWN
? Quality.SDTV
: QualityFinder.FindBySourceAndResolution(source, 480, modifier);
return result;
}
} }
if (codecRegex.Groups["x264"].Success) if (codecRegex.Groups["x264"].Success)
@ -421,53 +486,92 @@ namespace NzbDrone.Core.Parser
if (normalizedName.ContainsIgnoreCase("848x480")) if (normalizedName.ContainsIgnoreCase("848x480"))
{ {
if (normalizedName.ContainsIgnoreCase("dvd")) result.ResolutionDetectionSource = QualityDetectionSource.Name;
if (normalizedName.Contains("dvd"))
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.DVD; result.Quality = Quality.DVD;
} }
else if (normalizedName.ContainsIgnoreCase("bluray"))
{
result.SourceDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.Bluray480p;
}
else
{
result.Quality = Quality.SDTV;
}
result.Quality = Quality.SDTV; return result;
} }
if (normalizedName.ContainsIgnoreCase("1280x720")) if (normalizedName.ContainsIgnoreCase("1280x720"))
{ {
result.ResolutionDetectionSource = QualityDetectionSource.Name;
if (normalizedName.ContainsIgnoreCase("bluray")) if (normalizedName.ContainsIgnoreCase("bluray"))
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.Bluray720p; result.Quality = Quality.Bluray720p;
} }
else
{
result.Quality = Quality.HDTV720p;
}
result.Quality = Quality.HDTV720p; return result;
} }
if (normalizedName.ContainsIgnoreCase("1920x1080")) if (normalizedName.ContainsIgnoreCase("1920x1080"))
{ {
result.ResolutionDetectionSource = QualityDetectionSource.Name;
if (normalizedName.ContainsIgnoreCase("bluray")) if (normalizedName.ContainsIgnoreCase("bluray"))
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.Bluray1080p; result.Quality = Quality.Bluray1080p;
} }
else
{
result.Quality = Quality.HDTV1080p;
}
result.Quality = Quality.HDTV1080p; return result;
} }
if (normalizedName.ContainsIgnoreCase("bluray720p")) if (normalizedName.ContainsIgnoreCase("bluray720p"))
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.Bluray720p; result.Quality = Quality.Bluray720p;
return result;
} }
if (normalizedName.ContainsIgnoreCase("bluray1080p")) if (normalizedName.ContainsIgnoreCase("bluray1080p"))
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.Bluray1080p; result.Quality = Quality.Bluray1080p;
return result;
} }
if (normalizedName.ContainsIgnoreCase("bluray2160p")) if (normalizedName.ContainsIgnoreCase("bluray2160p"))
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
result.ResolutionDetectionSource = QualityDetectionSource.Name;
result.Quality = Quality.Bluray2160p; result.Quality = Quality.Bluray2160p;
return result;
} }
var otherSourceMatch = OtherSourceMatch(normalizedName); var otherSourceMatch = OtherSourceMatch(normalizedName);
if (otherSourceMatch != Quality.Unknown) if (otherSourceMatch != Quality.Unknown)
{ {
result.SourceDetectionSource = QualityDetectionSource.Name;
result.Quality = otherSourceMatch; result.Quality = otherSourceMatch;
} }

@ -1,7 +1,8 @@
namespace NzbDrone.Core.Qualities namespace NzbDrone.Core.Qualities
{ {
public enum QualityDetectionSource public enum QualityDetectionSource
{ {
Unknown,
Name, Name,
Extension, Extension,
MediaInfo MediaInfo

@ -1,4 +1,4 @@
using System; using System;
using Newtonsoft.Json; using Newtonsoft.Json;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
@ -13,7 +13,13 @@ namespace NzbDrone.Core.Qualities
public string HardcodedSubs { get; set; } public string HardcodedSubs { get; set; }
[JsonIgnore] [JsonIgnore]
public QualityDetectionSource QualityDetectionSource { get; set; } public QualityDetectionSource SourceDetectionSource { get; set; }
[JsonIgnore]
public QualityDetectionSource ResolutionDetectionSource { get; set; }
[JsonIgnore]
public QualityDetectionSource ModifierDetectionSource { get; set; }
public QualityModel() public QualityModel()
: this(Quality.Unknown, new Revision()) : this(Quality.Unknown, new Revision())

Loading…
Cancel
Save