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 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport _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 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport } [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 @@ namespace NzbDrone.Core.Test.ParserTests } } + [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 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport 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 @@ namespace NzbDrone.Core.Parser var normalizedName = name.Replace('_', ' ').Trim().ToLower(); var result = ParseQualityModifiers(name, normalizedName); - if (RawHDRegex.IsMatch(normalizedName)) { result.Quality = Quality.RAWHD; @@ -276,6 +275,7 @@ namespace NzbDrone.Core.Parser 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 @@ namespace NzbDrone.Core.Qualities { 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 + } +}