diff --git a/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs b/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs index f64d73aec..afc334895 100644 --- a/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs @@ -8,9 +8,6 @@ namespace NzbDrone.Core.Test.TvTests public class SeriesTitleNormalizerFixture { [TestCase("A to Z", 281588, "a to z")] - [TestCase("A.D. The Bible Continues", 289260, "ad bible continues")] - [TestCase("A.P. Bio", 328534, "ap bio")] - [TestCase("The A-Team", 77904, "ateam")] public void should_use_precomputed_title(string title, int tvdbId, string expected) { SeriesTitleNormalizer.Normalize(title, tvdbId).Should().Be(expected); @@ -23,6 +20,12 @@ namespace NzbDrone.Core.Test.TvTests [TestCase("The Good Wife", "good wife")] [TestCase("The Newsroom (2012)", "newsroom 2012")] [TestCase("Special Agent Oso", "special agent oso")] + [TestCase("A.N.T. Farm", "ant farm")] + [TestCase("A.I.C.O. -Incarnation-", "aico incarnation")] + [TestCase("A.D. The Bible Continues", "ad the bible continues")] + [TestCase("A.P. Bio", "ap bio")] + [TestCase("The A-Team", "ateam")] + [TestCase("And Just Like That", "and just like that")] public void should_normalize_title(string title, string expected) { SeriesTitleNormalizer.Normalize(title, 0).Should().Be(expected); diff --git a/src/NzbDrone.Core/Datastore/Migration/166_update_series_sort_title.cs b/src/NzbDrone.Core/Datastore/Migration/166_update_series_sort_title.cs new file mode 100644 index 000000000..0f72b980f --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/166_update_series_sort_title.cs @@ -0,0 +1,46 @@ +using System.Data; +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(166)] + public class update_series_sort_title : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.WithConnection(UpdateSortTitles); + } + + private void UpdateSortTitles(IDbConnection conn, IDbTransaction tran) + { + using (IDbCommand getSeriesCmd = conn.CreateCommand()) + { + getSeriesCmd.Transaction = tran; + getSeriesCmd.CommandText = @"SELECT Id, TvdbId, Title FROM Series"; + using (IDataReader seriesReader = getSeriesCmd.ExecuteReader()) + { + while (seriesReader.Read()) + { + var id = seriesReader.GetInt32(0); + var tvdbId = seriesReader.GetInt32(1); + var title = seriesReader.GetString(2); + + var sortTitle = SeriesTitleNormalizer.Normalize(title, tvdbId); + + using (IDbCommand updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = "UPDATE Series SET SortTitle = ? WHERE Id = ?"; + updateCmd.AddParameter(sortTitle); + updateCmd.AddParameter(id); + + updateCmd.ExecuteNonQuery(); + } + } + } + } + } + } +} diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 19f307fdf..4df8339ff 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -472,9 +472,8 @@ namespace NzbDrone.Core.Parser private static readonly Regex TitleComponentsRegex = new Regex(@"^(?:(?.+?) \((?<title>.+?)\)|(?<title>.+?) \| (?<title>.+?))$", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private static readonly Regex WordDelimiterRegex = new Regex(@"(\s|\.|,|_|-|=|\|)+", RegexOptions.Compiled); private static readonly Regex PunctuationRegex = new Regex(@"[^\w\s]", RegexOptions.Compiled); - private static readonly Regex CommonWordRegex = new Regex(@"\b(a|an|the|and|or|of)\b\s?", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex ArticleWordRegex = new Regex(@"^(a|an|the)\s", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex SpecialEpisodeWordRegex = new Regex(@"\b(part|special|edition|christmas)\b\s?", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex DuplicateSpacesRegex = new Regex(@"\s{2,}", RegexOptions.Compiled); @@ -705,9 +704,8 @@ namespace NzbDrone.Core.Parser public static string NormalizeTitle(string title) { - title = WordDelimiterRegex.Replace(title, " "); title = PunctuationRegex.Replace(title, string.Empty); - title = CommonWordRegex.Replace(title, string.Empty); + title = ArticleWordRegex.Replace(title, string.Empty); title = DuplicateSpacesRegex.Replace(title, " "); return title.Trim().ToLower(); diff --git a/src/NzbDrone.Core/Tv/SeriesTitleNormalizer.cs b/src/NzbDrone.Core/Tv/SeriesTitleNormalizer.cs index 890f5c7da..484321e8a 100644 --- a/src/NzbDrone.Core/Tv/SeriesTitleNormalizer.cs +++ b/src/NzbDrone.Core/Tv/SeriesTitleNormalizer.cs @@ -6,10 +6,7 @@ namespace NzbDrone.Core.Tv { private static readonly Dictionary<int, string> PreComputedTitles = new Dictionary<int, string> { - { 281588, "a to z" }, - { 289260, "ad bible continues"}, - { 328534, "ap bio"}, - { 77904, "ateam" } + { 281588, "a to z" } }; public static string Normalize(string title, int tvdbId)