Fixed: Enable parsing of repacks with revision

Closes #3320

(cherry picked from commit e29470d8cb9dd3d4d75a3abe1b9b7e8df4f2df4a)
pull/4202/head
Qstick 1 year ago
parent 5107fe73a1
commit 3d7d43bb46

@ -307,13 +307,16 @@ namespace NzbDrone.Core.Test.ParserTests
QualityParser.ParseCodec(null, null).Should().Be(Codec.Unknown); QualityParser.ParseCodec(null, null).Should().Be(Codec.Unknown);
} }
[TestCase("Artist Title - Album Title 2017 REPACK FLAC aAF", true)] [TestCase("Artist Title - Album Title 2017 REPACK FLAC aAF", true, 2)]
[TestCase("Artist Title - Album Title 2017 RERIP FLAC aAF", true)] [TestCase("Artist.Title-Album.Title.2017.REPACK.FLAC-aAF", true, 2)]
[TestCase("Artist Title - Album Title 2017 PROPER FLAC aAF", false)] [TestCase("Artist.Title-Album.Title.2017.REPACK2.FLAC-aAF", true, 3)]
public void should_be_able_to_parse_repack(string title, bool isRepack) [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); 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); result.Revision.IsRepack.Should().Be(isRepack);
} }

@ -15,10 +15,10 @@ namespace NzbDrone.Core.Parser
private static readonly Regex ProperRegex = new Regex(@"\b(?<proper>proper)\b", private static readonly Regex ProperRegex = new Regex(@"\b(?<proper>proper)\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase); RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex RepackRegex = new Regex(@"\b(?<repack>repack|rerip)\b", private static readonly Regex RepackRegex = new Regex(@"\b(?<repack>repack\d?|rerip\d?)\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase); RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex VersionRegex = new Regex(@"\d[-._ ]?v(?<version>\d)[-._ ]|\[v(?<version>\d)\]", private static readonly Regex VersionRegex = new Regex(@"\d[-._ ]?v(?<version>\d)[-._ ]|\[v(?<version>\d)\]|repack(?<version>\d)|rerip(?<version>\d)",
RegexOptions.Compiled | RegexOptions.IgnoreCase); RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex RealRegex = new Regex(@"\b(?<real>REAL)\b", private static readonly Regex RealRegex = new Regex(@"\b(?<real>REAL)\b",
@ -616,22 +616,25 @@ namespace NzbDrone.Core.Parser
{ {
var result = new QualityModel { Quality = Quality.Unknown }; 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.Version = versionRegexResult.Success ? Convert.ToInt32(versionRegexResult.Groups["version"].Value) + 1 : 2;
result.Revision.IsRepack = true; result.RevisionDetectionSource = QualityDetectionSource.Name;
} }
var versionRegexResult = VersionRegex.Match(normalizedName); if (RepackRegex.IsMatch(normalizedName))
if (versionRegexResult.Success)
{ {
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 // 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) if (realRegexResult.Count > 0)
{ {
result.Revision.Real = realRegexResult.Count; result.Revision.Real = realRegexResult.Count;
result.RevisionDetectionSource = QualityDetectionSource.Name;
} }
return result; return result;

@ -13,6 +13,9 @@ namespace NzbDrone.Core.Qualities
[JsonIgnore] [JsonIgnore]
public QualityDetectionSource QualityDetectionSource { get; set; } public QualityDetectionSource QualityDetectionSource { get; set; }
[JsonIgnore]
public QualityDetectionSource RevisionDetectionSource { get; set; }
public QualityModel() public QualityModel()
: this(Quality.Unknown, new Revision()) : this(Quality.Unknown, new Revision())
{ {

Loading…
Cancel
Save