diff --git a/src/NzbDrone.Core.Test/CustomFormat/QualityTagFixture.cs b/src/NzbDrone.Core.Test/CustomFormat/QualityTagFixture.cs index 7c35aeb87..1e07a8230 100644 --- a/src/NzbDrone.Core.Test/CustomFormat/QualityTagFixture.cs +++ b/src/NzbDrone.Core.Test/CustomFormat/QualityTagFixture.cs @@ -35,6 +35,7 @@ public class QualityTagFixture : CoreTest [TestCase("G_10<>20", TagType.Size, new[] { 10737418240L, 21474836480L})] [TestCase("G_15.55<>20", TagType.Size, new[] { 16696685363L, 21474836480L})] [TestCase("G_15.55<>25.1908754", TagType.Size, new[] { 16696685363L, 27048496500L})] + [TestCase("R__1080", TagType.Resolution, Resolution.R1080P)] public void should_parse_tag_from_string(string raw, TagType type, object value, params TagModifier[] modifiers) { var parsed = new FormatTag(raw); diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/149_regex_required_tagsFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/149_regex_required_tagsFixture.cs index 998f3dcb9..e1a3c1774 100644 --- a/src/NzbDrone.Core.Test/Datastore/Migration/149_regex_required_tagsFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/Migration/149_regex_required_tagsFixture.cs @@ -32,6 +32,7 @@ public void AddCustomFormat(convert_regex_required_tags c, string name, params s [TestCase("C_RE_RERN", "C_RQ_RERN")] [TestCase("E_NRER_Director", "E_NRXRQ_Director")] [TestCase("G_N_1000<>1000", "G_N_1000<>1000")] + [TestCase("G_1000<>1000", "G_1000<>1000")] public void should_correctly_convert_format_tag(string original, string converted) { var db = WithMigrationTestDb(c => { AddCustomFormat(c, "TestFormat", original); }); diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/150_fix_format_tags_double_underscoreFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/150_fix_format_tags_double_underscoreFixture.cs new file mode 100644 index 000000000..f329f18a6 --- /dev/null +++ b/src/NzbDrone.Core.Test/Datastore/Migration/150_fix_format_tags_double_underscoreFixture.cs @@ -0,0 +1,57 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using FluentAssertions; +using Newtonsoft.Json; +using NUnit.Framework; +using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration; +using NzbDrone.Core.Parser; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.Datastore.Migration +{ + [TestFixture] + public class fix_format_tags_double_underscoreFixture : MigrationTest + { + + public void AddCustomFormat(fix_format_tags_double_underscore c, string name, params string[] formatTags) + { + var customFormat = new {Name = name, FormatTags = formatTags.ToList().ToJson()}; + + c.Insert.IntoTable("CustomFormats").Row(customFormat); + } + + [TestCase("C_HDR", "C_HDR")] + [TestCase("C__HDR", "C_HDR")] + [TestCase("C_RXRQ_HDR", "C_RXRQ_HDR")] + [TestCase("C_RENR_HDR", "C_RENR_HDR")] + [TestCase("E__Director", "E_Director")] + [TestCase("G_N_1000<>1000", "G_N_1000<>1000")] + [TestCase("G_1000<>1000", "G_1000<>1000")] + public void should_correctly_convert_format_tag(string original, string converted) + { + var db = WithMigrationTestDb(c => { AddCustomFormat(c, "TestFormat", original); }); + + var items = QueryItems(db); + + var convertedTags = items.First().DeserializedTags; + + convertedTags.Should().HaveCount(1); + convertedTags.First().ShouldBeEquivalentTo(converted); + } + + private List QueryItems(IDirectDataMapper db) + { + var items = db.Query("SELECT Name, FormatTags FROM CustomFormats"); + + return items.Select(i => + { + i.DeserializedTags = JsonConvert.DeserializeObject>(i.FormatTags); + return i; + }).ToList(); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index b295ba044..bfd83ac26 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -140,6 +140,7 @@ + diff --git a/src/NzbDrone.Core/CustomFormats/FormatTag.cs b/src/NzbDrone.Core/CustomFormats/FormatTag.cs index e1a6a8ab6..0297231b1 100644 --- a/src/NzbDrone.Core/CustomFormats/FormatTag.cs +++ b/src/NzbDrone.Core/CustomFormats/FormatTag.cs @@ -15,7 +15,7 @@ public class FormatTag public TagModifier TagModifier { get; set; } public object Value { get; set; } - public static Regex QualityTagRegex = new Regex(@"^(?R|S|M|E|L|C|I|G)(_((?RX)|(?RQ)|(?N)){1,3})?_(?.*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + public static Regex QualityTagRegex = new Regex(@"^(?R|S|M|E|L|C|I|G)(_((?RX)|(?RQ)|(?N)){0,3})?_(?.*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); public static Regex SizeTagRegex = new Regex(@"(?\d+(\.\d+)?)\s*<>\s*(?\d+(\.\d+)?)", RegexOptions.Compiled | RegexOptions.IgnoreCase); diff --git a/src/NzbDrone.Core/Datastore/Migration/149_convert_regex_required_tags.cs b/src/NzbDrone.Core/Datastore/Migration/149_convert_regex_required_tags.cs index be3350b87..ab006cb91 100644 --- a/src/NzbDrone.Core/Datastore/Migration/149_convert_regex_required_tags.cs +++ b/src/NzbDrone.Core/Datastore/Migration/149_convert_regex_required_tags.cs @@ -28,7 +28,8 @@ private void ConvertExistingFormatTags(IDbConnection conn, IDbTransaction tran) if (match.Groups["m_n"].Success) modifiers += "N"; if (match.Groups["m_r"].Success) modifiers += "RX"; if (match.Groups["m_re"].Success) modifiers += "RQ"; - return $"{match.Groups["type"].Value}_{modifiers}_{match.Groups["value"].Value}"; + if (modifiers != "") modifiers = "_" + modifiers; + return $"{match.Groups["type"].Value}{modifiers}_{match.Groups["value"].Value}"; }); updater.Commit(); diff --git a/src/NzbDrone.Core/Datastore/Migration/150_fix_format_tags_double_underscore.cs b/src/NzbDrone.Core/Datastore/Migration/150_fix_format_tags_double_underscore.cs new file mode 100644 index 000000000..31d0238ad --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/150_fix_format_tags_double_underscore.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text.RegularExpressions; +using FluentMigrator; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(150)] + public class fix_format_tags_double_underscore : NzbDroneMigrationBase + { + public static Regex DoubleUnderscore = new Regex(@"^(?R|S|M|E|L|C|I|G)__(?.*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + protected override void MainDbUpgrade() + { + Execute.WithConnection(ConvertExistingFormatTags); + } + + private void ConvertExistingFormatTags(IDbConnection conn, IDbTransaction tran) + { + var updater = new CustomFormatUpdater149(conn, tran); + + updater.ReplaceInTags(DoubleUnderscore, match => + { + return $"{match.Groups["type"].Value}_{match.Groups["value"].Value}"; + }); + + updater.Commit(); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 5466109d8..866ba4b6a 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -145,6 +145,7 @@ +