Fixed: Improved title sorting for 'A to Z'

pull/6/head
Mark McDowall 10 years ago
parent 3411c4e5a7
commit 97c9217c0d

@ -85,7 +85,7 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
series.Should().NotBeNull();
series.Title.Should().NotBeNullOrWhiteSpace();
series.CleanTitle.Should().Be(Parser.Parser.CleanSeriesTitle(series.Title));
series.SortTitle.Should().Be(Parser.Parser.NormalizeEpisodeTitle(series.Title));
series.SortTitle.Should().Be(SeriesTitleNormalizer.Normalize(series.Title, series.TvdbId));
series.Overview.Should().NotBeNullOrWhiteSpace();
series.AirTime.Should().NotBeNullOrWhiteSpace();
series.FirstAired.Should().HaveValue();

@ -292,6 +292,7 @@
<Compile Include="TvTests\SeriesServiceTests\AddSeriesFixture.cs" />
<Compile Include="TvTests\SeriesServiceTests\UpdateMultipleSeriesFixture.cs" />
<Compile Include="TvTests\SeriesServiceTests\UpdateSeriesFixture.cs" />
<Compile Include="TvTests\SeriesTitleNormalizerFixture.cs" />
<Compile Include="TvTests\ShouldRefreshSeriesFixture.cs" />
<Compile Include="UpdateTests\UpdatePackageProviderFixture.cs" />
<Compile Include="UpdateTests\UpdateServiceFixture.cs" />

@ -0,0 +1,28 @@
using System;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.TvTests
{
[TestFixture]
public class SeriesTitleNormalizerFixture
{
[Test]
public void should_use_precomputed_title_for_a_to_z()
{
SeriesTitleNormalizer.Normalize("A to Z", 281588).Should().Be("a to z");
}
[TestCase("2 Broke Girls", "2 broke girls")]
[TestCase("Archer (2009)", "archer 2009")]
[TestCase("The Office (US)", "office us")]
[TestCase("The Mentalist", "mentalist")]
[TestCase("The Good Wife", "good wife")]
[TestCase("The Newsroom (2012)", "newsroom 2012")]
public void should_normalize_title(String title, String expected)
{
SeriesTitleNormalizer.Normalize(title, 0).Should().Be(expected);
}
}
}

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Datastore.Migration
var id = seriesReader.GetInt32(0);
var title = seriesReader.GetString(1);
var sortTitle = Parser.Parser.NormalizeEpisodeTitle(title).ToLower();
var sortTitle = Parser.Parser.NormalizeTitle(title).ToLower();
using (IDbCommand updateCmd = conn.CreateCommand())
{

@ -134,7 +134,7 @@ namespace NzbDrone.Core.MetadataSource
series.ImdbId = show.imdb_id;
series.Title = show.title;
series.CleanTitle = Parser.Parser.CleanSeriesTitle(show.title);
series.SortTitle = Parser.Parser.NormalizeEpisodeTitle(show.title).ToLower();
series.SortTitle = SeriesTitleNormalizer.Normalize(show.title, show.tvdb_id);
series.Year = GetYear(show.year, show.first_aired);
series.FirstAired = FromIso(show.first_aired_iso);
series.Overview = show.overview;

@ -765,6 +765,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Tv\SeriesStatusType.cs" />
<Compile Include="Tv\SeriesTitleNormalizer.cs" />
<Compile Include="Tv\SeriesTypes.cs" />
<Compile Include="Tv\ShouldRefreshSeries.cs" />
<Compile Include="Update\Commands\ApplicationUpdateCommand.cs" />

@ -323,7 +323,7 @@ namespace NzbDrone.Core.Parser
return MultiPartCleanupRegex.Replace(title, string.Empty).Trim();
}
public static string NormalizeEpisodeTitle(string title)
public static string NormalizeTitle(string title)
{
string singleSpaces = WordDelimiterRegex.Replace(title, " ");
string noPunctuation = PunctuationRegex.Replace(singleSpaces, String.Empty);

@ -106,12 +106,12 @@ namespace NzbDrone.Core.Tv
public Episode FindEpisodeByName(int seriesId, int seasonNumber, string episodeTitle)
{
// TODO: can replace this search mechanism with something smarter/faster/better
var search = Parser.Parser.NormalizeEpisodeTitle(episodeTitle);
var search = Parser.Parser.NormalizeTitle(episodeTitle);
return _episodeRepository.GetEpisodes(seriesId, seasonNumber)
.FirstOrDefault(e =>
{
// normalize episode title
string title = Parser.Parser.NormalizeEpisodeTitle(e.Title);
string title = Parser.Parser.NormalizeTitle(e.Title);
// find episode title within search string
return (title.Length > 0) && search.Contains(title);
});

@ -77,7 +77,7 @@ namespace NzbDrone.Core.Tv
newSeries.Monitored = true;
newSeries.CleanTitle = newSeries.Title.CleanSeriesTitle();
newSeries.SortTitle = Parser.Parser.NormalizeEpisodeTitle(newSeries.Title).ToLower();
newSeries.SortTitle = SeriesTitleNormalizer.Normalize(newSeries.Title, newSeries.TvdbId);
_seriesRepository.Insert(newSeries);
_eventAggregator.PublishEvent(new SeriesAddedEvent(GetSeries(newSeries.Id)));

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
namespace NzbDrone.Core.Tv
{
public static class SeriesTitleNormalizer
{
private readonly static Dictionary<Int32, String> PreComputedTitles = new Dictionary<Int32, String>
{
{ 281588, "a to z" }
};
public static String Normalize(String title, Int32 tvdbId)
{
if (PreComputedTitles.ContainsKey(tvdbId))
{
return PreComputedTitles[tvdbId];
}
return Parser.Parser.NormalizeTitle(title).ToLower();
}
}
}
Loading…
Cancel
Save