From 3d7d43bb464d41b977d134ae3109b6e9dee721cf Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 15 Oct 2023 19:37:51 -0500 Subject: [PATCH] Fixed: Enable parsing of repacks with revision Closes #3320 (cherry picked from commit e29470d8cb9dd3d4d75a3abe1b9b7e8df4f2df4a) --- .../ParserTests/QualityParserFixture.cs | 13 ++++++---- src/NzbDrone.Core/Parser/QualityParser.cs | 26 +++++++++++-------- src/NzbDrone.Core/Qualities/QualityModel.cs | 3 +++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs index c6ae83354..92986c379 100644 --- a/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/QualityParserFixture.cs @@ -307,13 +307,16 @@ namespace NzbDrone.Core.Test.ParserTests QualityParser.ParseCodec(null, null).Should().Be(Codec.Unknown); } - [TestCase("Artist Title - Album Title 2017 REPACK FLAC aAF", true)] - [TestCase("Artist Title - Album Title 2017 RERIP FLAC aAF", true)] - [TestCase("Artist Title - Album Title 2017 PROPER FLAC aAF", false)] - public void should_be_able_to_parse_repack(string title, bool isRepack) + [TestCase("Artist Title - Album Title 2017 REPACK FLAC aAF", true, 2)] + [TestCase("Artist.Title-Album.Title.2017.REPACK.FLAC-aAF", true, 2)] + [TestCase("Artist.Title-Album.Title.2017.REPACK2.FLAC-aAF", true, 3)] + [TestCase("Artist Title - Album Title 2017 RERIP FLAC aAF", true, 2)] + [TestCase("Artist Title - Album Title 2017 RERIP2 FLAC aAF", true, 3)] + [TestCase("Artist Title - Album Title 2017 PROPER FLAC aAF", false, 2)] + public void should_be_able_to_parse_repack(string title, bool isRepack, int version) { var result = QualityParser.ParseQuality(title, null, 0); - result.Revision.Version.Should().Be(2); + result.Revision.Version.Should().Be(version); result.Revision.IsRepack.Should().Be(isRepack); } diff --git a/src/NzbDrone.Core/Parser/QualityParser.cs b/src/NzbDrone.Core/Parser/QualityParser.cs index c2d3aa3c6..1ca788a83 100644 --- a/src/NzbDrone.Core/Parser/QualityParser.cs +++ b/src/NzbDrone.Core/Parser/QualityParser.cs @@ -15,10 +15,10 @@ namespace NzbDrone.Core.Parser private static readonly Regex ProperRegex = new Regex(@"\b(?proper)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); - private static readonly Regex RepackRegex = new Regex(@"\b(?repack|rerip)\b", + private static readonly Regex RepackRegex = new Regex(@"\b(?repack\d?|rerip\d?)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); - private static readonly Regex VersionRegex = new Regex(@"\d[-._ ]?v(?\d)[-._ ]|\[v(?\d)\]", + private static readonly Regex VersionRegex = new Regex(@"\d[-._ ]?v(?\d)[-._ ]|\[v(?\d)\]|repack(?\d)|rerip(?\d)", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex RealRegex = new Regex(@"\b(?REAL)\b", @@ -616,22 +616,25 @@ namespace NzbDrone.Core.Parser { var result = new QualityModel { Quality = Quality.Unknown }; - if (ProperRegex.IsMatch(normalizedName)) + var versionRegexResult = VersionRegex.Match(normalizedName); + + if (versionRegexResult.Success) { - result.Revision.Version = 2; + result.Revision.Version = Convert.ToInt32(versionRegexResult.Groups["version"].Value); + result.RevisionDetectionSource = QualityDetectionSource.Name; } - if (RepackRegex.IsMatch(normalizedName)) + if (ProperRegex.IsMatch(normalizedName)) { - result.Revision.Version = 2; - result.Revision.IsRepack = true; + result.Revision.Version = versionRegexResult.Success ? Convert.ToInt32(versionRegexResult.Groups["version"].Value) + 1 : 2; + result.RevisionDetectionSource = QualityDetectionSource.Name; } - var versionRegexResult = VersionRegex.Match(normalizedName); - - if (versionRegexResult.Success) + if (RepackRegex.IsMatch(normalizedName)) { - result.Revision.Version = Convert.ToInt32(versionRegexResult.Groups["version"].Value); + result.Revision.Version = versionRegexResult.Success ? Convert.ToInt32(versionRegexResult.Groups["version"].Value) + 1 : 2; + result.Revision.IsRepack = true; + result.RevisionDetectionSource = QualityDetectionSource.Name; } // TODO: re-enable this when we have a reliable way to determine real @@ -640,6 +643,7 @@ namespace NzbDrone.Core.Parser if (realRegexResult.Count > 0) { result.Revision.Real = realRegexResult.Count; + result.RevisionDetectionSource = QualityDetectionSource.Name; } return result; diff --git a/src/NzbDrone.Core/Qualities/QualityModel.cs b/src/NzbDrone.Core/Qualities/QualityModel.cs index 566c98080..3a1499f60 100644 --- a/src/NzbDrone.Core/Qualities/QualityModel.cs +++ b/src/NzbDrone.Core/Qualities/QualityModel.cs @@ -13,6 +13,9 @@ namespace NzbDrone.Core.Qualities [JsonIgnore] public QualityDetectionSource QualityDetectionSource { get; set; } + [JsonIgnore] + public QualityDetectionSource RevisionDetectionSource { get; set; } + public QualityModel() : this(Quality.Unknown, new Revision()) {