From a9444cef30c3e86521d80b4447b1fa2b38775875 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 22 Oct 2015 22:21:44 -0700 Subject: [PATCH] Fixed: Folder quality when file quality determined by its extension Closes #603 --- .../ImportDecisionMakerFixture.cs | 18 ++++++++++++------ .../ParserTests/QualityParserFixture.cs | 18 ++++++++++++++++++ .../EpisodeImport/ImportDecisionMaker.cs | 4 +--- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + src/NzbDrone.Core/Parser/QualityParser.cs | 2 +- src/NzbDrone.Core/Qualities/QualityModel.cs | 4 ++++ src/NzbDrone.Core/Qualities/QualitySource.cs | 9 +++++++++ 7 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/NzbDrone.Core/Qualities/QualitySource.cs diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportDecisionMakerFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportDecisionMakerFixture.cs index cba94adfb..93b7316fb 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportDecisionMakerFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/ImportDecisionMakerFixture.cs @@ -84,8 +84,8 @@ private void GivenVideoFiles(IEnumerable videoFiles) _videoFiles = videoFiles.ToList(); Mocker.GetMock() - .Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny())) - .Returns(_videoFiles); + .Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny())) + .Returns(_videoFiles); } [Test] @@ -180,21 +180,27 @@ public void should_use_file_quality_if_folder_quality_is_null() } [Test] - public void should_use_file_quality_if_folder_quality_is_lower_than_file_quality() + public void should_use_file_quality_if_file_quality_was_determined_by_name() { GivenSpecifications(_pass1, _pass2, _pass3); var expectedQuality = QualityParser.ParseQuality(_videoFiles.Single()); - var result = Subject.GetImportDecisions(_videoFiles, _series, new ParsedEpisodeInfo{Quality = new QualityModel(Quality.SDTV)}, true); + var result = Subject.GetImportDecisions(_videoFiles, _series, new ParsedEpisodeInfo{Quality = new QualityModel(Quality.Bluray1080p)}, true); result.Single().LocalEpisode.Quality.Should().Be(expectedQuality); } [Test] - public void should_use_folder_quality_when_it_is_greater_than_file_quality() + public void should_use_folder_quality_when_file_quality_was_determined_by_the_extension() { GivenSpecifications(_pass1, _pass2, _pass3); - var expectedQuality = new QualityModel(Quality.Bluray1080p); + GivenVideoFiles(new string[] { @"C:\Test\Unsorted\The.Office.S03E115.mkv".AsOsAgnostic() }); + + _localEpisode.Path = _videoFiles.Single(); + _localEpisode.Quality.QualitySource = QualitySource.Extension; + _localEpisode.Quality.Quality = Quality.HDTV720p; + + var expectedQuality = new QualityModel(Quality.SDTV); var result = Subject.GetImportDecisions(_videoFiles, _series, new ParsedEpisodeInfo { Quality = expectedQuality }, true); diff --git a/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs index dee8e0926..8378f221c 100644 --- a/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs @@ -228,6 +228,24 @@ public void should_parse_quality_from_other_source(string qualityString, Quality } } + [TestCase("Saturday.Night.Live.Vintage.S10E09.Eddie.Murphy.The.Honeydrippers.1080i.UPSCALE.HDTV.DD5.1.MPEG2-zebra")] + [TestCase("Dexter - S01E01 - Title [HDTV-1080p]")] + [TestCase("[CR] Sailor Moon - 004 [480p][48CE2D0F]")] + [TestCase("White.Van.Man.2011.S02E01.WS.PDTV.x264-REPACK-TLA")] + public void should_parse_quality_from_name(string title) + { + QualityParser.ParseQuality(title).QualitySource.Should().Be(QualitySource.Name); + } + + [TestCase("Revolution.S01E02.Chained.Heat.mkv")] + [TestCase("Dexter - S01E01 - Title.avi")] + [TestCase("the_x-files.9x18.sunshine_days.avi")] + [TestCase("[CR] Sailor Moon - 004 [48CE2D0F].avi")] + public void should_parse_quality_from_extension(string title) + { + QualityParser.ParseQuality(title).QualitySource.Should().Be(QualitySource.Extension); + } + private void ParseAndVerifyQuality(string title, Quality quality, bool proper) { var result = QualityParser.ParseQuality(title); diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs index ae1450167..4965f079a 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs @@ -181,9 +181,7 @@ private bool ShouldUseFolderName(List videoFiles, Series series, ParsedE private QualityModel GetQuality(ParsedEpisodeInfo folderInfo, QualityModel fileQuality, Series series) { - if (folderInfo != null && - folderInfo.Quality.Quality != Quality.Unknown && - new QualityModelComparer(series.Profile).Compare(folderInfo.Quality, fileQuality) > 0) + if (folderInfo != null && folderInfo.Quality.Quality != Quality.Unknown && fileQuality.QualitySource == QualitySource.Extension) { _logger.Debug("Using quality from folder: {0}", folderInfo.Quality); return folderInfo.Quality; diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 7117f823a..386e5b1ca 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -767,6 +767,7 @@ + diff --git a/src/NzbDrone.Core/Parser/QualityParser.cs b/src/NzbDrone.Core/Parser/QualityParser.cs index 81b3b28cc..3ac9bb908 100644 --- a/src/NzbDrone.Core/Parser/QualityParser.cs +++ b/src/NzbDrone.Core/Parser/QualityParser.cs @@ -58,7 +58,6 @@ public static QualityModel ParseQuality(string name) var normalizedName = name.Replace('_', ' ').Trim().ToLower(); var result = ParseQualityModifiers(name, normalizedName); - if (RawHDRegex.IsMatch(normalizedName)) { result.Quality = Quality.RAWHD; @@ -276,6 +275,7 @@ public static QualityModel ParseQuality(string name) try { result.Quality = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name)); + result.QualitySource = QualitySource.Extension; } catch (ArgumentException) { diff --git a/src/NzbDrone.Core/Qualities/QualityModel.cs b/src/NzbDrone.Core/Qualities/QualityModel.cs index c941b131c..a483d22c2 100644 --- a/src/NzbDrone.Core/Qualities/QualityModel.cs +++ b/src/NzbDrone.Core/Qualities/QualityModel.cs @@ -1,4 +1,5 @@ using System; +using Newtonsoft.Json; using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Qualities @@ -7,6 +8,9 @@ public class QualityModel : IEmbeddedDocument, IEquatable { public Quality Quality { get; set; } public Revision Revision { get; set; } + + [JsonIgnore] + public QualitySource QualitySource { get; set; } public QualityModel() : this(Quality.Unknown, new Revision()) diff --git a/src/NzbDrone.Core/Qualities/QualitySource.cs b/src/NzbDrone.Core/Qualities/QualitySource.cs new file mode 100644 index 000000000..5c0c2c81f --- /dev/null +++ b/src/NzbDrone.Core/Qualities/QualitySource.cs @@ -0,0 +1,9 @@ +namespace NzbDrone.Core.Qualities +{ + public enum QualitySource + { + Name, + Extension, + MediaInfo + } +}